Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actions not causing immediate remote changes #9

Open
HannesP opened this issue Jun 12, 2017 · 0 comments
Open

Actions not causing immediate remote changes #9

HannesP opened this issue Jun 12, 2017 · 0 comments

Comments

@HannesP
Copy link

HannesP commented Jun 12, 2017

The unidirectional dataflow makes perfect sense if user interaction always (or never, as in most tutorial examples) gives rise to remote changes. A typical case:

  • The user enters a value into a field, which triggers an action (e.g. CommentActions.setTitle(title))
  • The action makes a remote call, and upon success triggers the CommentActions.setTitle.completed(title) child action
  • The store listens through e.g. CommentStore#onSetTitleCompleted(title), and changes its state
  • A component is re-rendered reflecting the new state (e.g. state.title).

Another way to put this might be that every modification to the local store is mirrored by a change in the remote store. However, for various reasons, this is not always desirable. In a lot of situations, it makes sense to only call the server once editing is complete, e.g. upon pressing a "Save" or "Post" button.

I can see this happening in a multitude of situations. For example, without knowing the implementation details, it seems likely that when creating events on Facebook, all data (date, title, description, guest list etc.) is stored locally until the user hits the "Create Event" button.

It seems logical to introduce an action like CommentActions.postComment(), but that creates a difficulty: there is no obvious way for the action to access all the data that has been supplied and edited to that point, unlike the first case where each action is fed the data subject to change (e.g. the title).

The best way I've come up with so far is to make the component responsible for feeding the right data to the action. The local values are held in the store, and are thus accessible to the component through mixing in of state. When it's time for the final save, it's triggered by e.g. CommentActions.postComment(this.state.title, this.state.body, this.state.email, ...).

I suppose there are many solutions involving breaking the Flux flow (e.g. having the store calling actions) but I'm only interested in solutions that don't break the very basic principles behind the library :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant