@thi.ng/rstream
Advanced tools
Comparing version 9.1.0 to 9.2.0
# Change Log | ||
- **Last updated**: 2024-12-04T15:08:17Z | ||
- **Last updated**: 2024-12-05T12:02:40Z | ||
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub) | ||
@@ -12,2 +12,10 @@ | ||
## [9.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rstream@9.2.0) (2024-12-05) | ||
#### 🚀 Features | ||
- add fromTuple(), update StreamObj impl ([ef691cc](https://github.com/thi-ng/umbrella/commit/ef691cc)) | ||
- update docs | ||
- add tests | ||
## [9.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rstream@9.1.0) (2024-12-04) | ||
@@ -14,0 +22,0 @@ |
@@ -41,33 +41,23 @@ import type { IObjectOf, Keys, NumOrString, Predicate2 } from "@thi.ng/api"; | ||
* Takes an arbitrary object `src` and object of options (see | ||
* {@link StreamObjOpts}). Creates a new object and for each selected | ||
* key creates a new stream, optionally seeded with the key's value in | ||
* `src`. Returns new object of streams. | ||
* {@link StreamObjOpts}). Creates a new object and for each selected key | ||
* creates a new subscription, optionally seeded with the key's value in `src`. | ||
* Returns new {@link StreamObj}. | ||
* | ||
* @remarks | ||
* The structure of the returned object is | ||
* {@link StreamObj | as follows}: | ||
* The optional `opts` arg is used to customize overall behavior of `fromObject` | ||
* and specify shared options for *all* created streams. | ||
* | ||
* ```text | ||
* { | ||
* streams: { ... }, | ||
* next(x): void; | ||
* done(): void; | ||
* } | ||
* ``` | ||
* A {@link StreamObj} is a full {@link Subscription}, in which additionally all | ||
* configured key streams are exposed under `streams`. The | ||
* {@link StreamObj.next} and {@link StreamObj.done} methods allow the | ||
* {@link StreamObj} itself to be used as subscriber for an upstream | ||
* subscribable (see 2nd example below): | ||
* | ||
* All streams will be stored under `streams`. The `next()` and `done()` | ||
* functions/methods allow the object itself to be used as subscriber | ||
* for an upstream subscribable (see 2nd example below): | ||
* {@link StreamObj.next} receives an object of same type as `src` and feeds | ||
* each key's new value into its respective {@link StreamObj.streams}. If the | ||
* {@link StreamObjOpts.defaults} option is given, `undefined` key values are | ||
* replaced with their specified default. If {@link StreamObjOpts.dedupe} is | ||
* enabled (default) only changed values (as per {@link StreamObjOpts.equiv} | ||
* predicate option) will be propagated downstream. | ||
* | ||
* - `next()` - takes a object of same type as `src` and feeds each | ||
* key's new value into its respective stream. If the `defaults` | ||
* option is given, `undefined` key values are replaced with their | ||
* specified default. If `dedupe` is enabled (default) only changed | ||
* values (as per `equiv` predicate option) will be propagated | ||
* downstream. | ||
* - `done()` - calls {@link ISubscriber.done} on all streams | ||
* | ||
* The optional `opts` arg is used to customize overall behavior of | ||
* `fromObject` and specify shared options for *all* created streams. | ||
* | ||
* @example | ||
@@ -103,3 +93,3 @@ * ```ts tangle:../export/from-object.ts | ||
* const src = subscription<Foo, Foo>(); | ||
* // use as subscriber | ||
* // use `obj` as subscription itself | ||
* src.subscribe(obj); | ||
@@ -116,2 +106,23 @@ * | ||
export declare const fromObject: <T extends object, K extends Keys<T>>(src: T, opts?: Partial<StreamObjOpts<T, K>>) => StreamObj<T, K>; | ||
/** | ||
* Syntax sugar for {@link fromObject} for tuple/arrays. Returns a | ||
* {@link StreamObj} which provides individual subscriptions for each tuple | ||
* element, i.e. 1:N fanout. | ||
* | ||
* ```ts tangle:../export/from-tuple.ts | ||
* import { fromTuple, subscription, trace } from "@thi.ng/rstream"; | ||
* | ||
* const tup = fromTuple([1, 2, 3]); | ||
* | ||
* tup.streams[0].subscribe(trace("[0]:")); | ||
* tup.streams[1].subscribe(trace("[1]:")); | ||
* tup.streams[2].subscribe(trace("[2]:")); | ||
* ``` | ||
* @param src | ||
* @param opts | ||
*/ | ||
export declare const fromTuple: <T>(src: T[], opts?: Partial<StreamObjOpts<T[], number>>) => StreamObj<T[], number>; | ||
/** | ||
* See {@link fromObject} for details. | ||
*/ | ||
export declare class StreamObj<T extends object, K extends Keys<T>> extends Subscription<T, T> { | ||
@@ -126,4 +137,9 @@ /** | ||
/** | ||
* Feeds new values from `x` to each registered key's stream. | ||
* Satifies {@link ISubscriber.next} interface. | ||
* Receives an object of configured type and feeds each key's new value into | ||
* its respective {@link StreamObj.streams}. If the | ||
* {@link StreamObjOpts.defaults} option is given, `undefined` key values | ||
* are replaced with their specified default. If | ||
* {@link StreamObjOpts.dedupe} is enabled (default) only changed values (as | ||
* per {@link StreamObjOpts.equiv} predicate option) will be propagated | ||
* downstream. | ||
* | ||
@@ -133,8 +149,5 @@ * @param x - | ||
next(x: T): void; | ||
/** | ||
* Calls {@link ISubscriber.done} for all streams created. Satifies | ||
* {@link ISubscriber.done} interface. | ||
*/ | ||
done(): void; | ||
unsubscribe(sub?: ISubscription<T, any> | undefined): boolean; | ||
} | ||
//# sourceMappingURL=object.d.ts.map |
import { dedupe } from "@thi.ng/transducers/dedupe"; | ||
import { __optsWithID } from "./idgen.js"; | ||
import { Subscription, subscription } from "./subscription.js"; | ||
import { range } from "@thi.ng/transducers"; | ||
const fromObject = (src, opts = {}) => new StreamObj(src, opts); | ||
const fromTuple = (src, opts) => new StreamObj(src, { keys: [...range(src.length)], ...opts }); | ||
class StreamObj extends Subscription { | ||
@@ -29,4 +31,9 @@ /** | ||
/** | ||
* Feeds new values from `x` to each registered key's stream. | ||
* Satifies {@link ISubscriber.next} interface. | ||
* Receives an object of configured type and feeds each key's new value into | ||
* its respective {@link StreamObj.streams}. If the | ||
* {@link StreamObjOpts.defaults} option is given, `undefined` key values | ||
* are replaced with their specified default. If | ||
* {@link StreamObjOpts.dedupe} is enabled (default) only changed values (as | ||
* per {@link StreamObjOpts.equiv} predicate option) will be propagated | ||
* downstream. | ||
* | ||
@@ -43,7 +50,4 @@ * @param x - | ||
} | ||
super.next(x); | ||
} | ||
/** | ||
* Calls {@link ISubscriber.done} for all streams created. Satifies | ||
* {@link ISubscriber.done} interface. | ||
*/ | ||
done() { | ||
@@ -53,7 +57,17 @@ for (let k of this.keys) { | ||
} | ||
super.done(); | ||
} | ||
unsubscribe(sub) { | ||
if (!sub) { | ||
for (let k of this.keys) { | ||
this.streams[k].unsubscribe(); | ||
} | ||
} | ||
return super.unsubscribe(sub); | ||
} | ||
} | ||
export { | ||
StreamObj, | ||
fromObject | ||
fromObject, | ||
fromTuple | ||
}; |
{ | ||
"name": "@thi.ng/rstream", | ||
"version": "9.1.0", | ||
"version": "9.2.0", | ||
"description": "Reactive streams & subscription primitives for constructing dataflow graphs / pipelines", | ||
@@ -222,3 +222,3 @@ "type": "module", | ||
}, | ||
"gitHead": "7f97d3a454bb605afabf785af1736cb155ecced4\n" | ||
"gitHead": "b3cc41cd55dd21cf672c2567b748b0a632b01d76\n" | ||
} |
@@ -218,3 +218,3 @@ <!-- This file is generated - DO NOT EDIT! --> | ||
Package sizes (brotli'd, pre-treeshake): ESM: 6.28 KB | ||
Package sizes (brotli'd, pre-treeshake): ESM: 6.34 KB | ||
@@ -455,2 +455,3 @@ ## Dependencies | ||
- [fromRAF()](https://docs.thi.ng/umbrella/rstream/functions/fromRAF.html) - requestAnimationFrame() counter (w/ node fallback) | ||
- [fromTuple()](https://docs.thi.ng/umbrella/rstream/functions/fromTuple.html) - tuple/vector per-component streams | ||
- [fromView()](https://docs.thi.ng/umbrella/rstream/functions/fromView.html) - derived view value changes (see [@thi.ng/atom](https://github.com/thi-ng/umbrella/tree/develop/packages/atom)) | ||
@@ -457,0 +458,0 @@ - [fromWorker()](https://docs.thi.ng/umbrella/rstream/functions/fromWorker.html) - messages received from worker |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
252091
3979
1013