@thi.ng/rstream 9.4.0 → 9.4.1
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/event.js +8 -5
- package/iterable.js +24 -18
- package/package.json +9 -9
- package/promise.js +21 -18
- package/raf.js +21 -18
package/event.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { __optsWithID } from "./idgen.js";
|
|
2
2
|
import { stream, Stream } from "./stream.js";
|
|
3
3
|
const fromEvent = (src, name, listenerOpts = false, streamOpts) => {
|
|
4
|
-
const result = stream(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const result = stream(
|
|
5
|
+
(stream2) => {
|
|
6
|
+
let listener = (e) => stream2.next(e);
|
|
7
|
+
src.addEventListener(name, listener, listenerOpts);
|
|
8
|
+
return () => src.removeEventListener(name, listener, listenerOpts);
|
|
9
|
+
},
|
|
10
|
+
__optsWithID(`event-${name}`, streamOpts)
|
|
11
|
+
);
|
|
9
12
|
streamOpts?.init !== void 0 && result.next(streamOpts.init);
|
|
10
13
|
return result;
|
|
11
14
|
};
|
package/iterable.js
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
import { __optsWithID } from "./idgen.js";
|
|
2
2
|
import { stream } from "./stream.js";
|
|
3
|
-
const fromIterable = (src, opts = {}) => stream(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
const fromIterable = (src, opts = {}) => stream(
|
|
4
|
+
(stream2) => {
|
|
5
|
+
const iter = src[Symbol.iterator]();
|
|
6
|
+
const id = setInterval(() => {
|
|
7
|
+
let val;
|
|
8
|
+
if ((val = iter.next()).done) {
|
|
9
|
+
clearInterval(id);
|
|
10
|
+
stream2.closeIn !== "never" && stream2.done();
|
|
11
|
+
} else {
|
|
12
|
+
stream2.next(val.value);
|
|
13
|
+
}
|
|
14
|
+
}, opts.delay || 0);
|
|
15
|
+
return () => clearInterval(id);
|
|
16
|
+
},
|
|
17
|
+
__optsWithID("iterable", opts)
|
|
18
|
+
);
|
|
19
|
+
const fromIterableSync = (src, opts) => stream(
|
|
20
|
+
(stream2) => {
|
|
21
|
+
for (const s of src) {
|
|
22
|
+
stream2.next(s);
|
|
12
23
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
for (const s of src) {
|
|
18
|
-
stream2.next(s);
|
|
19
|
-
}
|
|
20
|
-
stream2.closeIn !== "never" && stream2.done();
|
|
21
|
-
}, __optsWithID("iterable-sync", opts));
|
|
24
|
+
stream2.closeIn !== "never" && stream2.done();
|
|
25
|
+
},
|
|
26
|
+
__optsWithID("iterable-sync", opts)
|
|
27
|
+
);
|
|
22
28
|
export {
|
|
23
29
|
fromIterable,
|
|
24
30
|
fromIterableSync
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/rstream",
|
|
3
|
-
"version": "9.4.
|
|
3
|
+
"version": "9.4.1",
|
|
4
4
|
"description": "Reactive streams & subscription primitives for constructing dataflow graphs / pipelines",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -44,14 +44,14 @@
|
|
|
44
44
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@thi.ng/api": "^8.12.
|
|
48
|
-
"@thi.ng/arrays": "^2.14.
|
|
49
|
-
"@thi.ng/associative": "^7.1.
|
|
50
|
-
"@thi.ng/atom": "^5.3.
|
|
51
|
-
"@thi.ng/checks": "^3.8.
|
|
52
|
-
"@thi.ng/errors": "^2.6.
|
|
47
|
+
"@thi.ng/api": "^8.12.17",
|
|
48
|
+
"@thi.ng/arrays": "^2.14.13",
|
|
49
|
+
"@thi.ng/associative": "^7.1.33",
|
|
50
|
+
"@thi.ng/atom": "^5.3.58",
|
|
51
|
+
"@thi.ng/checks": "^3.8.7",
|
|
52
|
+
"@thi.ng/errors": "^2.6.6",
|
|
53
53
|
"@thi.ng/logger": "^3.3.0",
|
|
54
|
-
"@thi.ng/transducers": "^9.6.
|
|
54
|
+
"@thi.ng/transducers": "^9.6.30"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/node": "^24.10.9",
|
|
@@ -223,5 +223,5 @@
|
|
|
223
223
|
],
|
|
224
224
|
"year": 2017
|
|
225
225
|
},
|
|
226
|
-
"gitHead": "
|
|
226
|
+
"gitHead": "1107498d31504dc63d1a457b5def387d7a134f69\n"
|
|
227
227
|
}
|
package/promise.js
CHANGED
|
@@ -9,25 +9,28 @@ const fromPromise = (src, opts) => {
|
|
|
9
9
|
err = e;
|
|
10
10
|
isError = true;
|
|
11
11
|
});
|
|
12
|
-
return stream(
|
|
13
|
-
|
|
14
|
-
(
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
return stream(
|
|
13
|
+
(stream2) => {
|
|
14
|
+
src.then(
|
|
15
|
+
(x) => {
|
|
16
|
+
if (!canceled && stream2.getState() < State.DONE) {
|
|
17
|
+
if (isError) {
|
|
18
|
+
stream2.error(err);
|
|
19
|
+
err = null;
|
|
20
|
+
} else {
|
|
21
|
+
stream2.next(x);
|
|
22
|
+
stream2.closeIn !== "never" && stream2.done();
|
|
23
|
+
}
|
|
22
24
|
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
25
|
+
},
|
|
26
|
+
(e) => stream2.error(e)
|
|
27
|
+
);
|
|
28
|
+
return () => {
|
|
29
|
+
canceled = true;
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
__optsWithID("promise", opts)
|
|
33
|
+
);
|
|
31
34
|
};
|
|
32
35
|
export {
|
|
33
36
|
fromPromise
|
package/raf.js
CHANGED
|
@@ -3,24 +3,27 @@ import { isNumber } from "@thi.ng/checks/is-number";
|
|
|
3
3
|
import { __optsWithID } from "./idgen.js";
|
|
4
4
|
import { fromInterval } from "./interval.js";
|
|
5
5
|
import { stream } from "./stream.js";
|
|
6
|
-
const fromRAF = (opts = {}) => isNode() ? fromInterval(16, opts) : stream(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
6
|
+
const fromRAF = (opts = {}) => isNode() ? fromInterval(16, opts) : stream(
|
|
7
|
+
(stream2) => {
|
|
8
|
+
let i = 0;
|
|
9
|
+
let isActive = true;
|
|
10
|
+
let t0 = isNumber(opts.t0) ? opts.t0 : void 0;
|
|
11
|
+
const loop = (time) => {
|
|
12
|
+
if (opts.timestamp && opts.t0) {
|
|
13
|
+
if (t0 === void 0) t0 = time;
|
|
14
|
+
time -= t0;
|
|
15
|
+
}
|
|
16
|
+
isActive && stream2.next(opts.timestamp ? time : i++);
|
|
17
|
+
isActive && (id = requestAnimationFrame(loop));
|
|
18
|
+
};
|
|
19
|
+
let id = requestAnimationFrame(loop);
|
|
20
|
+
return () => {
|
|
21
|
+
isActive = false;
|
|
22
|
+
cancelAnimationFrame(id);
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
__optsWithID("raf", opts)
|
|
26
|
+
);
|
|
24
27
|
export {
|
|
25
28
|
fromRAF
|
|
26
29
|
};
|