Skip to content

Commit a471353

Browse files
authored
Merge pull request #221 from tusharmath/extra-updates
refactor(extra): add generic from() static util
2 parents 872838a + 54f32fd commit a471353

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

extra.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,105 +23,143 @@ export class Air<T> implements IObservable<T> {
2323
): ISubscription {
2424
return this.src.subscribe(observer, scheduler)
2525
}
26+
2627
concatMap<S>(fn: (t: T) => IObservable<S>) {
2728
return new Air(O.concatMap(fn, this))
2829
}
30+
2931
concat(src: IObservable<T>) {
3032
return new Air(O.concat(this, src))
3133
}
34+
3235
delay(t: number) {
3336
return new Air(O.delay(t, this))
3437
}
38+
3539
filter(fn: (t: T) => boolean) {
3640
return new Air(O.filter(fn, this))
3741
}
42+
3843
flatMap<S>(fn: (t: T) => IObservable<S>) {
3944
return new Air(O.flatMap(fn, this))
4045
}
46+
4147
forEach(fn: (t: T) => void) {
4248
return O.forEach(fn, this)
4349
}
50+
4451
join() {
4552
return new Air(O.join(this as any))
4653
}
54+
4755
mapTo<S>(t: S) {
4856
return new Air(O.mapTo(t, this))
4957
}
58+
5059
map<S>(fn: (t: T) => S) {
5160
return new Air(O.map(fn, this))
5261
}
62+
5363
mergeMap<S>(n: IObservable<number>, project: (t: T) => IObservable<S>) {
5464
return new Air(O.mergeMap(n, project, this))
5565
}
66+
5667
multicast() {
5768
return new Air(O.multicast(this))
5869
}
70+
5971
reduce<R>(fn: (memory: R, current: T) => R, seed: R) {
6072
return new Air(O.reduce(fn, seed, this))
6173
}
74+
6275
sample(fn: (...e: Array<any>) => T, sources: Array<IObservable<any>>) {
6376
return new Air(O.sample(fn, this, sources))
6477
}
78+
6579
skipRepeats(fn: (a: T, b: T) => boolean) {
6680
return new Air(O.skipRepeats(fn, this))
6781
}
82+
6883
slice(start: number, count: number) {
6984
return new Air(O.slice(start, count, this))
7085
}
86+
7187
switchLatest() {
7288
return new Air(O.switchLatest(this as any))
7389
}
90+
7491
switchMap<S>(fn: (t: T) => IObservable<S>) {
7592
return new Air(O.switchMap(fn, this))
7693
}
94+
7795
tap(fn: (t: T) => void) {
7896
return new Air(O.tap(fn, this))
7997
}
98+
8099
uniqueWith(set: Set<any>) {
81100
return new Air(O.uniqueWith(set, this))
82101
}
102+
83103
unique() {
84104
return new Air(O.unique(this))
85105
}
106+
86107
debounce(t: number) {
87108
return new Air(debounce(t, this))
88109
}
110+
89111
toNodeStream(): Stream {
90112
return toNodeStream(this)
91113
}
114+
92115
toPromise() {
93116
return O.toPromise(this)
94117
}
118+
119+
scan<R>(reducer: (memory: R, current: T) => R, seed: R) {
120+
return new Air(O.scan(reducer, seed, this))
121+
}
122+
95123
static combine<T>(selector: (...t: any[]) => T, sources: IObservable<any>[]) {
96124
return new Air(combine(selector, sources))
97125
}
126+
98127
static fromNodeStream(node: Readable) {
99128
return new Air(fromNodeStream(node))
100129
}
130+
101131
static empty() {
102132
return new Air(O.empty())
103133
}
134+
104135
static frames() {
105136
return new Air(O.frames())
106137
}
138+
107139
static fromArray<T>(arr: Array<T>) {
108140
return new Air(O.fromArray(arr))
109141
}
142+
110143
static fromDOM(el: HTMLElement, event: string) {
111144
return new Air(O.fromDOM(el, event))
112145
}
146+
113147
static fromPromise<T>(fn: () => Promise<T>) {
114148
return new Air(O.fromPromise(fn))
115149
}
150+
116151
static interval(t: number) {
117152
return new Air(O.interval(t))
118153
}
154+
119155
static just<T>(t: T) {
120156
return new Air(O.just(t))
121157
}
158+
122159
static never() {
123160
return new Air(O.never())
124161
}
162+
125163
static of<T>(...t: T[]) {
126164
return new Air(O.of(...t))
127165
}

0 commit comments

Comments
 (0)