Skip to content

Commit

Permalink
fix(breakpoints): emit only one event for adjacent breakpoint changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
josephperrott committed Apr 30, 2018
1 parent ff0cc7a commit 7610ff0
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/cdk/layout/breakpoints-observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/
import {Injectable, NgZone, OnDestroy} from '@angular/core';
import {MediaMatcher} from './media-matcher';
import {combineLatest, fromEventPattern, Observable, Subject} from 'rxjs';
import {map, startWith, takeUntil} from 'rxjs/operators';
import {asapScheduler, combineLatest, fromEventPattern, Observable, Subject} from 'rxjs';
import {debounceTime, map, startWith, takeUntil} from 'rxjs/operators';
import {coerceArray} from '@angular/cdk/coercion';


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

return combineLatest(observables).pipe(map((breakpointStates: BreakpointState[]) => {
return {
matches: breakpointStates.some(state => state && state.matches)
};
}));
return combineLatest(observables).pipe(
debounceTime(0, asapScheduler),
map((breakpointStates: BreakpointState[]) => {
return {
matches: breakpointStates.some(state => state && state.matches)
};
}));
}

/** Registers a specific query to be listened for. */
Expand Down

0 comments on commit 7610ff0

Please sign in to comment.