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 25, 2018
1 parent 85039ca commit ccba8d6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/cdk/layout/breakpoints-observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
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 {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),
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 ccba8d6

Please sign in to comment.