refactor(router): create pipeable recognize function (#25740)

PR Close #25740
This commit is contained in:
Jason Aden
2018-07-25 17:19:58 -07:00
committed by Kara Erickson
parent 549de1e21a
commit 2b2e841e5b
2 changed files with 43 additions and 13 deletions

View File

@ -0,0 +1,28 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* 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 {Type} from '@angular/core';
import {Observable, OperatorFunction} from 'rxjs';
import {mergeMap} from 'rxjs/operators';
import {Route} from '../config';
import {recognize as recognizeFn} from '../recognize';
import {RouterStateSnapshot} from '../router_state';
import {UrlTree} from '../url_tree';
export function recognize(
rootComponentType: Type<any>| null, config: Route[], serializer: (url: UrlTree) => string,
paramsInheritanceStrategy: 'emptyOnly' |
'always'): OperatorFunction<UrlTree, RouterStateSnapshot> {
return function(source: Observable<UrlTree>) {
return source.pipe(mergeMap(
(appliedUrl: UrlTree) => recognizeFn(
rootComponentType, config, appliedUrl, serializer(appliedUrl),
paramsInheritanceStrategy)));
};
}