本文整理匯總了TypeScript中rxjs/operators.takeUntil函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript takeUntil函數的具體用法?TypeScript takeUntil怎麽用?TypeScript takeUntil使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了takeUntil函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should dispose notifier if source observable completes', () => {
const e1 = hot('--a--| ');
const e1subs = '^ ! ';
const e2 = hot('-------x--|');
const e2subs = '^ ! ';
const expected = '--a--| ';
expectObservable(e1.pipe(takeUntil(e2))).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});
示例2: ngOnInit
// -----------------------------------------------------------------------------------------------------
// @ Lifecycle hooks
// -----------------------------------------------------------------------------------------------------
/**
* On init
*/
ngOnInit(): void
{
// Subscribe to config changes
this._fuseConfigService.config
.pipe(takeUntil(this._unsubscribeAll))
.subscribe(
(config) => {
this.fuseConfig = config;
}
);
}
示例3: asDiagram
asDiagram('takeUntil')('should take values until notifier emits', () => {
const e1 = hot('--a--b--c--d--e--f--g--|');
const e1subs = '^ ! ';
const e2 = hot('-------------z--| ');
const e2subs = '^ ! ';
const expected = '--a--b--c--d-| ';
expectObservable(e1.pipe(takeUntil(e2))).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});
示例4: switchMap
switchMap(() => merge( // then emit every 500ms, and when the navigation ends or cancels or errors. This delay must
// match the transition duration in the .scss file
timer(0, 500).pipe(
map(i => 100 - (100 / Math.pow(2, i))), // emit 0 then 50, 75, 87.5, etc.
takeWhile(i => i < 99.95), // stop because that just triggers change detection with no visual change anymore
takeUntil(end$), // but stop emitting every 500ms when the navigation ends or cancels or errors
map(i => ({ value: i }))
),
end$.pipe(first(), map(() => null)) // set back to null when the navigation ends or cancels or errors to hide
// the progress bar
))