byte-fe / react-model

The next generation state management library for React
236 stars 23 forks source link

Need executed `setter` from `stateUpdater` communicator middleware #166

Open tianyingchun opened 3 years ago

tianyingchun commented 3 years ago

Cause of the __hash function setter has been executed in stateUpdater: Middleware

we don't need to executed this __hash state update again in communicator middleware, i think it should be changed to

 if (Global.Setter.functionSetter[modelName]) {
    Object.keys(Global.Setter.functionSetter[modelName]).map((hash) => {
      const setter = Global.Setter.functionSetter[modelName][hash];
      // If we need to exclude executed `setter` from `stateUpdater`
      // we should exclude `__hash` once __hash  has been executed in `stateUpdatater` middleware.
      if (setter && __hash !== hash) {
        if (!setter.selector) {
          setter.setState(Global.State[modelName]);
        } else {
          const newSelectorRef = setter.selector(Global.State[modelName]);
          if (!shallowEqual(newSelectorRef, setter.selectorRef)) {
            setter.selectorRef = newSelectorRef;
            setter.setState(Global.State[modelName]);
          }
        }
      }
    });
  }