(query: DatabaseQuery, action$: Observable<SnapshotAction<T>[]>, scheduler?: SchedulerLike)
| 38 | } |
| 39 | |
| 40 | function waitForLoaded<T>(query: DatabaseQuery, action$: Observable<SnapshotAction<T>[]>, scheduler?: SchedulerLike) { |
| 41 | const loaded$ = loadedData<T>(query, scheduler); |
| 42 | return loaded$ |
| 43 | .pipe( |
| 44 | withLatestFrom(action$), |
| 45 | // Get the latest values from the "loaded" and "child" datasets |
| 46 | // We can use both datasets to form an array of the latest values. |
| 47 | map(([loaded, actions]) => { |
| 48 | // Store the last key in the data set |
| 49 | const lastKeyToLoad = loaded.lastKeyToLoad; |
| 50 | // Store all child keys loaded at this point |
| 51 | const loadedKeys = actions.map(snap => snap.key); |
| 52 | return { actions, lastKeyToLoad, loadedKeys }; |
| 53 | }), |
| 54 | // This is the magical part, only emit when the last load key |
| 55 | // in the dataset has been loaded by a child event. At this point |
| 56 | // we can assume the dataset is "whole". |
| 57 | skipWhile(meta => meta.loadedKeys.indexOf(meta.lastKeyToLoad) === -1), |
| 58 | // Pluck off the meta data because the user only cares |
| 59 | // to iterate through the snapshots |
| 60 | map(meta => meta.actions) |
| 61 | ); |
| 62 | } |
no test coverage detected