-
Notifications
You must be signed in to change notification settings - Fork 6
/
flatmaplatest.ts
48 lines (45 loc) · 1.22 KB
/
flatmaplatest.ts
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {
Scope,
EventStream,
EventStreamSeed,
isPropertySeed,
Observable,
Property,
PropertySeed,
} from "./abstractions"
import { applyScopeMaybe } from "./applyscope"
import { FlatMapStreamSeed, FlatMapPropertySeed, Spawner } from "./flatmap"
import { BinaryTransformOp, BinaryTransformOpScoped } from "./transform"
// TODO: typing is not perfect: spawners for properties should spawn property(seed)s, not streams
export function flatMapLatest<A, B>(
fn: Spawner<
A,
PropertySeed<B> | Property<B> | EventStream<B> | EventStreamSeed<B>
>
): BinaryTransformOp<A, B>
export function flatMapLatest<A, B>(
fn: Spawner<
A,
PropertySeed<B> | Property<B> | EventStream<B> | EventStreamSeed<B>
>,
scope: Scope
): BinaryTransformOpScoped<A, B>
export function flatMapLatest<A>(fn: Spawner<A, any>, scope?: Scope): any {
return (s: any) => {
if (isPropertySeed<A>(s)) {
return applyScopeMaybe(
new FlatMapPropertySeed([s, "flatMapLatest", [fn]], s, fn, {
latest: true,
}),
scope
)
} else {
return applyScopeMaybe(
new FlatMapStreamSeed([s, "flatMapLatest", [fn]], s, fn, {
latest: true,
}),
scope
)
}
}
}