當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。