Skip to content

Commit

Permalink
feat(lib): remove uses of rxjs patch operators
Browse files Browse the repository at this point in the history
Usages of RxJS operators should use the "longhand" syntax, which avoids polluting the Observable.prototype in userland.
Refactors the entire codebase not to use the patch operators from RxJS, because they pollute the user's setup. Instead, opts into importing the operators directly.

> Refs angular/components#2622.
  • Loading branch information
ThomasBurleson committed Jul 27, 2017
1 parent f796a8c commit 78f7e4a
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 70 deletions.
3 changes: 0 additions & 3 deletions src/lib/flexbox/responsive/responsive-activation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

// RxJS Operators used by the classes...

import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';

import {TestBed, inject} from '@angular/core/testing';

import {DEFAULT_BREAKPOINTS_PROVIDER} from '../../media-query/breakpoints/break-points-provider';
Expand Down
9 changes: 4 additions & 5 deletions src/lib/flexbox/responsive/responsive-activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Subscription} from 'rxjs/Subscription';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/filter';
import {extendObject} from '../../utils/object-extend';
import {map} from 'rxjs/operator/map';

import {MediaChange, MediaQuerySubscriber} from '../../media-query/media-change';
import {BreakPoint} from '../../media-query/breakpoints/break-point';
import {MediaMonitor} from '../../media-query/media-monitor';

import {extendObject} from '../../utils/object-extend';

export declare type SubscriptionList = Subscription[ ];

export interface BreakPointX extends BreakPoint {
Expand Down Expand Up @@ -118,8 +118,7 @@ export class ResponsiveActivation {
};

subscriptions.push(
this.mediaMonitor.observe(bp.alias)
.map(buildChanges)
map.call(this.mediaMonitor.observe(bp.alias), buildChanges)
.subscribe(change => {
this._onMonitorEvents(change);
})
Expand Down
5 changes: 0 additions & 5 deletions src/lib/media-query/breakpoints/data/break-points.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/

// RxJS Operators used by the classes...

import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';

import {TestBed, inject, async} from '@angular/core/testing';

import {BreakPoint} from '../break-point';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/

// RxJS Operators used by the classes...

import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';

import {TestBed, inject, async} from '@angular/core/testing';

import {BreakPoint} from '../break-point';
Expand Down
4 changes: 0 additions & 4 deletions src/lib/media-query/match-media.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
// RxJS Operators used by the classes...

import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';
import {Observable} from 'rxjs/Observable';

import {TestBed, inject, async} from '@angular/core/testing';
Expand Down
12 changes: 4 additions & 8 deletions src/lib/media-query/match-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import {Injectable, NgZone} from '@angular/core';

import {BehaviorSubject} from 'rxjs/BehaviorSubject';
import {Observable} from 'rxjs/Observable';

// RxJS Operators used by the classes...
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';
import {filter} from 'rxjs/operator/filter';

import {MediaChange} from './media-change';

Expand Down Expand Up @@ -76,10 +73,9 @@ export class MatchMedia {
observe(mediaQuery?: string): Observable<MediaChange> {
this.registerQuery(mediaQuery);

return this._observable$
.filter((change: MediaChange) => {
return mediaQuery ? (change.mediaQuery === mediaQuery) : true;
});
return filter.call(this._observable$, (change: MediaChange) => {
return mediaQuery ? (change.mediaQuery === mediaQuery) : true;
});
}

/**
Expand Down
5 changes: 0 additions & 5 deletions src/lib/media-query/media-monitor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
// RxJS Operators used by the classes...

import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';

import {TestBed, inject, async} from '@angular/core/testing';

import {DEFAULT_BREAKPOINTS_PROVIDER} from './breakpoints/break-points-provider';
Expand Down
10 changes: 5 additions & 5 deletions src/lib/media-query/media-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {MediaChange} from './media-change';
import {mergeAlias} from '../utils/add-alias';

import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import {filter} from 'rxjs/operator/filter';
import {map} from 'rxjs/operator/map';

/**
* MediaMonitor uses the MatchMedia service to observe mediaQuery changes (both activations and
Expand Down Expand Up @@ -81,10 +82,9 @@ export class MediaMonitor {
let bp = this._breakpoints.findByAlias(alias) || this._breakpoints.findByQuery(alias);
let hasAlias = (change: MediaChange) => (bp ? change.mqAlias !== '' : true);
// Note: the raw MediaChange events [from MatchMedia] do not contain important alias information
return this._matchMedia
.observe(bp ? bp.mediaQuery : alias)
.map(change => mergeAlias(change, bp))
.filter(hasAlias);

let media$ = this._matchMedia.observe(bp ? bp.mediaQuery : alias);
return filter.call(map.call(media$, change => mergeAlias(change, bp)), hasAlias);
}

/**
Expand Down
5 changes: 0 additions & 5 deletions src/lib/media-query/mock/mock-match-media.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/

// RxJS Operators used by the classes...

import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';

import {TestBed, inject, async} from '@angular/core/testing';

import {MediaChange} from '../media-change';
Expand Down
3 changes: 0 additions & 3 deletions src/lib/media-query/observable-media-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import {
SkipSelf
} from '@angular/core';

import 'rxjs/add/operator/map';
import 'rxjs/add/operator/filter';

import {BreakPointRegistry} from './breakpoints/break-point-registry';

import {MatchMedia} from './match-media';
Expand Down
27 changes: 13 additions & 14 deletions src/lib/media-query/observable-media.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

// RxJS Operators used by the classes...

import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';

import {TestBed, inject, async} from '@angular/core/testing';

import {filter} from 'rxjs/operator/filter';
import {map} from 'rxjs/operator/map';

import {BreakPoint} from './breakpoints/break-point';
import {BREAKPOINTS} from './breakpoints/break-points-token';
import {BreakPointRegistry} from './breakpoints/break-point-registry';
Expand Down Expand Up @@ -71,13 +68,15 @@ describe('observable-media', () => {
[ObservableMedia, MatchMedia],
(mediaService, matchMedia) => {
let count = 0,
subscription = mediaService
.asObservable()
.filter(change => change.mqAlias == 'md')
.map(change => change.mqAlias)
.subscribe((alias) => {
count += 1;
});
subscription = map.call(
filter.call(
mediaService.asObservable(),
change => change.mqAlias == 'md'
),
change => change.mqAlias
).subscribe(_ => {
count += 1;
});


// Activate mediaQuery associated with 'md' alias
Expand Down Expand Up @@ -177,7 +176,7 @@ describe('observable-media', () => {
providers: [
BreakPointRegistry, // Registry of known/used BreakPoint(s)
MockMatchMediaProvider,
CUSTOM_BREAKPOINTS_PROVIDER_FACTORY(CUSTOM_BREAKPOINTS, excludeDefaults),
CUSTOM_BREAKPOINTS_PROVIDER_FACTORY(CUSTOM_BREAKPOINTS, {defaults: excludeDefaults} ),
OBSERVABLE_MEDIA_PROVIDER,
]
});
Expand Down
17 changes: 11 additions & 6 deletions src/lib/media-query/observable-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import {Injectable} from '@angular/core';

import {Subscription} from 'rxjs/Subscription';
import {Observable, Subscribable} from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/filter';

import {map} from 'rxjs/operator/map';
import {filter} from 'rxjs/operator/filter';

import {BreakPointRegistry} from './breakpoints/break-point-registry';

Expand Down Expand Up @@ -151,10 +152,14 @@ export class MediaService implements ObservableMedia {
* Inject associated (if any) alias information into the MediaChange event
* Exclude mediaQuery activations for overlapping mQs. List bounded mQ ranges only
*/
return this.mediaWatcher.observe()
.filter(activationsOnly)
.map(addAliasInformation)
.filter(excludeOverlaps);
return filter.call(
map.call(
filter.call(
this.mediaWatcher.observe(),
activationsOnly
),
addAliasInformation),
excludeOverlaps);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/lib/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';

import {ModuleWithProviders, NgModule} from '@angular/core';
import {MediaQueriesModule} from './media-query/_module';
Expand Down
1 change: 1 addition & 0 deletions src/lib/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* @description
* Entry point for all public APIs of Angular Flex-Layout.
*/
export * from './module';
export * from './flexbox/index';
export * from './media-query/index';
export * from './utils/index';
Expand Down

0 comments on commit 78f7e4a

Please sign in to comment.