logux / redux

Redux compatible API for Logux
https://logux.org/
MIT License
127 stars 16 forks source link

fix: undo didchange condition #47

Closed DecathectZero closed 2 years ago

DecathectZero commented 2 years ago

I spoke with @effervescentia about this fix on https://github.com/logux/redux/pull/46

All that mattered was the wait and delete wait[id]. The boolean return and the didChange was more of an optimization.

However if didChange is false, we might miss an action that we've added and never get back a 'change' event emitted.

It seems like there's nowhere in logux itself that listens for the 'change' event, but we've actually found it necessary to listen for it to enable a "partialSync":

export const createPartialSync =
  (store: Store) =>
  <T extends AnyAction>(action: T) =>
    new Promise<ClientMeta>((resolve) => {
      const meta: Record<string, any> = { sync: true };
      // this will mutate meta and add "id"
      store.log.add(action, meta);

      const unbind = store.on('change', (_state, _prevState, _action, changeMeta) => {
        if (meta.id === changeMeta.id) {
          resolve(meta);
          unbind();
        }
      });
    });
ai commented 2 years ago

What is the best explanation for ChangeLog of these changes?