phillipskevin / observable-decorators

Make class properties observable using decorators
MIT License
2 stars 1 forks source link

Handle errors thrown by derived observables #5

Open phillipskevin opened 7 years ago

phillipskevin commented 7 years ago

My current thoughts are, if a derived observable throws an error, a separate stream should emit a value.

So if you had

class Foo {
  @observable
  bar() {
    // something happens that causes an error
  }
}

var myFoo = new Foo();

foo.bar // "baz" -> good value
foo.bar // causes an error for some reason
foo.errors.bar // this would emit the error
foo.bar // this is still "baz"

This could also be configured somehow for the whole class and also for each property

@error("propertyErrors")
class Foo {
  @observable
  bar() {
    // something happens that causes an error
  }

  @observable({
    error: "bazError"
  })
  baz() {
    // something happens that causes an error
  }
}

var myFoo = new Foo();
myFoo.propertyErrors.bar // this is the errors for bar
myFoo.bazError // this is the errors for baz