-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrx-helpers.js
33 lines (27 loc) · 846 Bytes
/
rx-helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import Rx from 'rx';
import h from 'virtual-dom/h';
export const combine$ = Rx.Observable.combineLatest;
export function sink$(subject) {
return (event) => subject.onNext(event);
}
export function container$(tagName, children) {
return sequenceCombine$(children).
map(views => h(tagName, [...views]));
}
function asObservable(valueOrObservable) {
if (valueOrObservable instanceof Rx.Observable) {
return valueOrObservable;
} else {
return Rx.Observable.return(valueOrObservable);
}
}
function sequenceCombine$(items$) {
// Work around odd behaviour of combineLatest with empty Array
// (never yields a value)
if (items$.length === 0) {
return Rx.Observable.return([]);
} else {
const observables$ = items$.map(asObservable);
return Rx.Observable.combineLatest(observables$, (...all) => all);
}
}