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


TypeScript store.Dispatcher类代码示例

本文整理汇总了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;未经允许,请勿转载。