当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Subject.observeOn方法代码示例

本文整理汇总了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();
    }
开发者ID:KallynGowdy,项目名称:RxUI,代码行数:50,代码来源:reactive-command.ts


注:本文中的rxjs/Rx.Subject.observeOn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。