ff363a4ccd56e376222019c6af933214749002383777511a027c6225e2e7b0bba98661fbd27c55c1845dd738692ed10d832a9193f902da15c1ff00b326ea01 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { Subscriber } from './Subscriber';
  2. import { ObservableNotification } from './types';
  3. /**
  4. * The {@link GlobalConfig} object for RxJS. It is used to configure things
  5. * like how to react on unhandled errors.
  6. */
  7. export const config: GlobalConfig = {
  8. onUnhandledError: null,
  9. onStoppedNotification: null,
  10. Promise: undefined,
  11. useDeprecatedSynchronousErrorHandling: false,
  12. useDeprecatedNextContext: false,
  13. };
  14. /**
  15. * The global configuration object for RxJS, used to configure things
  16. * like how to react on unhandled errors. Accessible via {@link config}
  17. * object.
  18. */
  19. export interface GlobalConfig {
  20. /**
  21. * A registration point for unhandled errors from RxJS. These are errors that
  22. * cannot were not handled by consuming code in the usual subscription path. For
  23. * example, if you have this configured, and you subscribe to an observable without
  24. * providing an error handler, errors from that subscription will end up here. This
  25. * will _always_ be called asynchronously on another job in the runtime. This is because
  26. * we do not want errors thrown in this user-configured handler to interfere with the
  27. * behavior of the library.
  28. */
  29. onUnhandledError: ((err: any) => void) | null;
  30. /**
  31. * A registration point for notifications that cannot be sent to subscribers because they
  32. * have completed, errored or have been explicitly unsubscribed. By default, next, complete
  33. * and error notifications sent to stopped subscribers are noops. However, sometimes callers
  34. * might want a different behavior. For example, with sources that attempt to report errors
  35. * to stopped subscribers, a caller can configure RxJS to throw an unhandled error instead.
  36. * This will _always_ be called asynchronously on another job in the runtime. This is because
  37. * we do not want errors thrown in this user-configured handler to interfere with the
  38. * behavior of the library.
  39. */
  40. onStoppedNotification: ((notification: ObservableNotification<any>, subscriber: Subscriber<any>) => void) | null;
  41. /**
  42. * The promise constructor used by default for {@link Observable#toPromise toPromise} and {@link Observable#forEach forEach}
  43. * methods.
  44. *
  45. * @deprecated As of version 8, RxJS will no longer support this sort of injection of a
  46. * Promise constructor. If you need a Promise implementation other than native promises,
  47. * please polyfill/patch Promise as you see appropriate. Will be removed in v8.
  48. */
  49. Promise?: PromiseConstructorLike;
  50. /**
  51. * If true, turns on synchronous error rethrowing, which is a deprecated behavior
  52. * in v6 and higher. This behavior enables bad patterns like wrapping a subscribe
  53. * call in a try/catch block. It also enables producer interference, a nasty bug
  54. * where a multicast can be broken for all observers by a downstream consumer with
  55. * an unhandled error. DO NOT USE THIS FLAG UNLESS IT'S NEEDED TO BUY TIME
  56. * FOR MIGRATION REASONS.
  57. *
  58. * @deprecated As of version 8, RxJS will no longer support synchronous throwing
  59. * of unhandled errors. All errors will be thrown on a separate call stack to prevent bad
  60. * behaviors described above. Will be removed in v8.
  61. */
  62. useDeprecatedSynchronousErrorHandling: boolean;
  63. /**
  64. * If true, enables an as-of-yet undocumented feature from v5: The ability to access
  65. * `unsubscribe()` via `this` context in `next` functions created in observers passed
  66. * to `subscribe`.
  67. *
  68. * This is being removed because the performance was severely problematic, and it could also cause
  69. * issues when types other than POJOs are passed to subscribe as subscribers, as they will likely have
  70. * their `this` context overwritten.
  71. *
  72. * @deprecated As of version 8, RxJS will no longer support altering the
  73. * context of next functions provided as part of an observer to Subscribe. Instead,
  74. * you will have access to a subscription or a signal or token that will allow you to do things like
  75. * unsubscribe and test closed status. Will be removed in v8.
  76. */
  77. useDeprecatedNextContext: boolean;
  78. }