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

Allow restoring a tree path to a previous value #43

Open
drborges opened this issue Dec 29, 2017 · 0 comments
Open

Allow restoring a tree path to a previous value #43

drborges opened this issue Dec 29, 2017 · 0 comments
Labels

Comments

@drborges
Copy link
Owner

drborges commented Dec 29, 2017

This would essentially allow one to "rollback" mutations to a certain path. For optimistic UIs this means we'd be able to easily rollback UI changes upon API request failures:

store.subscribe("/users/:index", async (newUser, oldUser, restore) => {
  const response = await api.users.update(newUser)
  if (response.status >= 400) {
    restore(oldUser).errors.push(response.message)
  }
})

Subscribers would receive a restore function as the third argument, to be called with the previous value of the mutated node, returning the restored node allowing further method chaining.

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

No branches or pull requests

1 participant