1

I've had something bothering me for the past couple of days and I can't seem to come up with a solution that I like. I'm using refluxjs, but I think its applicable to vanilla flux as well.

So, say I have a React ComponentOne that calls a flux action to post some form data to an API to create a Thing.

My store fires a "ok, a Thing is POSTing" event, and then in a bit fires a "ok, a Thing was created" event.

How is my ComponentOne supposed to disambiguate these events? ComponentTwo could have called the same action and we don't know which Thing-POSTed event corresponds to which component.

Maybe ComponentOne's data results in a failure event, whilst ComponentTwo results in a completed event...we've got two events, both of which are plausible events for both components to expect and no obvious way to tell which is which.

Dustin Wyatt
  • 4,046
  • 5
  • 31
  • 60
  • 1
    One solution could be to send the component in the action payload: `SomeActionCreator.postThing({thing: thing: caller: this});` – Paolo Moretti Feb 23 '15 at 17:58

1 Answers1

0

You can maintain the state of API data changes inside respective Store like isLoading, isLoaded and optional time stamp. Then inside View onChange event get the current state from Store and update respective View with current state.

see related solution - Calling other action on the basis of results of other action in React JS

Community
  • 1
  • 1
Oppo
  • 11
  • 2