NGXS 重用状态(扩展状态类)

its*_*ers 5 javascript redux angular ngxs

有一种东西叫作文。https://ngxs.gitbook.io/ngxs/advanced/composition

我希望它能让我为所有网格构建可重用状态。喜欢:

@State<GridStateModel<any>>({
  name: 'basegridstate',
  defaults: {
    total: 0,
    rows: []
  }
})
export class BaseGridState {

  @Action(LoadGridRows)
  loadRows({patchState, dispatch, setState}: StateContext<GridStateModel<any>>) {
    patchState({
      total: 2,
    });
  }

}
Run Code Online (Sandbox Code Playgroud)

然后我想将其扩展很多次,以便在每个网格中使用以获得自己的数据。

喜欢

@State<GridStateModel<Product>>({
  name: 'cataloggrid',
  defaults: {
    total: 0,
    rows: []
  }
})
export class CatalogGridState extends BaseGridState {

  @Action(LoadCatalogRows)
  loadCatalogRows({patchState, dispatch, setState}: StateContext<GridStateModel<any>>) {
    patchState({
      total: 3,
    });
    dispatch(new LoadGridRows());
  }

}
Run Code Online (Sandbox Code Playgroud)

但问题是在扩展基数一的所有其他状态上调度调用 LoadGridRows :(

有没有办法让它只在当前状态下工作?或者也许有其他方法可以重用具有相同逻辑但自定义数据的状态?