rx.observable.combinetemplate
v0.2.6
Published
Generate values based on the Observable and object template. Similar to `Bacon.combineTemplate`
Downloads
22
Readme
Rx.Observable.combineTemplate
Generate values based on the Observable and object template. Similar to Bacon.combineTemplate
.
Usage
Install
npm install --save rx.observable.combinetemplate
Basics
import combineTemplate from 'rx.observable.combinetemplate';
import * as Rx from 'rx';
let subject1 = new Rx.Subject();
let subject2 = new Rx.Subject();
combineTemplate({
foo : 'bar',
baz : {
foo : ['bar', subject1 'qux']
},
qux : {
foo : {
foo : 'bar'
baz : subject2
}
}
}).subscribe((value)=> {
console.log(value);
/* === output ===
{
foo : 'bar',
baz : {
foo : ['bar', 'BAZ' 'qux']
},
qux : {
foo : {
foo : 'bar'
baz : 'QUX'
}
}
}
*/
});
subject1.onNext('BAZ');
subject2.onNext('QUX');
with React
State is updated automatically receives a value from the observables.
componentWillMount() {
combineTemplate({
items : store.itemsObservable$,
count : store.itemsObservable$.map((items) => items.length)
}).subscribe(this.setState.bind(this));
}
Tests
npm test
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
MIT