Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some thoughts on optimistic updates #51

Open
otakustay opened this issue Apr 18, 2017 · 0 comments
Open

Some thoughts on optimistic updates #51

otakustay opened this issue Apr 18, 2017 · 0 comments

Comments

@otakustay
Copy link

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:

  1. Optimistic updates are not always the "success part" of non-optimistic updates, they can vary from each other
  2. 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"
  3. 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:

  1. Just consume an array with 2 items [Promise, Action]
  2. The first is a Promise which works the same as current redux-promise
  3. The second is a plain object action which will be dispatched immediately to make optimistic updates
  4. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant