martyjs / marty

A Javascript library for state management in React applications
http://martyjs.org
MIT License
1.09k stars 76 forks source link

Simplify error handling #163

Closed jhollingworth closed 9 years ago

jhollingworth commented 9 years ago

How action creators work, in particular error handling is a recurring issue (#157, #152, #127) we need to solve. Having the action creators automatically dispatch ACTION_{type} errors seemed like a neat idea at the time but it's not very useful and has lead to a load of complicated code and crappy APIs.

I think we should just go back to a simpler, explicit approach (Yahoo has some good examples):

var FooActionCreators = Marty.createActionCreators({
  createFoo(foo) {
    this.dispatch(Constants.RECIEVE_FOO, foo);

    FooAPI.createFoo(foo).catch((error) => {
      this.dispatch(Constants.RECIEVE_FOO_FAILED, foo, error);
    });
  }  
});

As much as I'd like to have some automatic error handling/retrying I think we should get the simple case right first.

jhollingworth commented 9 years ago

@oliverwoodings @dariocravero @giuse88 what do you think?

dariocravero commented 9 years ago

:+1: for a simplified approach. Clean stack traces are vital and even though we have some tracing right now the confusion it creates as to what actually originated the exception is enough to rethink what Marty is doing here. Eventually the automated functionality could be provided through some syntactic sugar at some stage?

jhollingworth commented 9 years ago

166 should resolve this