Sam Julien
Energy Trust of Oregon Dev, Treehouse Mentor, Maker
Open Source Hardware + RxJS =
Image from Hackaday
*if you know C :( Arduino being worked on as we speak!
So new, it's 20 years old!
Single return value |
Multiple return values | |
---|---|---|
Pull/Synchronous/ Interactive |
Object | Iterables (Array | Set | Map) |
Push/Asynchronous/Reactive | Promise | Observable |
The subscribe method returns a Disposable object that allows you to clean up the subscription when you're done
var source$ = Rx.Observable.range(1,4); //1,2,3,4
//map (select) & flatMap (selectMany): changes each value
//flatMap returns an observable so it works well with async operations
source$.map(x => x*2); //2, 4, 6, 8
//filter: returns only selected values based on custom logic
source$.filter(x => x % 2 === 0); //2, 4
//reduce: performs a computation on the stream and outputs the final value
source$.reduce((prev, curr) => prev + curr); //10
//scan: performs a computation on the stream but outputs intermittment values
source$.scan((prev, curr) => prev + curr); //1, 3, 6, 10
Stack:
What happens when you improve the...
What if we apply these concepts in...