本文整理匯總了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();
}
示例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;
}
示例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);
//.........這裏部分代碼省略.........
示例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();
});
示例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);
});
示例6: reset
reset() {
this.dispatcher.dispatch({ type: RESET });
}
示例7: decrement
decrement() {
this.dispatcher.dispatch({ type: DECREMENT });
}
示例8: increment
increment() {
this.dispatcher.dispatch({ type: INCREMENT });
}
示例9:
actions.forEach(action => dispatcher.dispatch(action));
示例10: complete
complete() {
this._dispatcher.complete();
}