* Gets an observable of results for the given queries that will emit new results for any changes * in matching of the given queries. * @param value One or more media queries to check. * @returns A stream of matches for the given queries.
(value: string | readonly string[])
| 72 | * @returns A stream of matches for the given queries. |
| 73 | */ |
| 74 | observe(value: string | readonly string[]): Observable<BreakpointState> { |
| 75 | const queries = splitQueries(coerceArray(value)); |
| 76 | const observables = queries.map(query => this._registerQuery(query).observable); |
| 77 | |
| 78 | let stateObservable = combineLatest(observables); |
| 79 | // Emit the first state immediately, and then debounce the subsequent emissions. |
| 80 | stateObservable = concat( |
| 81 | stateObservable.pipe(take(1)), |
| 82 | stateObservable.pipe(skip(1), debounceTime(0)), |
| 83 | ); |
| 84 | return stateObservable.pipe( |
| 85 | map(breakpointStates => { |
| 86 | const response: BreakpointState = { |
| 87 | matches: false, |
| 88 | breakpoints: {}, |
| 89 | }; |
| 90 | breakpointStates.forEach(({matches, query}) => { |
| 91 | response.matches = response.matches || matches; |
| 92 | response.breakpoints[query] = matches; |
| 93 | }); |
| 94 | return response; |
| 95 | }), |
| 96 | ); |
| 97 | } |
| 98 | |
| 99 | /** Registers a specific query to be listened for. */ |
| 100 | private _registerQuery(query: string): Query { |
no test coverage detected