logux / redux

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

Question: Why dispatch.sync applies action to the store asynchronously? #44

Closed mifopen closed 2 years ago

mifopen commented 2 years ago

In Redux we have one useful guarantee: dispatch applies changes to the store synchronously. It means that we can get a new version of the state immediately after dispatching an action. But with dispatch.local or dispatch.sync it's achievable only by awaiting the result of the functions which actually kills the optimistic approach of applying changes. I'm wondering was it an intentional design decision and if yes then what are the implications of applying changes synchronously (like in simple dispatch implementation).

ai commented 2 years ago

Mostly because of async nature of Logux Core (we need async to be compatible with IndexedDB).

Note, that we recommend switching to syncMap (check API for defineSyncMap on client and addSyncMap on server). It provides better DX.