标签: component-store

ngrx/component-store 状态改变时触发效果

我有一个有角度的应用程序@ngrx/component-store

当用户从设备列表中选择一个条目时,我将其存储到component-store

  component.ts:
  onDeviceClicked(device: DeviceTO) {
    this.inspectionStore.setDeviceSelected(device);
  }

  inspectionStore.ts
  readonly setDeviceSelected = (data: DeviceTO) =>  {this.patchState({selectedDevice: data})};
Run Code Online (Sandbox Code Playgroud)

现在,用户已经选择了设备,应该会触发副作用。但是,我不确定当部分状态发生变化时如何触发副作用。

更新状态时需要这样做吗?

  readonly setDeviceSelected = (data: DeviceTO) =>  {
    this.patchState({selectedDevice: data});
    this.tiggerMySideEffect(data);
  };
Run Code Online (Sandbox Code Playgroud)

或者有其他方法可以告诉 sideEffect 监听变化吗?

ngrx-store component-store

8
推荐指数
1
解决办法
4379
查看次数

标签 统计

component-store ×1

ngrx-store ×1