Reactive-Redux Store.select两次触发

时间:2016-08-10 13:04:14

标签: angular rxjs ngrx

通过behaviorSubject定义动作管道并将ngrx / store作为Observer订阅它有什么好处?

例如

SomeModel() {
  actionPipelines = new BehaviorSubject<Action>({type:null, payload:null});

  actionPipelines.filter(Filter1).map(Map1).mergeMap(Svc1(),SomeAction1());
  actionPipelines.filter(Filter2).map(Map2).mergeMap(Svc2(),SomeAction2());
  Observable.merge(actionPipelines).subscribe(store);
  //Data is manipulated in Reducer code and stored under store.dataReducer
  this.storedData$ = this.store.select<Data>('dataReducer').map(someExpr);

  loadData() { this.actionPipeline.next(Filter2); }
}


@Component(
  selector: 'component',
  template: '<div>Data Display {model.storedData$ | async}</div>'
)
MyComponent(model: SomeModel) {
  constructor() { this.model.loadData(); }
}

0 个答案:

没有答案