Ngxs Store中的快照和选择快照有什么不同?
我知道如何使用快照,它会获取当前状态值。
this.oriFormData = this.store.snapshot();
因此,当重置时,我像这样重置商店
this.store.reset(this.oriFormData);
是否可以使用selectsnapshot方法来选择一个/多个状态,而不是使用快照来获取整个应用程序的状态?
发布于 2020-05-23 19:03:32
你有没有考虑过使用选择器,@Select()
@Select(ZooState.pandas) pandas$: Observable<string[]>;
@Select(FoodState.leafs) leafs$: Observable<string[]>;然后使用一些rxjs魔法
let pandasAndLeafs;
[pandas$, leafs$].pipe(combineAll()).subscribe(dinner => (pandasAndLeafs = dinner));
console.log(pandasAndLeafs);发布于 2020-05-19 11:00:17
是的,您可以使用selectSnapshot来获取特定状态的当前状态值,所使用的语法与从存储中执行常规select时使用的语法相同。
例如。
store.selectSnapshot(MyState)或store.selectSnapshot(state => state.myState)
传递静态选择器也是有效的,例如store.selectSnapshot(MyState.mySelector)
https://stackoverflow.com/questions/61882087
复制相似问题