0

通过 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(); }
}
4

0 回答 0