jeudi 21 février 2019

the best way to get an action result

I'm curious if getting an action result is a valid approach, and if it is then how to do that?

For example let's say I have a page with form for creating entities, after successful entity creation I'd like to redirect user to entity's detail view, otherwise (on failure) update the form by error messages. I'd like to perform that without mixing up application layers (eg. to not redirect user in epic/effect after success).

I have a few approaches to this problem in mind:

  1. dispatch a "trigger" action (entity_add), then dispatch a success (entity_add_success) or failure (entity_add_failure) action somewhere in my epic/effect, wait for failure or success action and do an action - this approach has a noticable drawback: other entities may be created meanwhile and how to distinguish the failure/success actions of entities in that case?

  2. dispatch a trigger action with additional callback parameter which should be called when action result becomes determined, this approach has a drawback as well (not as big as the previous one though): possibility of creating callback hell.

  3. give up at using flux in that case, use services directly, design drawback: mixing application layers

I'd be glad to hear any ideas.

Aucun commentaire:

Enregistrer un commentaire