data-source.d-Bblv7Zvh.d.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { Observable } from 'rxjs';
  2. /** Represents a range of numbers with a specified start and end. */
  3. type ListRange = {
  4. start: number;
  5. end: number;
  6. };
  7. /**
  8. * Interface for any component that provides a view of some data collection and wants to provide
  9. * information regarding the view and any changes made.
  10. */
  11. interface CollectionViewer {
  12. /**
  13. * A stream that emits whenever the `CollectionViewer` starts looking at a new portion of the
  14. * data. The `start` index is inclusive, while the `end` is exclusive.
  15. */
  16. viewChange: Observable<ListRange>;
  17. }
  18. declare abstract class DataSource<T> {
  19. /**
  20. * Connects a collection viewer (such as a data-table) to this data source. Note that
  21. * the stream provided will be accessed during change detection and should not directly change
  22. * values that are bound in template views.
  23. * @param collectionViewer The component that exposes a view over the data provided by this
  24. * data source.
  25. * @returns Observable that emits a new value when the data changes.
  26. */
  27. abstract connect(collectionViewer: CollectionViewer): Observable<readonly T[]>;
  28. /**
  29. * Disconnects a collection viewer (such as a data-table) from this data source. Can be used
  30. * to perform any clean-up or tear-down operations when a view is being destroyed.
  31. *
  32. * @param collectionViewer The component that exposes a view over the data provided by this
  33. * data source.
  34. */
  35. abstract disconnect(collectionViewer: CollectionViewer): void;
  36. }
  37. /** Checks whether an object is a data source. */
  38. declare function isDataSource(value: any): value is DataSource<any>;
  39. export { DataSource as D, isDataSource as i };
  40. export type { CollectionViewer as C, ListRange as L };