@trxcllnt
UI PLATFORM TEAM @
time
t = 0
t = -10
t = 10
(x, y)
[{x, y}]
[{x', y'}]
???
listeners[]
emit(event, data)
addListener(e, observer)
removeListener(e, observer)
function emit(event, data) {
listeners[event].forEach(listener =>
listener(data)
}
4. unsubscribe early
makes all this possible:
map
filter
reduce
concat
flatten
reverse
groupBy
join
sort
find
skip
pluck
partition
zip
0s
1s
2s
2.5s
4s
https://tc39.github.io/proposal-observable/
var randomNumbers = new Observable((observer) => {
var i = setTimeout(() => {
observer.next(Math.random());
observer.complete();
}, 100);
return () => clearTimeout(i);
});
var subscription = randomNumbers.subscribe({
next(x) { console.log(x); },
error(e) { console.error(e); },
complete() { console.log('done') }
});
subscription.unsubscribe();
randomNumbers.subscribe((x) => console.log(x));
// > 1: 0.1231982301923192831231
randomNumbers.subscribe((x) => console.log(x));
// > 2: 0.8178491823912837129834
var randomNumbers = new Observable((observer) => {
var i = setTimeout(() => {
observer.next(Math.random());
observer.complete();
}, 100);
return () => clearTimeout(i);
});
Observable is a function that, when invoked, returns 0-∞ values between now and the end of time.
.map(ball => makeSquare(ball))
map, filter, scan, reduce, flatMap, zip, combineLatest, take, skip, timeInterval, delay, debounce, sample, throttle, ...
async
^
Observable
.fromEvent(document, 'mousedown')
Observable
.interval(0, Scheduler.animationFrame)
Observable
.bindNodeCallback(fs.readdir)
Observable
.from(Promise.resolve('I guess?'))
Observable
.ajax('localhost:9000/getData.json')
Observable
.webSocket('ws://localhost:9001')
.scan((x, y) => x + y, 0)
3
2
24
7
18
3
5
29
36
54
.flatMap(x => )
3
24
18
x*2
x*2
x*2
6
6
6
48
48
48
36
36
36
.takeUntil( )
3
2
24
7
18
3
2
.windowTime(100)
3
2
24
7
18
3
5
29
36
54