News for hackers. Stuff that matters.
Re:React JS Best Practices by pbowyer on Sunday May 10, 2015 @04:19AM (#9519289)
Thanks for your explanation, that makes sense theoretically but... could you provide a code example for how this breaks out in practice?
Re:React JS Best Practices by yblu on Sunday May 10, 2015 @10:46PM (#9522433)
I guess what s/he meant was having something like this in the store:

  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.