6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
+ import { coerceArray } from '@angular/cdk/coercion' ;
9
10
import { Injectable , NgZone , OnDestroy } from '@angular/core' ;
10
- import { MediaMatcher } from './media-matcher' ;
11
- import { combineLatest , concat , Observable , Subject , Observer } from 'rxjs' ;
11
+ import { combineLatest , concat , Observable , Observer , Subject } from 'rxjs' ;
12
12
import { debounceTime , map , skip , startWith , take , takeUntil } from 'rxjs/operators' ;
13
- import { coerceArray } from '@angular/cdk/coercion ' ;
13
+ import { MediaMatcher } from './media-matcher ' ;
14
14
15
15
16
16
/** The current state of a layout breakpoint. */
@@ -60,7 +60,7 @@ export class BreakpointObserver implements OnDestroy {
60
60
* @param value One or more media queries to check.
61
61
* @returns Whether any of the media queries match.
62
62
*/
63
- isMatched ( value : string | string [ ] ) : boolean {
63
+ isMatched ( value : string | readonly string [ ] ) : boolean {
64
64
const queries = splitQueries ( coerceArray ( value ) ) ;
65
65
return queries . some ( mediaQuery => this . _registerQuery ( mediaQuery ) . mql . matches ) ;
66
66
}
@@ -71,7 +71,7 @@ export class BreakpointObserver implements OnDestroy {
71
71
* @param value One or more media queries to check.
72
72
* @returns A stream of matches for the given queries.
73
73
*/
74
- observe ( value : string | string [ ] ) : Observable < BreakpointState > {
74
+ observe ( value : string | readonly string [ ] ) : Observable < BreakpointState > {
75
75
const queries = splitQueries ( coerceArray ( value ) ) ;
76
76
const observables = queries . map ( query => this . _registerQuery ( query ) . observable ) ;
77
77
@@ -80,14 +80,14 @@ export class BreakpointObserver implements OnDestroy {
80
80
stateObservable = concat (
81
81
stateObservable . pipe ( take ( 1 ) ) ,
82
82
stateObservable . pipe ( skip ( 1 ) , debounceTime ( 0 ) ) ) ;
83
- return stateObservable . pipe ( map ( ( breakpointStates : InternalBreakpointState [ ] ) => {
83
+ return stateObservable . pipe ( map ( breakpointStates => {
84
84
const response : BreakpointState = {
85
85
matches : false ,
86
86
breakpoints : { } ,
87
87
} ;
88
- breakpointStates . forEach ( ( state : InternalBreakpointState ) => {
89
- response . matches = response . matches || state . matches ;
90
- response . breakpoints [ state . query ] = state . matches ;
88
+ breakpointStates . forEach ( ( { matches , query } ) => {
89
+ response . matches = response . matches || matches ;
90
+ response . breakpoints [ query ] = matches ;
91
91
} ) ;
92
92
return response ;
93
93
} ) ) ;
@@ -100,10 +100,10 @@ export class BreakpointObserver implements OnDestroy {
100
100
return this . _queries . get ( query ) ! ;
101
101
}
102
102
103
- const mql : MediaQueryList = this . _mediaMatcher . matchMedia ( query ) ;
103
+ const mql = this . _mediaMatcher . matchMedia ( query ) ;
104
104
105
105
// Create callback for match changes and add it is as a listener.
106
- const queryObservable = new Observable < MediaQueryList > ( ( observer : Observer < MediaQueryList > ) => {
106
+ const queryObservable = new Observable ( ( observer : Observer < MediaQueryList > ) => {
107
107
// Listener callback methods are wrapped to be placed back in ngZone. Callbacks must be placed
108
108
// back into the zone because matchMedia is only included in Zone.js by loading the
109
109
// webapis-media-query.js file alongside the zone.js file. Additionally, some browsers do not
@@ -117,7 +117,7 @@ export class BreakpointObserver implements OnDestroy {
117
117
} ;
118
118
} ) . pipe (
119
119
startWith ( mql ) ,
120
- map ( ( nextMql : MediaQueryList ) => ( { query, matches : nextMql . matches } ) ) ,
120
+ map ( ( { matches } ) => ( { query, matches} ) ) ,
121
121
takeUntil ( this . _destroySubject )
122
122
) ;
123
123
@@ -132,8 +132,8 @@ export class BreakpointObserver implements OnDestroy {
132
132
* Split each query string into separate query strings if two queries are provided as comma
133
133
* separated.
134
134
*/
135
- function splitQueries ( queries : string [ ] ) : string [ ] {
136
- return queries . map ( ( query : string ) => query . split ( ',' ) )
137
- . reduce ( ( a1 : string [ ] , a2 : string [ ] ) => a1 . concat ( a2 ) )
135
+ function splitQueries ( queries : readonly string [ ] ) : readonly string [ ] {
136
+ return queries . map ( query => query . split ( ',' ) )
137
+ . reduce ( ( a1 , a2 ) => a1 . concat ( a2 ) )
138
138
. map ( query => query . trim ( ) ) ;
139
139
}
0 commit comments