observe-content.d.ts 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. import { AfterContentInit, ElementRef, EventEmitter, NgZone, OnDestroy } from '@angular/core';
  9. import { Observable } from 'rxjs';
  10. /**
  11. * Factory that creates a new MutationObserver and allows us to stub it out in unit tests.
  12. * @docs-private
  13. */
  14. export declare class MutationObserverFactory {
  15. create(callback: MutationCallback): MutationObserver | null;
  16. }
  17. /** An injectable service that allows watching elements for changes to their content. */
  18. export declare class ContentObserver implements OnDestroy {
  19. private _mutationObserverFactory;
  20. /** Keeps track of the existing MutationObservers so they can be reused. */
  21. private _observedElements;
  22. constructor(_mutationObserverFactory: MutationObserverFactory);
  23. ngOnDestroy(): void;
  24. /**
  25. * Observe content changes on an element.
  26. * @param element The element to observe for content changes.
  27. */
  28. observe(element: Element): Observable<MutationRecord[]>;
  29. /**
  30. * Observe content changes on an element.
  31. * @param element The element to observe for content changes.
  32. */
  33. observe(element: ElementRef<Element>): Observable<MutationRecord[]>;
  34. /**
  35. * Observes the given element by using the existing MutationObserver if available, or creating a
  36. * new one if not.
  37. */
  38. private _observeElement;
  39. /**
  40. * Un-observes the given element and cleans up the underlying MutationObserver if nobody else is
  41. * observing this element.
  42. */
  43. private _unobserveElement;
  44. /** Clean up the underlying MutationObserver for the specified element. */
  45. private _cleanupObserver;
  46. }
  47. /**
  48. * Directive that triggers a callback whenever the content of
  49. * its associated element has changed.
  50. */
  51. export declare class CdkObserveContent implements AfterContentInit, OnDestroy {
  52. private _contentObserver;
  53. private _elementRef;
  54. private _ngZone;
  55. /** Event emitted for each change in the element's content. */
  56. event: EventEmitter<MutationRecord[]>;
  57. /**
  58. * Whether observing content is disabled. This option can be used
  59. * to disconnect the underlying MutationObserver until it is needed.
  60. */
  61. disabled: any;
  62. private _disabled;
  63. /** Debounce interval for emitting the changes. */
  64. debounce: number;
  65. private _debounce;
  66. private _currentSubscription;
  67. constructor(_contentObserver: ContentObserver, _elementRef: ElementRef<HTMLElement>, _ngZone: NgZone);
  68. ngAfterContentInit(): void;
  69. ngOnDestroy(): void;
  70. private _subscribe;
  71. private _unsubscribe;
  72. }
  73. export declare class ObserversModule {
  74. }