NGRX存储中的阵列发生更改时,可观察到的更新

时间:2018-12-07 21:55:53

标签: angular ngrx ngrx-store ngrx-effects

当NGRX商店中保存的货物发生变化时,我需要更新一个可观察值。目前,我使用选择器来选择数组列表,但是我不确定这是否是非常有效的代码,因为我希望它仅在选择器返回另一个数组对象时才调用下一个函数。

这是我的代码:

 this.store.select<any[]>(getConnections(Id))
                .takeUntil(this.onDestroy$).subscribe(connections => {
                    this.selectDataStream.next(connections);
                });

选择器:

export const getConnections = (id) => createSelector(selectFinderResults, entities => {
    return entities[id].connections;
});

减速器:

 case LOAD_INTEGRATOR_CONNECTIONS_SUCCESS: {
          let payload = (action as LoadConnectionsSuccessAction).payload;
          let integratorId = (action as LoadConnectionsSuccessAction).integratorId;

          if (payload) {

              const integratorModel = state.connectorresults[integratorId];

              const updatedstate = {
                  ...state,
                  connectorresults: {
                      ...state.connectorresults,
                      [integratorId]: {
                          ...integratorModel,
                          connections: payload
                      }
                  },
                  searchconnectorresults: {
                      ...state.searchconnectorresults,
                      [integratorId]: {
                          ...integratorModel,
                          connections: payload
                      }
                  }
              };

              return {
                  ...updatedstate
              };
          }


      }

这是在连接列表更改时触发主题下一个功能的最佳方法吗?我希望它触发多次,但只能在列表更改时触发,但似乎并没有这样做。

0 个答案:

没有答案