forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: avoid polluting the user's rxjs setup
Currently, the internal uses of RxJS operators are done via patch imports, which add methods directly to the global `Observable` object. This can be an issue since the user may not know where these methods are coming from and may depend on them. Afterwards, if Material removes a method import, the user's app will break since the methods won't be defined anymore. This PR: * Replaces all of the patch imports with imports of individual operators and fixes any issues that showed up afterwards. * Adds a `FunctionChain` class to help with chaining the individually-imported operators. Fixes angular#2622.
- Loading branch information
Showing
18 changed files
with
296 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {FunctionChain} from './function-chain'; | ||
|
||
describe('FunctionChain', () => { | ||
it('should chain functions', () => { | ||
let first = jasmine.createSpy('First function'); | ||
let second = jasmine.createSpy('Second function'); | ||
let third = jasmine.createSpy('Third function'); | ||
|
||
new FunctionChain().call(first).call(second).call(third).execute(); | ||
|
||
expect(first).toHaveBeenCalled(); | ||
expect(second).toHaveBeenCalled(); | ||
expect(third).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should pass in arguments to the functions', () => { | ||
let first = jasmine.createSpy('First function'); | ||
let second = jasmine.createSpy('Second function'); | ||
|
||
new FunctionChain().call(first, 1, 2).call(second, 3, 4).execute(); | ||
|
||
expect(first).toHaveBeenCalledWith(1, 2); | ||
expect(second).toHaveBeenCalledWith(3, 4); | ||
}); | ||
|
||
it('should clear the chain once it has been executed', () => { | ||
let fn = jasmine.createSpy('Spy function'); | ||
let chain = new FunctionChain().call(fn); | ||
|
||
chain.execute(); | ||
expect(fn).toHaveBeenCalledTimes(1); | ||
|
||
chain.execute(); | ||
expect(fn).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should return the final function result', () => { | ||
let result = new FunctionChain() | ||
.context([1, 2, 3, 4, 5]) | ||
.call(Array.prototype.map, (current: number) => current * 2) | ||
.call(Array.prototype.filter, (current: number) => current > 5) | ||
.execute(); | ||
|
||
expect(result).toEqual([6, 8, 10]); | ||
}); | ||
}); |
Oops, something went wrong.