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

[redux] Entities/resource pattern with redux-saga-thunk #273

Open
brandoniffert opened this issue Jun 10, 2017 · 3 comments
Open

[redux] Entities/resource pattern with redux-saga-thunk #273

brandoniffert opened this issue Jun 10, 2017 · 3 comments
Labels

Comments

@brandoniffert
Copy link

brandoniffert commented Jun 10, 2017

From the redux-saga-thunk docs:

store.dispatch(resourceCreateRequest({ title: 'foo' })).then((detail) => {
  // detail is the action payload property
  console.log('Yaay!', detail)
}).catch((error) => {
  // error is the action payload property
  console.log('Oops!', error)
})

I'm using the entities/resource pattern outlined in this repo and it seems that detail above is always the id of the resource I am creating/updating. I'm assuming this is so it works with the entities/normalizr pattern? Is there any way to have it return the actual entity object or get access to it somehow from within the resource dispatch promise? I am using resource dispatches a lot in redux-form onSubmits.

Thank you

@diegohaz
Copy link
Owner

Does this work for you?

import { fromEntities } from 'store/selectors'

store.dispatch(resourceCreateRequest('posts', { title: 'foo' })).then((id) => {
  const detail = fromEntities.getDetail(store.getState(), 'posts', id)
  console.log('Yaay!', detail)
})

@diegohaz diegohaz changed the title Entities/resource pattern with redux-saga-thunk [redux] Entities/resource pattern with redux-saga-thunk Jun 10, 2017
@brandoniffert
Copy link
Author

Seems like it would but I am trying to use it inside a redux-form onSubmit function so I wouldn't necessarily have access to the current state.

https://github.com/diegohaz/arc/blob/redux-ssr/src-example/containers/PostForm.js#L10

const onSubmit = (data, dispatch) => dispatch(resourceCreateRequest('posts', data))

Trying to do something like that and then have access to the response object from the create/update API call all within onSubmit.

@alduro
Copy link

alduro commented Apr 20, 2018

@brandoniffert I'm facing the same issue. Did you solve that someway ? Tks.

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