-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Params): Simplify params services by removing select method
Remove the select method from RouteParams and QueryParams. Simplify both services by giving them an abstract token for DI and a simple projection factory. Remove the replace method from QueryParams. Add new search method to Location to update query params. BREAKING CHANGE: select method removed from QueryParams and RouteParams. Use pluck instead: BEFORE: ```ts routeParams.select('id').subscribe(id => {}); ``` AFTER: ```ts routeParams.pluck('id').subscribe(id => {}); ```
- Loading branch information
1 parent
86c0e52
commit af160d7
Showing
9 changed files
with
131 additions
and
239 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'rxjs/add/operator/map'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import { Provider } from 'angular2/core'; | ||
|
||
import { RouteSet } from './route-set'; | ||
|
||
export abstract class RouteParams extends Observable<{ [param: string]: any }> { } | ||
export abstract class QueryParams extends Observable<{ [param: string]: any }> { } | ||
|
||
function createRouteParams(set$: RouteSet): RouteParams { | ||
return set$.map(next => next.params); | ||
} | ||
|
||
function createQueryParams(set$: RouteSet): QueryParams { | ||
return set$.map(next => next.query); | ||
} | ||
|
||
export const PARAMS_PROVIDERS = [ | ||
new Provider(RouteParams, { | ||
deps: [ RouteSet ], | ||
useFactory: createRouteParams | ||
}), | ||
new Provider(QueryParams, { | ||
deps: [ RouteSet ], | ||
useFactory: createQueryParams | ||
}) | ||
]; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,54 @@ | ||
import { Subject } from 'rxjs/Subject'; | ||
import { Injector, provide } from 'angular2/core'; | ||
import { NextRoute, RouteSet } from '../lib/route-set'; | ||
import { RouteParams, QueryParams, PARAMS_PROVIDERS } from '../lib/params'; | ||
|
||
|
||
describe('Params Services', function() { | ||
let routeSet$: Subject<NextRoute>; | ||
let routeParams$: RouteParams; | ||
let queryParams$: QueryParams; | ||
|
||
beforeEach(function() { | ||
routeSet$ = new Subject<NextRoute>(); | ||
const injector = Injector.resolveAndCreate([ | ||
PARAMS_PROVIDERS, | ||
provide(RouteSet, { useValue: routeSet$ }) | ||
]); | ||
|
||
routeParams$ = injector.get(RouteParams); | ||
queryParams$ = injector.get(QueryParams); | ||
}); | ||
|
||
afterEach(function() { | ||
routeSet$.complete(); | ||
}); | ||
|
||
describe('RouteParams', function() { | ||
it('should project route params from the current route set', function(done) { | ||
const params = { id: 123 }; | ||
|
||
routeParams$.subscribe(value => { | ||
expect(value).toBe(params); | ||
|
||
done(); | ||
}); | ||
|
||
routeSet$.next({ routes: [], params, url: '', query: {} }); | ||
}); | ||
}); | ||
|
||
describe('QueryParams', function() { | ||
it('should project query params from the current route set', function(done) { | ||
const query = { search: 'abcd' }; | ||
|
||
queryParams$.subscribe(value => { | ||
expect(value).toBe(query); | ||
|
||
done(); | ||
}); | ||
|
||
routeSet$.next({ routes: [], params: {}, url: '', query }); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.