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

add Recipe for Optimistic UI #139

Open
cometta opened this issue Nov 9, 2016 · 1 comment
Open

add Recipe for Optimistic UI #139

cometta opened this issue Nov 9, 2016 · 1 comment

Comments

@cometta
Copy link

cometta commented Nov 9, 2016

Can add example of Cashay+Optimistic UI for Recipe

@mattkrick
Copy link
Owner

That's a really good idea.
Note that I'm hoping to change the API in the months ahead, but for now, you write a mutation handler like this:

  updateUserProfile(optimisticVariables, queryResponse, currentResponse) {
    if (optimisticVariables) {
      Object.assign(currentResponse.user, optimisticVariables.updatedProfile);
    } else if (queryResponse) {
      Object.assign(currentResponse.user, queryResponse);
    }
    return currentResponse;
  },

This function runs twice. Once with optimisticVariables and again with a queryResponse (what comes back from the server). So, if you want to do something optimistically, you just check for optimisticVariables & mutate the object however you like. Those mutations get back propagated to the normalized state. Still not sure I love mutating it, but it's SO much easier than imperatively creating an object inside an object inside an array inside an object....

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

2 participants