本文整理汇总了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();
}