本文整理匯總了TypeScript中rxjs/Rx.Subject.observeOn方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Subject.observeOn方法的具體用法?TypeScript Subject.observeOn怎麽用?TypeScript Subject.observeOn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rxjs/Rx.Subject
的用法示例。
在下文中一共展示了Subject.observeOn方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: constructor
/**
* Creates a new Reactive Command.
* @param canRun An observable that determines whether the given task is allowed to run at a given moment.
* @param task A function that returns an observable that represents the asynchronous operation.
* @param scheduler The scheduler that all of the results should be observed on.
*/
constructor(private task: (args: TArgs) => Observable<TResult>, private canRun: Observable<boolean>, private scheduler: Scheduler) {
if (!task) {
throw new Error("The task parameter must be supplied");
}
if (!canRun) {
throw new Error("The canRun parameter must be supplied");
}
if (!scheduler) {
throw new Error("The scheduler parameter must be supplied");
}
this._executionInfo = new Subject<ExecutionInfo<TResult>>();
this._synchronizedExcecutionInfo = this._executionInfo;
this._exceptions = new Subject<any>();
// Implementation mostly taken from:
// https://github.com/reactiveui/ReactiveUI/blob/rxui7-master/ReactiveUI/ReactiveCommand.cs#L628
this._isExecuting = this._synchronizedExcecutionInfo
.observeOn(scheduler)
.map(info => info.demarcation === ExecutionDemarcation.Begin)
.startWith(false)
.distinctUntilChanged()
.publishReplay(1)
.refCount();
this._canExecute = this.canRun
.catch(ex => {
this._exceptions.next(ex);
return Observable.of(false);
})
.startWith(false)
.combineLatest(this._isExecuting, (canRun, isExecuting) => {
return canRun && !isExecuting;
})
.distinctUntilChanged()
.publishReplay(1)
.refCount();
this._results = this._synchronizedExcecutionInfo
.observeOn(scheduler)
.filter(info => info.demarcation === ExecutionDemarcation.EndWithResult)
.map(info => info.result);
// Make sure that can execute is triggered to be a hot observable.
this._canExecuteSubscription = this._canExecute.subscribe();
}