sygnal 5.3.6 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -38
- package/dist/astro/client.cjs.js +18 -8106
- package/dist/astro/client.cjs.js.map +1 -0
- package/dist/astro/client.mjs +17 -8105
- package/dist/astro/client.mjs.map +1 -0
- package/dist/astro/index.cjs.js +768 -9
- package/dist/astro/index.cjs.js.map +1 -0
- package/dist/astro/index.mjs +768 -9
- package/dist/astro/index.mjs.map +1 -0
- package/dist/astro/server.cjs.js +4 -1
- package/dist/astro/server.cjs.js.map +1 -0
- package/dist/astro/server.mjs +4 -1
- package/dist/astro/server.mjs.map +1 -0
- package/dist/diagnostics.cjs.js +1297 -0
- package/dist/diagnostics.cjs.js.map +1 -0
- package/dist/diagnostics.esm.js +1267 -0
- package/dist/diagnostics.esm.js.map +1 -0
- package/dist/index.cjs.js +2981 -1386
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +848 -111
- package/dist/index.esm.js +2997 -1411
- package/dist/index.esm.js.map +1 -0
- package/dist/jsx-dev-runtime.cjs.js +15 -9
- package/dist/jsx-dev-runtime.cjs.js.map +1 -0
- package/dist/jsx-dev-runtime.esm.js +15 -9
- package/dist/jsx-dev-runtime.esm.js.map +1 -0
- package/dist/jsx-runtime.cjs.js +15 -9
- package/dist/jsx-runtime.cjs.js.map +1 -0
- package/dist/jsx-runtime.esm.js +15 -9
- package/dist/jsx-runtime.esm.js.map +1 -0
- package/dist/jsx.cjs.js +15 -9
- package/dist/jsx.cjs.js.map +1 -0
- package/dist/jsx.esm.js +15 -9
- package/dist/jsx.esm.js.map +1 -0
- package/dist/sygnal.min.js +2 -1
- package/dist/sygnal.min.js.map +1 -0
- package/dist/vike/+config.cjs.js +1 -0
- package/dist/vike/+config.cjs.js.map +1 -0
- package/dist/vike/+config.js +1 -0
- package/dist/vike/+config.js.map +1 -0
- package/dist/vike/ClientOnly.cjs.js +1 -0
- package/dist/vike/ClientOnly.cjs.js.map +1 -0
- package/dist/vike/ClientOnly.mjs +1 -0
- package/dist/vike/ClientOnly.mjs.map +1 -0
- package/dist/vike/onRenderClient.cjs.js +1 -0
- package/dist/vike/onRenderClient.cjs.js.map +1 -0
- package/dist/vike/onRenderClient.mjs +1 -0
- package/dist/vike/onRenderClient.mjs.map +1 -0
- package/dist/vike/onRenderHtml.cjs.js +1 -0
- package/dist/vike/onRenderHtml.cjs.js.map +1 -0
- package/dist/vike/onRenderHtml.mjs +1 -0
- package/dist/vike/onRenderHtml.mjs.map +1 -0
- package/dist/vite/plugin.cjs.js +680 -47
- package/dist/vite/plugin.cjs.js.map +1 -0
- package/dist/vite/plugin.mjs +680 -47
- package/dist/vite/plugin.mjs.map +1 -0
- package/llms.txt +250 -0
- package/package.json +15 -6
- package/src/astro/client.ts +13 -2
- package/src/astro/index.d.ts +24 -1
- package/src/astro/index.ts +40 -9
- package/src/astro/server.ts +3 -1
- package/src/collection.ts +5 -2
- package/src/component.ts +375 -330
- package/src/cycle/dom/MainDOMSource.ts +4 -0
- package/src/cycle/dom/classNameModule.ts +74 -0
- package/src/cycle/dom/controlledInputModule.ts +33 -0
- package/src/cycle/dom/enrichEventStream.ts +9 -3
- package/src/cycle/dom/makeDOMDriver.ts +1 -2
- package/src/cycle/dom/mockDOMSource.ts +62 -8
- package/src/cycle/dom/modules.ts +5 -1
- package/src/cycle/state/Collection.ts +13 -3
- package/src/cycle/state/StateSource.ts +1 -1
- package/src/cycle/state/pickCombine.ts +35 -1
- package/src/cycle/state/withState.ts +1 -1
- package/src/extra/devtools.ts +8 -0
- package/src/extra/diagnostics/checks/collections.ts +67 -0
- package/src/extra/diagnostics/checks/dom.ts +241 -0
- package/src/extra/diagnostics/checks/events.ts +68 -0
- package/src/extra/diagnostics/checks/index.ts +109 -0
- package/src/extra/diagnostics/checks/inspect.ts +319 -0
- package/src/extra/diagnostics/checks/props.ts +51 -0
- package/src/extra/diagnostics/checks/public.d.ts +211 -0
- package/src/extra/diagnostics/checks/rxjsHints.ts +88 -0
- package/src/extra/diagnostics/checks/shared.ts +119 -0
- package/src/extra/diagnostics/checks/state.ts +55 -0
- package/src/extra/diagnostics/checks/strict.ts +112 -0
- package/src/extra/diagnostics/checks/wiring.ts +65 -0
- package/src/extra/diagnostics/codes.ts +232 -0
- package/src/extra/diagnostics/index.ts +328 -0
- package/src/extra/diagnostics/legacy.ts +59 -0
- package/src/extra/driverFactories.ts +106 -58
- package/src/extra/eventDriver.ts +4 -0
- package/src/extra/flatten.ts +75 -0
- package/src/extra/reducers.ts +12 -5
- package/src/extra/run.ts +11 -0
- package/src/extra/testing.ts +890 -180
- package/src/extra/xstreamExtras.ts +269 -0
- package/src/index.d.ts +428 -17
- package/src/index.ts +7 -6
- package/src/pragma/index.ts +14 -9
- package/src/switchable.ts +10 -8
- package/src/vike/types.ts +21 -4
- package/src/vite/plugin.d.ts +95 -2
- package/src/vite/plugin.ts +730 -55
- package/dist/astro/astro/client.d.ts +0 -5
- package/dist/astro/astro/index.d.ts +0 -16
- package/dist/astro/astro/server.d.ts +0 -12
- package/dist/astro/client.d.ts +0 -5
- package/dist/astro/client.esm.js +0 -4665
- package/dist/astro/collection.d.ts +0 -12
- package/dist/astro/component.d.ts +0 -22
- package/dist/astro/cycle/dom/BodyDOMSource.d.ts +0 -10
- package/dist/astro/cycle/dom/DOMSource.d.ts +0 -11
- package/dist/astro/cycle/dom/DocumentDOMSource.d.ts +0 -12
- package/dist/astro/cycle/dom/ElementFinder.d.ts +0 -8
- package/dist/astro/cycle/dom/EventDelegator.d.ts +0 -34
- package/dist/astro/cycle/dom/IsolateModule.d.ts +0 -23
- package/dist/astro/cycle/dom/MainDOMSource.d.ts +0 -32
- package/dist/astro/cycle/dom/PriorityQueue.d.ts +0 -7
- package/dist/astro/cycle/dom/ScopeChecker.d.ts +0 -9
- package/dist/astro/cycle/dom/SymbolTree.d.ts +0 -9
- package/dist/astro/cycle/dom/VNodeWrapper.d.ts +0 -8
- package/dist/astro/cycle/dom/enrichEventStream.d.ts +0 -24
- package/dist/astro/cycle/dom/fromEvent.d.ts +0 -6
- package/dist/astro/cycle/dom/index.d.ts +0 -8
- package/dist/astro/cycle/dom/isolate.d.ts +0 -9
- package/dist/astro/cycle/dom/makeDOMDriver.d.ts +0 -11
- package/dist/astro/cycle/dom/mockDOMSource.d.ts +0 -17
- package/dist/astro/cycle/dom/modules.d.ts +0 -5
- package/dist/astro/cycle/dom/snabbdom.d.ts +0 -22
- package/dist/astro/cycle/dom/styleModule.d.ts +0 -13
- package/dist/astro/cycle/dom/thunk.d.ts +0 -11
- package/dist/astro/cycle/dom/utils.d.ts +0 -8
- package/dist/astro/cycle/isolate/index.d.ts +0 -42
- package/dist/astro/cycle/run/adapt.d.ts +0 -6
- package/dist/astro/cycle/run/index.d.ts +0 -36
- package/dist/astro/cycle/run/internals.d.ts +0 -8
- package/dist/astro/cycle/run/types.d.ts +0 -49
- package/dist/astro/cycle/state/Collection.d.ts +0 -29
- package/dist/astro/cycle/state/StateSource.d.ts +0 -20
- package/dist/astro/cycle/state/index.d.ts +0 -5
- package/dist/astro/cycle/state/pickCombine.d.ts +0 -3
- package/dist/astro/cycle/state/pickMerge.d.ts +0 -3
- package/dist/astro/cycle/state/types.d.ts +0 -18
- package/dist/astro/cycle/state/withState.d.ts +0 -17
- package/dist/astro/extra/classes.d.ts +0 -7
- package/dist/astro/extra/devtools.d.ts +0 -78
- package/dist/astro/extra/dragDriver.d.ts +0 -20
- package/dist/astro/extra/driverFactories.d.ts +0 -12
- package/dist/astro/extra/eventDriver.d.ts +0 -9
- package/dist/astro/extra/exactState.d.ts +0 -1
- package/dist/astro/extra/hmr.d.ts +0 -17
- package/dist/astro/extra/logDriver.d.ts +0 -2
- package/dist/astro/extra/processDrag.d.ts +0 -19
- package/dist/astro/extra/processForm.d.ts +0 -15
- package/dist/astro/extra/run.d.ts +0 -13
- package/dist/astro/extra/xstreamCompat.d.ts +0 -5
- package/dist/astro/index.d.ts +0 -19
- package/dist/astro/index.esm.js +0 -27
- package/dist/astro/jsx-dev-runtime.d.ts +0 -1
- package/dist/astro/jsx-runtime.d.ts +0 -4
- package/dist/astro/jsx.d.ts +0 -2
- package/dist/astro/pragma/fn.d.ts +0 -7
- package/dist/astro/pragma/index.d.ts +0 -7
- package/dist/astro/pragma/is.d.ts +0 -10
- package/dist/astro/server.d.ts +0 -12
- package/dist/astro/server.esm.js +0 -25
- package/dist/astro/switchable.d.ts +0 -7
- package/dist/collection.d.ts +0 -12
- package/dist/component.d.ts +0 -22
- package/dist/cycle/dom/BodyDOMSource.d.ts +0 -10
- package/dist/cycle/dom/DOMSource.d.ts +0 -11
- package/dist/cycle/dom/DocumentDOMSource.d.ts +0 -12
- package/dist/cycle/dom/ElementFinder.d.ts +0 -8
- package/dist/cycle/dom/EventDelegator.d.ts +0 -34
- package/dist/cycle/dom/IsolateModule.d.ts +0 -23
- package/dist/cycle/dom/MainDOMSource.d.ts +0 -32
- package/dist/cycle/dom/PriorityQueue.d.ts +0 -7
- package/dist/cycle/dom/ScopeChecker.d.ts +0 -9
- package/dist/cycle/dom/SymbolTree.d.ts +0 -9
- package/dist/cycle/dom/VNodeWrapper.d.ts +0 -8
- package/dist/cycle/dom/enrichEventStream.d.ts +0 -24
- package/dist/cycle/dom/fromEvent.d.ts +0 -6
- package/dist/cycle/dom/index.d.ts +0 -8
- package/dist/cycle/dom/isolate.d.ts +0 -9
- package/dist/cycle/dom/makeDOMDriver.d.ts +0 -11
- package/dist/cycle/dom/mockDOMSource.d.ts +0 -17
- package/dist/cycle/dom/modules.d.ts +0 -5
- package/dist/cycle/dom/snabbdom.d.ts +0 -22
- package/dist/cycle/dom/styleModule.d.ts +0 -13
- package/dist/cycle/dom/thunk.d.ts +0 -11
- package/dist/cycle/dom/utils.d.ts +0 -8
- package/dist/cycle/isolate/index.d.ts +0 -42
- package/dist/cycle/run/adapt.d.ts +0 -6
- package/dist/cycle/run/index.d.ts +0 -36
- package/dist/cycle/run/internals.d.ts +0 -8
- package/dist/cycle/run/types.d.ts +0 -49
- package/dist/cycle/state/Collection.d.ts +0 -29
- package/dist/cycle/state/StateSource.d.ts +0 -20
- package/dist/cycle/state/index.d.ts +0 -5
- package/dist/cycle/state/pickCombine.d.ts +0 -3
- package/dist/cycle/state/pickMerge.d.ts +0 -3
- package/dist/cycle/state/types.d.ts +0 -18
- package/dist/cycle/state/withState.d.ts +0 -17
- package/dist/extra/classes.d.ts +0 -7
- package/dist/extra/devtools.d.ts +0 -78
- package/dist/extra/dragDriver.d.ts +0 -20
- package/dist/extra/driverFactories.d.ts +0 -12
- package/dist/extra/eventDriver.d.ts +0 -9
- package/dist/extra/exactState.d.ts +0 -1
- package/dist/extra/hmr.d.ts +0 -17
- package/dist/extra/logDriver.d.ts +0 -2
- package/dist/extra/processDrag.d.ts +0 -19
- package/dist/extra/processForm.d.ts +0 -15
- package/dist/extra/run.d.ts +0 -13
- package/dist/extra/xstreamCompat.d.ts +0 -5
- package/dist/jsx-dev-runtime.d.ts +0 -1
- package/dist/jsx-dev-runtime.js +0 -224
- package/dist/jsx-runtime.d.ts +0 -4
- package/dist/jsx-runtime.js +0 -224
- package/dist/jsx.d.ts +0 -2
- package/dist/pragma/fn.d.ts +0 -7
- package/dist/pragma/index.d.ts +0 -7
- package/dist/pragma/is.d.ts +0 -10
- package/dist/switchable.d.ts +0 -7
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ESM ports of xstream's `concat`, `debounce`, `throttle`, `delay`, `dropRepeats` and
|
|
3
|
+
* `sampleCombine` extras (xstream, MIT, André Staltz), behaviour-identical.
|
|
4
|
+
*
|
|
5
|
+
* Why not import 'xstream/extra/*': those modules are CommonJS with `exports.default`. Under
|
|
6
|
+
* Vite/Vitest the default import resolves to the function, but in the rollup CJS build and in
|
|
7
|
+
* native Node ESM it resolves to the module object `{ default: fn }`, so the re-exports from
|
|
8
|
+
* 'sygnal' were not callable there (and neither were sygnal's own internal uses). ESM classes
|
|
9
|
+
* are also tree-shaken when an app does not use them. See also ./flatten.ts.
|
|
10
|
+
*/
|
|
11
|
+
import {Stream} from 'xstream'
|
|
12
|
+
|
|
13
|
+
// ---------------------------------------------------------------- concat
|
|
14
|
+
|
|
15
|
+
class ConcatProducer {
|
|
16
|
+
type = 'concat'
|
|
17
|
+
out: any = null
|
|
18
|
+
i = 0
|
|
19
|
+
constructor(public streams: any[]) {}
|
|
20
|
+
_start(out: any) { this.out = out; this.streams[this.i]._add(this) }
|
|
21
|
+
_stop() {
|
|
22
|
+
const streams = this.streams
|
|
23
|
+
if (this.i < streams.length) streams[this.i]._remove(this)
|
|
24
|
+
this.i = 0
|
|
25
|
+
this.out = null
|
|
26
|
+
}
|
|
27
|
+
_n(t: any) { const u = this.out; if (u) u._n(t) }
|
|
28
|
+
_e(err: any) { const u = this.out; if (u) u._e(err) }
|
|
29
|
+
_c() {
|
|
30
|
+
const u = this.out
|
|
31
|
+
if (!u) return
|
|
32
|
+
const streams = this.streams
|
|
33
|
+
streams[this.i]._remove(this)
|
|
34
|
+
if (++this.i < streams.length) streams[this.i]._add(this)
|
|
35
|
+
else u._c()
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Emits everything from the first stream, then (once it completes) the second, and so on. */
|
|
40
|
+
export function concat<T>(...streams: Stream<T>[]): Stream<T> {
|
|
41
|
+
return new Stream<T>(new ConcatProducer(streams) as any)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ---------------------------------------------------------------- debounce
|
|
45
|
+
|
|
46
|
+
const NO_VALUE = {}
|
|
47
|
+
|
|
48
|
+
class DebounceOperator {
|
|
49
|
+
type = 'debounce'
|
|
50
|
+
out: any = null
|
|
51
|
+
id: any = null
|
|
52
|
+
t: any = NO_VALUE
|
|
53
|
+
constructor(public dt: number, public ins: any) {}
|
|
54
|
+
_start(out: any) { this.out = out; this.ins._add(this) }
|
|
55
|
+
_stop() { this.ins._remove(this); this.out = null; this.clearInterval() }
|
|
56
|
+
clearInterval() {
|
|
57
|
+
const id = this.id
|
|
58
|
+
if (id !== null) clearInterval(id)
|
|
59
|
+
this.id = null
|
|
60
|
+
}
|
|
61
|
+
_n(t: any) {
|
|
62
|
+
const u = this.out
|
|
63
|
+
if (!u) return
|
|
64
|
+
this.clearInterval()
|
|
65
|
+
this.t = t
|
|
66
|
+
this.id = setInterval(() => {
|
|
67
|
+
this.clearInterval()
|
|
68
|
+
u._n(t)
|
|
69
|
+
this.t = NO_VALUE
|
|
70
|
+
}, this.dt)
|
|
71
|
+
}
|
|
72
|
+
_e(err: any) {
|
|
73
|
+
const u = this.out
|
|
74
|
+
if (!u) return
|
|
75
|
+
this.clearInterval()
|
|
76
|
+
u._e(err)
|
|
77
|
+
}
|
|
78
|
+
_c() {
|
|
79
|
+
const u = this.out
|
|
80
|
+
if (!u) return
|
|
81
|
+
this.clearInterval()
|
|
82
|
+
if (this.t != NO_VALUE) u._n(this.t)
|
|
83
|
+
this.t = NO_VALUE
|
|
84
|
+
u._c()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Emits a value only after `period` ms have passed without another value. */
|
|
89
|
+
export function debounce(period: number): <T>(ins: Stream<T>) => Stream<T> {
|
|
90
|
+
return function debounceOperator<T>(ins: Stream<T>): Stream<T> {
|
|
91
|
+
return new Stream<T>(new DebounceOperator(period, ins) as any)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// ---------------------------------------------------------------- throttle
|
|
96
|
+
|
|
97
|
+
class ThrottleOperator {
|
|
98
|
+
type = 'throttle'
|
|
99
|
+
out: any = null
|
|
100
|
+
id: any = null
|
|
101
|
+
constructor(public dt: number, public ins: any) {}
|
|
102
|
+
_start(out: any) { this.out = out; this.ins._add(this) }
|
|
103
|
+
_stop() { this.ins._remove(this); this.out = null; this.id = null }
|
|
104
|
+
clearInterval() {
|
|
105
|
+
const id = this.id
|
|
106
|
+
if (id !== null) clearInterval(id)
|
|
107
|
+
this.id = null
|
|
108
|
+
}
|
|
109
|
+
_n(t: any) {
|
|
110
|
+
const u = this.out
|
|
111
|
+
if (!u) return
|
|
112
|
+
if (this.id) return
|
|
113
|
+
u._n(t)
|
|
114
|
+
this.id = setInterval(() => { this.clearInterval() }, this.dt)
|
|
115
|
+
}
|
|
116
|
+
_e(err: any) {
|
|
117
|
+
const u = this.out
|
|
118
|
+
if (!u) return
|
|
119
|
+
this.clearInterval()
|
|
120
|
+
u._e(err)
|
|
121
|
+
}
|
|
122
|
+
_c() {
|
|
123
|
+
const u = this.out
|
|
124
|
+
if (!u) return
|
|
125
|
+
this.clearInterval()
|
|
126
|
+
u._c()
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Emits a value, then ignores further values for `period` ms. */
|
|
131
|
+
export function throttle(period: number): <T>(ins: Stream<T>) => Stream<T> {
|
|
132
|
+
return function throttleOperator<T>(ins: Stream<T>): Stream<T> {
|
|
133
|
+
return new Stream<T>(new ThrottleOperator(period, ins) as any)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ---------------------------------------------------------------- delay
|
|
138
|
+
|
|
139
|
+
class DelayOperator {
|
|
140
|
+
type = 'delay'
|
|
141
|
+
out: any = null
|
|
142
|
+
constructor(public dt: number, public ins: any) {}
|
|
143
|
+
_start(out: any) { this.out = out; this.ins._add(this) }
|
|
144
|
+
_stop() { this.ins._remove(this); this.out = null }
|
|
145
|
+
_n(t: any) {
|
|
146
|
+
const u = this.out
|
|
147
|
+
if (!u) return
|
|
148
|
+
const id = setInterval(() => { u._n(t); clearInterval(id) }, this.dt)
|
|
149
|
+
}
|
|
150
|
+
_e(err: any) {
|
|
151
|
+
const u = this.out
|
|
152
|
+
if (!u) return
|
|
153
|
+
const id = setInterval(() => { u._e(err); clearInterval(id) }, this.dt)
|
|
154
|
+
}
|
|
155
|
+
_c() {
|
|
156
|
+
const u = this.out
|
|
157
|
+
if (!u) return
|
|
158
|
+
const id = setInterval(() => { u._c(); clearInterval(id) }, this.dt)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Delays every event (values, error, completion) by `period` ms. */
|
|
163
|
+
export function delay(period: number): <T>(ins: Stream<T>) => Stream<T> {
|
|
164
|
+
return function delayOperator<T>(ins: Stream<T>): Stream<T> {
|
|
165
|
+
return new Stream<T>(new DelayOperator(period, ins) as any)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ---------------------------------------------------------------- dropRepeats
|
|
170
|
+
|
|
171
|
+
const EMPTY = {}
|
|
172
|
+
|
|
173
|
+
class DropRepeatsOperator {
|
|
174
|
+
type = 'dropRepeats'
|
|
175
|
+
out: any = null
|
|
176
|
+
v: any = EMPTY
|
|
177
|
+
isEq: (x: any, y: any) => boolean
|
|
178
|
+
constructor(public ins: any, fn?: (x: any, y: any) => boolean) {
|
|
179
|
+
this.isEq = fn ? fn : (x: any, y: any) => x === y
|
|
180
|
+
}
|
|
181
|
+
_start(out: any) { this.out = out; this.ins._add(this) }
|
|
182
|
+
_stop() { this.ins._remove(this); this.out = null; this.v = EMPTY }
|
|
183
|
+
_n(t: any) {
|
|
184
|
+
const u = this.out
|
|
185
|
+
if (!u) return
|
|
186
|
+
const v = this.v
|
|
187
|
+
if (v !== EMPTY && this.isEq(t, v)) return
|
|
188
|
+
this.v = t
|
|
189
|
+
u._n(t)
|
|
190
|
+
}
|
|
191
|
+
_e(err: any) { const u = this.out; if (u) u._e(err) }
|
|
192
|
+
_c() { const u = this.out; if (u) u._c() }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Drops consecutive duplicates (`===`, or the given equality function). */
|
|
196
|
+
export function dropRepeats<T>(isEqual?: (x: T, y: T) => boolean): (ins: Stream<T>) => Stream<T> {
|
|
197
|
+
return function dropRepeatsOperator(ins: Stream<T>): Stream<T> {
|
|
198
|
+
return new Stream<T>(new DropRepeatsOperator(ins, isEqual as any) as any)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ---------------------------------------------------------------- sampleCombine
|
|
203
|
+
|
|
204
|
+
const NO = {}
|
|
205
|
+
|
|
206
|
+
class SampleCombineListener {
|
|
207
|
+
constructor(public i: number, public p: SampleCombineOperator) { p.ils[i] = this }
|
|
208
|
+
_n(t: any) {
|
|
209
|
+
const p = this.p
|
|
210
|
+
if (p.out === NO) return
|
|
211
|
+
p.up(t, this.i)
|
|
212
|
+
}
|
|
213
|
+
_e(err: any) { this.p._e(err) }
|
|
214
|
+
_c() { this.p.down(this.i, this) }
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
class SampleCombineOperator {
|
|
218
|
+
type = 'sampleCombine'
|
|
219
|
+
out: any = NO
|
|
220
|
+
ils: any[] = []
|
|
221
|
+
Nn = 0
|
|
222
|
+
vals: any[] = []
|
|
223
|
+
constructor(public ins: any, public others: any[]) {}
|
|
224
|
+
_start(out: any) {
|
|
225
|
+
this.out = out
|
|
226
|
+
const s = this.others
|
|
227
|
+
const n = this.Nn = s.length
|
|
228
|
+
const vals = this.vals = new Array(n)
|
|
229
|
+
for (let i = 0; i < n; i++) {
|
|
230
|
+
vals[i] = NO
|
|
231
|
+
s[i]._add(new SampleCombineListener(i, this))
|
|
232
|
+
}
|
|
233
|
+
this.ins._add(this)
|
|
234
|
+
}
|
|
235
|
+
_stop() {
|
|
236
|
+
const s = this.others
|
|
237
|
+
const n = s.length
|
|
238
|
+
const ils = this.ils
|
|
239
|
+
this.ins._remove(this)
|
|
240
|
+
for (let i = 0; i < n; i++) s[i]._remove(ils[i])
|
|
241
|
+
this.out = NO
|
|
242
|
+
this.vals = []
|
|
243
|
+
this.ils = []
|
|
244
|
+
}
|
|
245
|
+
_n(t: any) {
|
|
246
|
+
const out = this.out
|
|
247
|
+
if (out === NO) return
|
|
248
|
+
if (this.Nn > 0) return
|
|
249
|
+
out._n([t, ...this.vals])
|
|
250
|
+
}
|
|
251
|
+
_e(err: any) { const out = this.out; if (out !== NO) out._e(err) }
|
|
252
|
+
_c() { const out = this.out; if (out !== NO) out._c() }
|
|
253
|
+
up(t: any, i: number) {
|
|
254
|
+
const v = this.vals[i]
|
|
255
|
+
if (this.Nn > 0 && v === NO) this.Nn--
|
|
256
|
+
this.vals[i] = t
|
|
257
|
+
}
|
|
258
|
+
down(i: number, l: any) { this.others[i]._remove(l) }
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Operator: whenever the source emits, emits `[source, latest(a), latest(b), ...]`
|
|
263
|
+
* (only once every other stream has emitted at least once).
|
|
264
|
+
*/
|
|
265
|
+
export function sampleCombine(...streams: Stream<any>[]): (sampler: Stream<any>) => Stream<any[]> {
|
|
266
|
+
return function sampleCombineOperator(sampler: Stream<any>): Stream<any[]> {
|
|
267
|
+
return new Stream<any[]>(new SampleCombineOperator(sampler, streams) as any)
|
|
268
|
+
}
|
|
269
|
+
}
|