phillipskevin / observable-decorators

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

Use config to support any Observable #3

Closed phillipskevin closed 7 years ago

phillipskevin commented 7 years ago

For example Recompose: rxjs kefir

https://github.com/redux-observable/redux-observable uses a similar setup.

phillipskevin commented 7 years ago

This could look something like:

import { observableFromConfig } from 'observable-decorators';
import kefirConfig from 'observable-decorators/config/kefir';
import Kefir from 'kefir';

const observable = observableFromConfig(kefirConfig);

class Foo {
  @observable
  bar = 'baz';

  @observable
  abc = 'xyz';

  @observable
  derived() {
    return Kefir.merge([ bar ,abc ]);
  }
}

This would use the toObservable and fromObservable functions from the config in the internal getter/setters so that internally it would use RxJS, but when properties are read from the class instances, they would be whatever stream the user wants (in this case Kefir).