observable.extensions.d.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import type { EventState } from "./observable";
  2. import { Observable } from "./observable";
  3. /**
  4. * Represent a list of observers registered to multiple Observables object.
  5. */
  6. export declare class MultiObserver<T> {
  7. private _observers;
  8. private _observables;
  9. /**
  10. * Release associated resources
  11. */
  12. dispose(): void;
  13. /**
  14. * Raise a callback when one of the observable will notify
  15. * @param observables defines a list of observables to watch
  16. * @param callback defines the callback to call on notification
  17. * @param mask defines the mask used to filter notifications
  18. * @param scope defines the current scope used to restore the JS context
  19. * @returns the new MultiObserver
  20. */
  21. static Watch<T>(observables: Observable<T>[], callback: (eventData: T, eventState: EventState) => void, mask?: number, scope?: any): MultiObserver<T>;
  22. }
  23. declare module "./observable" {
  24. interface Observable<T> {
  25. /**
  26. * Calling this will execute each callback, expecting it to be a promise or return a value.
  27. * If at any point in the chain one function fails, the promise will fail and the execution will not continue.
  28. * This is useful when a chain of events (sometimes async events) is needed to initialize a certain object
  29. * and it is crucial that all callbacks will be executed.
  30. * The order of the callbacks is kept, callbacks are not executed parallel.
  31. *
  32. * @param eventData The data to be sent to each callback
  33. * @param mask is used to filter observers defaults to -1
  34. * @param target defines the callback target (see EventState)
  35. * @param currentTarget defines he current object in the bubbling phase
  36. * @param userInfo defines any user info to send to observers
  37. * @returns {Promise<T>} will return a Promise than resolves when all callbacks executed successfully.
  38. */
  39. notifyObserversWithPromise(eventData: T, mask?: number, target?: any, currentTarget?: any, userInfo?: any): Promise<T>;
  40. }
  41. }