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 redux-optimist #55

Closed
fresk-nc opened this issue Mar 15, 2016 · 5 comments
Closed

Add redux-optimist #55

fresk-nc opened this issue Mar 15, 2016 · 5 comments
Labels

Comments

@fresk-nc
Copy link

Do you want to add support "optimistically apply actions" with module redux-optimist?

@fresk-nc fresk-nc changed the title add redux-optimist Add redux-optimist Mar 15, 2016
@barrystaes
Copy link
Contributor

Is this not already supported?
From the redux-optimist docs it appears a root optimist reducer (wrapping other reducers) and adding the optimist key in each FSA that your RSAA makes would work.. would it not?

Have not (yet) used it myself though.

@fresk-nc
Copy link
Author

How can I add optimist: {type: COMMIT, id: transactionID} for success action?

@barrystaes
Copy link
Contributor

A quick search tells me that since 0.2.1 you can put optimist in meta so its a FSA compliant.

So i guess something like..

{
  [CALL_API]: {
    endpoint: 'http://www.example.com/api/users',
    method: 'GET',
    types: [
      'REQUEST',
      {
        type: 'SUCCESS',
        payload: (action, state, res) => {
          // whatever
        },
        meta: (action, state, res) => {
          optimist: {type: COMMIT, id: res.transactionID}          //    <---
        }
      },
      'FAILURE'
    ]
  }
}

But ofcourse for REQUEST and FAILURE you would have to also use optimist keys, and instead of getting the transaction id returned in a response you may want to use action or state to get it.

If you got this to work, we'd be happy to hear! I am going to have to do optimistic updates too in the foreseeable future.

@typeofweb
Copy link

@barrystaes did you ever manage to implement this?

@barrystaes
Copy link
Contributor

@mmiszy Not this specific example. And I never put redux-api-middleware in actual production use so my experience using it is/was very limited. Having todays experience i'd probably just use a ES6 promise in the called action to achieve this.

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

3 participants