martyjs / marty

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

Allow you to specify what the whens function context should inherit from... #184

Closed jhollingworth closed 9 years ago

jhollingworth commented 9 years ago

When using when its really common to want to call component functions and/or other handlers. This PR allows that by creating a function context which has all the handlers on it but inherits from another context (if passed in) thus allowing both scenarios. Resolves #76

var Foo = React.createClass({
  render() {
    return this.foo.when({
      pending() {
        return this.done({})
      },
      failed(error) {
        return <Error error={error} />;
      },
      done(foo) {
        return <div className="Foo">{this.renderBody(foo)}</div>;
      }
    }, this);
  },
  renderBody(foo) {
    return <div className="Foo-body">{foo.bar}</div>;
  }
})