Skip to content

performAction

Michael Niday edited this page Jun 6, 2018 · 1 revision

Arguments

  1. action (string): you must specify these actions first in your resource_config file
  2. options (object)

Options:

  • 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

responseStrategy

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'].

  • append applies the response ids to the store after the existing ids in the store.
  • prepend applies the response ids to the store before the existing ids in the store.
  • ignore returns with an empty object, this also happens when there are no ids returned in the response.
  • replace applies 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.
  • subtract removes the response ids from the existing ids in the store.

Example

// 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

Clone this wiki locally