• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript store.Dispatcher类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@ngrx/store.Dispatcher的典型用法代码示例。如果您正苦于以下问题:TypeScript Dispatcher类的具体用法?TypeScript Dispatcher怎么用?TypeScript Dispatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Dispatcher类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: connect

  connect(nextCallbackFn: (state: any) => void) {
    this._liftedDispatcher
      .let(this._preMiddleware)
      .map(liftAction)
      .merge(this._dispatcher)
      .scan((state: LiftedState, action) => this._reducer(state, action), this._initialLiftedState)
      .do((liftedState: LiftedState) => this.liftedState.next(liftedState))
      .map(unliftState)
      .filter(state => state !== undefined)
      .let(this._postMiddleware)
      .subscribe(nextCallbackFn);

    this._init();
  }
开发者ID:dmackerman,项目名称:devtools,代码行数:14,代码来源:devtools.ts


示例2: constructor

  constructor(
    dispatcher: DevtoolsDispatcher,
    actions$: Dispatcher,
    reducers$: Reducer,
    initialState: any,
    options: Options,
    extension: Extension
  ) {
    const liftedInitialState = liftInitialState(initialState, options.monitor);
    const liftReducer = liftReducerWith(initialState, liftedInitialState, options.monitor, {
      maxAge: options.maxAge
    });

    const liftedActions$ = actions$
      .skip(1)
      .merge(extension.actions$)
      .map(liftAction)
      .merge(dispatcher, extension.liftedActions$)
      .observeOn(queue);

    const liftedReducers$ = reducers$
      .map(liftReducer);

    const liftedState = liftedActions$
      .withLatestFrom(liftedReducers$)
      .scan((liftedState, [ action, reducer ]) => {
        const nextState = reducer(liftedState, action);

        extension.notify(action, nextState);

        return nextState;
      }, liftedInitialState)
      .publishReplay(1)
      .refCount();

    const state = liftedState
      .map(unliftState);

    this.dispatcher = dispatcher;
    this.liftedState = liftedState;
    this.state = state;
  }
开发者ID:dballance,项目名称:store-devtools,代码行数:42,代码来源:devtools.ts


示例3: describe

  describe('SagaRunner', function() {
    let runner: SagaRunner;
    let child: SagaRunner;
    let dispatcher: Dispatcher<Action>;

    beforeEach(() => {
      const rootInjector = Injector.resolveAndCreate([ Dispatcher, SagaRunner ]);
      const childInjector = rootInjector.resolveAndCreateChild([ SagaRunner ]);

      runner = rootInjector.get(SagaRunner);
      child = childInjector.get(SagaRunner);
      dispatcher = rootInjector.get(Dispatcher);
    });

    it('should resolve the parent SagaRunner if it is available', function() {
      expect(child).not.toBe(runner);
      expect(child.parent).toBe(runner);
    });

    it('should let you run an effect', function() {
      let factoryCalled = false;
      let sagaCalled = false;
      const effect = createSaga(() => {
        factoryCalled = true;
        return () => {
          sagaCalled = true;

          return Observable.empty();
        }
      });

      runner.run(effect);
      expect(factoryCalled).toBe(true);
      expect(sagaCalled).toBe(true);
    });

    it('should let you pause an effect', function() {
      const watch = 'Watch';
      const next = 'Next';
      const effect = createSaga(() => saga$ => saga$
        .filter(whenAction(watch))
        .map(() => ({ type: next }))
      );
      let callCount = 0;

      dispatcher.filter(action => action.type === next).subscribe(() => {
        ++callCount;
      });

      runner.run(effect);
      runner.next({ action: { type: watch }, state: {} });
      runner.pause(effect);
      runner.next({ action: { type: watch }, state: {} });

      expect(callCount).toEqual(1);
    });

    it('should not call the injector when restarting a paused effect', function() {
      let callCount = 0;
      const effect = createSaga(() => {
        ++callCount;
        return saga$ => saga$.filter(() => false);
      });

      runner.run(effect);
      runner.pause(effect);
      runner.run(effect);

      expect(callCount).toEqual(1);
    });

    it('should use the injector to resolve a stopped effect', function() {
      let callCount = 0;
      const effect = createSaga(() => {
        ++callCount;
        return saga$ => saga$.filter(() => false);
      });

      runner.run(effect);
      runner.stop(effect);
      runner.run(effect);

      expect(callCount).toEqual(2);
    });

    it('should call parent methods if the parent is set', function() {
      spyOn(runner, 'next');
      spyOn(child, '_next');
      spyOn(runner, 'stop');
      spyOn(child, '_stop');
      spyOn(runner, 'pause');
      spyOn(child, '_pause');
      spyOn(runner, 'run');
      spyOn(child, '_run');

      const effect = createSaga(() => saga$ => saga$.filter(() => false));

      child.next({ action: {}, state: {} });
      child.run(effect);
      child.pause(effect);
//.........这里部分代码省略.........
开发者ID:robwormald,项目名称:store-saga,代码行数:101,代码来源:index.spec.ts


示例4: it

  it('should let you filter out actions', function() {
    const actions = [ ADD, ADD, SUBTRACT, ADD, SUBTRACT ];
    const expected = actions.filter(type => type === ADD);

    stateUpdates$
      .whenAction(ADD)
      .map(update => update.action.type)
      .toArray()
      .subscribe({
        next(actual) {
          expect(actual).toEqual(expected);
        }
      });

    actions.forEach(action => dispatcher.dispatch({ type: action }));
    dispatcher.complete();
  });
开发者ID:Merott,项目名称:effects,代码行数:17,代码来源:state-updates.spec.ts


示例5: it

    it('should let you pause an effect', function() {
      const watch = 'Watch';
      const next = 'Next';
      const effect = createSaga(() => saga$ => saga$
        .filter(whenAction(watch))
        .map(() => ({ type: next }))
      );
      let callCount = 0;

      dispatcher.filter(action => action.type === next).subscribe(() => {
        ++callCount;
      });

      runner.run(effect);
      runner.next({ action: { type: watch }, state: {} });
      runner.pause(effect);
      runner.next({ action: { type: watch }, state: {} });

      expect(callCount).toEqual(1);
    });
开发者ID:robwormald,项目名称:store-saga,代码行数:20,代码来源:index.spec.ts


示例6: reset

 reset() {
   this.dispatcher.dispatch({ type: RESET });
 }
开发者ID:petebacondarwin,项目名称:angular2-webpack2-ngrx-starter,代码行数:3,代码来源:counter.store.ts


示例7: decrement

 decrement() {
   this.dispatcher.dispatch({ type: DECREMENT });
 }
开发者ID:petebacondarwin,项目名称:angular2-webpack2-ngrx-starter,代码行数:3,代码来源:counter.store.ts


示例8: increment

 increment() {
   this.dispatcher.dispatch({ type: INCREMENT });
 }
开发者ID:petebacondarwin,项目名称:angular2-webpack2-ngrx-starter,代码行数:3,代码来源:counter.store.ts


示例9:

 actions.forEach(action => dispatcher.dispatch(action));
开发者ID:christophercr,项目名称:effects,代码行数:1,代码来源:actions.spec.ts


示例10: complete

 complete() {
   this._dispatcher.complete();
 }
开发者ID:dmackerman,项目名称:devtools,代码行数:3,代码来源:devtools.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript store.Reducer类代码示例发布时间:2022-05-28
下一篇:
TypeScript store.ActionReducer类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap