0

I'm trying to handle an action which depends on the result of another action.

I have a form component to CREATE/UPDATE 2 entities :

  1. Submit form
  2. First call APIAction.save and save "parentEntityData"
  3. Second call APIAction.save and save "childEntityData" with the "parentEntityData" id received from server.

Does it make sense to add a callback to action payload ?

APIAction.save({
    entity: 'parentEntity',
    model: parentModel,
    next: (parentEntityId) => {
        APIAction.save({
            entity: 'childEntity',
            model: childModel.set('parentId', parentEntityId)
        })          
    }
})
AniZ
  • 21
  • 1
  • 1
  • 4

1 Answers1

0

For communicating with server, having one flux-action that sends off 2 messages to server is probably OK. Depends on what the server side is capable of handling.

The server might respond 2x also, so your stores and components should be prepared to handle server response properly.

So you may have to do special stuff in your stores/components if you want to prevent the 2 server responses to trigger 2 render cycles.

On the client side, 1 flux action (the submit action) should not generate more than 1 dispatch.

wintvelt
  • 13,855
  • 3
  • 38
  • 43