@thi.ng/rstream 9.0.9 → 9.1.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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-11-24T18:15:49Z
3
+ - **Last updated**: 2024-12-04T15:08:17Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [9.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rstream@9.1.0) (2024-12-04)
13
+
14
+ #### 🚀 Features
15
+
16
+ - update fromObject(), re-implement as full subscription ([6903507](https://github.com/thi-ng/umbrella/commit/6903507))
17
+
12
18
  # [9.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rstream@9.0.0) (2024-08-20)
13
19
 
14
20
  #### 🛑 Breaking changes
package/object.d.ts CHANGED
@@ -1,29 +1,9 @@
1
- import type { Keys, Predicate2 } from "@thi.ng/api";
1
+ import type { IObjectOf, Keys, NumOrString, Predicate2 } from "@thi.ng/api";
2
2
  import type { CommonOpts, ISubscription } from "./api.js";
3
+ import { Subscription } from "./subscription.js";
3
4
  export type KeyStreams<T, K extends Keys<T>> = {
4
5
  [id in K]-?: ISubscription<T[id], T[id]>;
5
6
  };
6
- /**
7
- * Result object type for {@link fromObject}.
8
- */
9
- export interface StreamObj<T, K extends Keys<T>> {
10
- /**
11
- * Object of managed & typed streams for registered keys.
12
- */
13
- streams: KeyStreams<T, K>;
14
- /**
15
- * Feeds new values from `x` to each registered key's stream.
16
- * Satifies {@link ISubscriber.next} interface.
17
- *
18
- * @param x -
19
- */
20
- next(x: T): void;
21
- /**
22
- * Calls {@link ISubscriber.done} for all streams created. Satifies
23
- * {@link ISubscriber.done} interface.
24
- */
25
- done(): void;
26
- }
27
7
  export interface StreamObjOpts<T, K extends Keys<T>> extends CommonOpts {
28
8
  /**
29
9
  * Array of selected `keys` (else selects all by default) for which
@@ -131,4 +111,25 @@ export interface StreamObjOpts<T, K extends Keys<T>> extends CommonOpts {
131
111
  * @param opts -
132
112
  */
133
113
  export declare const fromObject: <T extends object, K extends Keys<T>>(src: T, opts?: Partial<StreamObjOpts<T, K>>) => StreamObj<T, K>;
114
+ export declare class StreamObj<T extends object, K extends Keys<T>> extends Subscription<T, T> {
115
+ /**
116
+ * Object of managed & typed streams for registered keys.
117
+ */
118
+ keys: NumOrString[];
119
+ streams: IObjectOf<Subscription<any, any>>;
120
+ defaults?: Partial<T>;
121
+ constructor(src: T, opts?: Partial<StreamObjOpts<T, K>>);
122
+ /**
123
+ * Feeds new values from `x` to each registered key's stream.
124
+ * Satifies {@link ISubscriber.next} interface.
125
+ *
126
+ * @param x -
127
+ */
128
+ next(x: T): void;
129
+ /**
130
+ * Calls {@link ISubscriber.done} for all streams created. Satifies
131
+ * {@link ISubscriber.done} interface.
132
+ */
133
+ done(): void;
134
+ }
134
135
  //# sourceMappingURL=object.d.ts.map
package/object.js CHANGED
@@ -1,39 +1,56 @@
1
1
  import { dedupe } from "@thi.ng/transducers/dedupe";
2
- import { __nextID } from "./idgen.js";
3
- import { subscription } from "./subscription.js";
4
- const fromObject = (src, opts = {}) => {
5
- const id = opts.id || `obj${__nextID()}`;
6
- const keys = opts.keys || Object.keys(src);
7
- const _opts = opts.dedupe !== false ? {
8
- xform: dedupe(opts.equiv || ((a, b) => a === b)),
9
- ...opts
10
- } : opts;
11
- const streams = {};
12
- for (let k of keys) {
13
- streams[k] = subscription(void 0, {
14
- ..._opts,
15
- id: `${id}-${String(k)}`
16
- });
2
+ import { __optsWithID } from "./idgen.js";
3
+ import { Subscription, subscription } from "./subscription.js";
4
+ const fromObject = (src, opts = {}) => new StreamObj(src, opts);
5
+ class StreamObj extends Subscription {
6
+ /**
7
+ * Object of managed & typed streams for registered keys.
8
+ */
9
+ keys;
10
+ streams = {};
11
+ defaults;
12
+ constructor(src, opts = {}) {
13
+ super(void 0, __optsWithID("obj", opts));
14
+ this.keys = opts.keys || Object.keys(src);
15
+ this.defaults = opts.defaults;
16
+ const _opts = opts.dedupe !== false ? {
17
+ xform: dedupe(opts.equiv || ((a, b) => a === b)),
18
+ ...opts
19
+ } : opts;
20
+ for (let k of this.keys) {
21
+ this.streams[k] = subscription(void 0, {
22
+ ..._opts,
23
+ id: `${this.id}-${k}`
24
+ });
25
+ }
26
+ opts.initial !== false && this.next(src);
17
27
  }
18
- const res = {
19
- streams,
20
- next(state) {
21
- for (let k of keys) {
22
- const val = state[k];
23
- streams[k].next(
24
- opts.defaults && val === void 0 ? opts.defaults[k] : val
25
- );
26
- }
27
- },
28
- done() {
29
- for (let k of keys) {
30
- streams[k].done();
31
- }
28
+ /**
29
+ * Feeds new values from `x` to each registered key's stream.
30
+ * Satifies {@link ISubscriber.next} interface.
31
+ *
32
+ * @param x -
33
+ */
34
+ next(x) {
35
+ this.cacheLast && (this.last = x);
36
+ for (let k of this.keys) {
37
+ const val = x[k];
38
+ this.streams[k].next(
39
+ this.defaults && val === void 0 ? this.defaults[k] : val
40
+ );
32
41
  }
33
- };
34
- opts.initial !== false && res.next(src);
35
- return res;
36
- };
42
+ }
43
+ /**
44
+ * Calls {@link ISubscriber.done} for all streams created. Satifies
45
+ * {@link ISubscriber.done} interface.
46
+ */
47
+ done() {
48
+ for (let k of this.keys) {
49
+ this.streams[k].done();
50
+ }
51
+ }
52
+ }
37
53
  export {
54
+ StreamObj,
38
55
  fromObject
39
56
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/rstream",
3
- "version": "9.0.9",
3
+ "version": "9.1.0",
4
4
  "description": "Reactive streams & subscription primitives for constructing dataflow graphs / pipelines",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -219,5 +219,5 @@
219
219
  ],
220
220
  "year": 2017
221
221
  },
222
- "gitHead": "85e2f0935b58bde5d165fbe754fafec5da0b731e\n"
222
+ "gitHead": "7f97d3a454bb605afabf785af1736cb155ecced4\n"
223
223
  }