-
Notifications
You must be signed in to change notification settings - Fork 0
performAction
Michael Niday edited this page Jun 6, 2018
·
1 revision
-
action(string): you must specify these actions first in your resource_config file -
options(object)
- itemId: In POST /contacts/:id this would populate the
:id - data (object): In POST /contacts this would be body request data
- filters (Immutable.Map): In GET /contacts this would be query params used in fetching the resource
- responseStrategy (string): How to reconcile the response data for the store
- onSuccess (Function): Callback that gets called when ApiClient promise resolves
- onError (Function): Callback that gets called when request errors
The way in which a performAction's response will be applied to the store. There are 5 strategies that can be applied, ['append', 'prepend', 'ignore', 'replace', 'subtract'].
-
appendapplies the response ids to the store after the existing ids in the store. -
prependapplies the response ids to the store before the existing ids in the store. -
ignorereturns with an empty object, this also happens when there are no ids returned in the response. -
replaceapplies the response ids to the store without the formerly existing ids in the store. This is also the default responseStrategy if none is explictly set. -
subtractremoves the response ids from the existing ids in the store.
// In a React component
...
handleGetPerson = (url) => {
this.props.people.performAction('fetch', {
itemId: idFromUrl(url),
responseStrategy: 'ignore',
onSuccess: ({data}) => {
this.setState({selectedPersonId: data.id})
this.fetchPlanet(data.homeworld)
}
})
}
...
export default entities({people: {type: 'people'}})(Component)
Here people is both the name of the container prop provided to Component and the record type defined in records.js