Basically, how would you migrate the following code to Flux:
click() { doAction().catch(err => showModal(err)) }Actions describe things that happened in the world and the role of your store is to figure out if that thing that happened is valid or not, and pass the necessary data to components listening for changes.
handleComment(comment) {
if (comment === '') this.dispatch('comment-error', 'empty')
else svc.send(comment)
.then(() => this.dispatch('comment-success')
.catch(err => this.dispatch('comment-error', err))
}
The view/controller (or whatever it's called in React) will then listen to the events and set its state accordingly so that the UI can be re-rendered.It does look quite complicated compared with typical error handling code. Not sure if I misunderstood something or whether this additional layer of message dispatching is worthwhile in most apps.
Thinking it only refers to one field and is wrong - when the usage is totally correct (and very applicable) just makes you sound snobbish... and foolish.
Thanks!
Also, can't hurt that the library was designed and implemented in ES6, which is what I've begun moving our architecture towards!
You can still use singletons on the server, but you have to pass the current user id to every method/event on that singleton. And that ends up being quite annoying.
Edit: grammar.
We felt the same way, until we moved away from Facebook's Flux implementation and adopted Flummox[0]. It's singleton-free, so we gained isomorphism for our application with only a tiny bit of extra work, and it hides away the dispatcher (unless you need it, which we haven't despite having over a dozen stores, tonnes of actions and a large number of components).
With Flummox making it so easy, we put all state into a store. This allows us to save application UI state to localStorage, bootstrapping the app into the same position the user was previous, with again no extra effort on our behalf. It's well worth checking out!
[0] http://acdlite.github.io/flummox/