refactor(router): cleanup to navigation stream for readability and documentation (#25740)
* Pull out `activateRoutes` into new operator * Add `asyncTap` operator * Use `asyncTap` operator for router hooks and remove corresponding abstracted operators * Clean up formatting * Minor performance improvements PR Close #25740
This commit is contained in:

committed by
Kara Erickson

parent
12ccf57340
commit
64aa6701f6
29
packages/router/src/operators/switch_tap.ts
Normal file
29
packages/router/src/operators/switch_tap.ts
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @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 {MonoTypeOperatorFunction, ObservableInput, from} from 'rxjs';
|
||||
import {map, switchMap} from 'rxjs/operators';
|
||||
|
||||
/**
|
||||
* Perform a side effect through a switchMap for every emission on the source Observable,
|
||||
* but return an Observable that is identical to the source. It's essentially the same as
|
||||
* the `tap` operator, but if the side effectful `next` function returns an ObservableInput,
|
||||
* it will wait before continuing with the original value.
|
||||
*/
|
||||
export function switchTap<T>(next: (x: T) => void|ObservableInput<any>):
|
||||
MonoTypeOperatorFunction<T> {
|
||||
return function(source) {
|
||||
return source.pipe(switchMap(v => {
|
||||
const nextResult = next(v);
|
||||
if (nextResult) {
|
||||
return from(nextResult).pipe(map(() => v));
|
||||
}
|
||||
return from([v]);
|
||||
}));
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user