Open
Description
I know #12 includes some discussion about optimistic updates, but my topic is not related to FSA, so I decide to open an new issue.
I've been thinking about how optimistic UI should land in a redux architecture, as a conclusion I discovered:
- Optimistic updates are not always the "success part" of non-optimistic updates, they can vary from each other
- It's not really good to pollute hundreds of actions in order to have optimistic updates, it could be hard if we need "optimistic in some situations but without optimistic otherwise"
- Optimistic should be an add-on part, easy to plug in or out on demand.
As a result I developed a optimistic updates supported middleware based on redux-thunk: redux-optimistic-thunk
I think this pattern can also easily apply to promise based architecture:
- Just consume an array with 2 items
[Promise, Action]
- The first is a
Promise
which works the same as current redux-promise - The second is a plain object action which will be dispatched immediately to make optimistic updates
- Just remember the state before optimistic actions are dispatched, as well as all actions after a state is remembered, rollback them after Promise fulfills
I've thought about developing a redux-optimistic-promise
middleware myself, but it seems to be better if redux-promise can support it directly, since an array is a brand new type of action, this will have no backward compatibility issues
Metadata
Metadata
Assignees
Labels
No labels