Skip to content

Commit ccba8d6

Browse files
committed
fix(breakpoints): emit only one event for adjacent breakpoint changes.
1 parent 85039ca commit ccba8d6

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/cdk/layout/breakpoints-observer.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import {Injectable, NgZone, OnDestroy} from '@angular/core';
99
import {MediaMatcher} from './media-matcher';
1010
import {combineLatest, fromEventPattern, Observable, Subject} from 'rxjs';
11-
import {map, startWith, takeUntil} from 'rxjs/operators';
11+
import {debounceTime, map, startWith, takeUntil} from 'rxjs/operators';
1212
import {coerceArray} from '@angular/cdk/coercion';
1313

1414

@@ -59,11 +59,13 @@ export class BreakpointObserver implements OnDestroy {
5959
const queries = splitQueries(coerceArray(value));
6060
const observables = queries.map(query => this._registerQuery(query).observable);
6161

62-
return combineLatest(observables).pipe(map((breakpointStates: BreakpointState[]) => {
63-
return {
64-
matches: breakpointStates.some(state => state && state.matches)
65-
};
66-
}));
62+
return combineLatest(observables).pipe(
63+
debounceTime(0),
64+
map((breakpointStates: BreakpointState[]) => {
65+
return {
66+
matches: breakpointStates.some(state => state && state.matches)
67+
};
68+
}));
6769
}
6870

6971
/** Registers a specific query to be listened for. */

0 commit comments

Comments
 (0)