@effectionx/stream-helpers 0.1.0 → 0.2.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 CHANGED
@@ -241,11 +241,11 @@ await run(function* () {
241
241
  // Pass an operation to control the rate at which items are sent to the stream
242
242
  yield* faucet.pour(function* (send) {
243
243
  yield* sleep(10);
244
- send(5);
244
+ yield* send(5);
245
245
  yield* sleep(30);
246
- send(6);
246
+ yield* send(6);
247
247
  yield* sleep(10);
248
- send(7);
248
+ yield* send(7);
249
249
  });
250
250
 
251
251
  // You can close the faucet to stop items from being sent
@@ -256,5 +256,7 @@ await run(function* () {
256
256
  });
257
257
  ```
258
258
 
259
- Items sent to the faucet stream while it's closed are not buffered, in other
260
- words, they'll be dropped.
259
+ When passing a function to `faucet.pour`, the `send` function will return an
260
+ operation. This operation will block when the faucet is closed. This is
261
+ particularly helpful when testing backpressure, because you can send many event
262
+ without worrying about the `open/close` state.
package/esm/batch.d.ts CHANGED
@@ -16,6 +16,6 @@ export interface BatchOptions {
16
16
  * @param options.maxSize - The maximum size of a batch.
17
17
  * @returns A stream of arrays of items from the source stream.
18
18
  */
19
- export declare function batch(options: RequireAtLeastOne<BatchOptions>): <T>(stream: Stream<T, never>) => Stream<T[], never>;
19
+ export declare function batch(options: RequireAtLeastOne<BatchOptions>): <T>(stream: Stream<T, never>) => Stream<Readonly<T[]>, never>;
20
20
  export {};
21
21
  //# sourceMappingURL=batch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../src/batch.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAGlE,KAAK,iBAAiB,CAAC,CAAC,EAAE,IAAI,SAAS,MAAM,CAAC,GAAG,MAAM,CAAC,IACpD,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,GAC/B;KACC,C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B,CAAC,YAAY,CAAC,GACvC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CA4C/D"}
package/esm/batch.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { each, race, sleep, spawn } from "effection";
2
- import { createArraySignal, is } from "./signals.js";
2
+ import { createArraySignal, is } from "@effectionx/signals";
3
3
  /**
4
4
  * Creates batches of items from the source stream. The batches can be created either by
5
5
  * specifying a maximum time or a maximum size. If both are specified, the batch will be
@@ -1,5 +1,5 @@
1
1
  import { createSignal } from "effection";
2
- import { createBoolean, is } from "../signals.js";
2
+ import { createBooleanSignal, is } from "@effectionx/signals";
3
3
  /**
4
4
  * Creates a stream that can be used to test the behavior of streams that use backpressure.
5
5
  * It's useful in tests where it can be used as a source stream. This function is used to create
@@ -45,7 +45,7 @@ import { createBoolean, is } from "../signals.js";
45
45
  */
46
46
  export function* useFaucet(options) {
47
47
  let signal = createSignal();
48
- let open = yield* createBoolean(options.open);
48
+ let open = yield* createBooleanSignal(options.open);
49
49
  return {
50
50
  [Symbol.iterator]: signal[Symbol.iterator],
51
51
  *pour(items) {
package/esm/tracker.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { resource } from "effection";
2
- import { createSetSignal, is } from "./signals.js";
2
+ import { createSetSignal, is } from "@effectionx/signals";
3
3
  /**
4
4
  * Creates a tracker that can be used to verify that all items that entered the stream
5
5
  * eventually exit the stream. This is helpful when you want to ensure that all items
package/esm/valve.d.ts CHANGED
@@ -1,8 +1,23 @@
1
1
  import { type Operation, type Stream } from "effection";
2
+ /**
3
+ * Options for the valve.
4
+ */
2
5
  export interface ValveOptions {
6
+ /**
7
+ * The buffer size when {@link ValveOptions#open} method is called.
8
+ */
3
9
  openAt: number;
10
+ /**
11
+ * The buffer size when {@link ValveOptions#close} method is called.
12
+ */
4
13
  closeAt: number;
14
+ /**
15
+ * The operation to resume the upstream.
16
+ */
5
17
  open(): Operation<void>;
18
+ /**
19
+ * The operation to pause the upstream.
20
+ */
6
21
  close(): Operation<void>;
7
22
  }
8
23
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"valve.d.ts","sourceRoot":"","sources":["../src/valve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,SAAS,EAAS,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAGrE,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;IACxB,KAAK,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CACnB,OAAO,EAAE,YAAY,GACpB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAkCnD"}
1
+ {"version":3,"file":"valve.d.ts","sourceRoot":"","sources":["../src/valve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,SAAS,EAAS,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAGrE;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;IACxB;;OAEG;IACH,KAAK,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CACnB,OAAO,EAAE,YAAY,GACpB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAkCnD"}
package/esm/valve.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { each, spawn } from "effection";
2
- import { createArraySignal } from "./signals.js";
2
+ import { createArraySignal } from "@effectionx/signals";
3
3
  /**
4
4
  * This function buffers incoming items, if the upstream is producing faster than the downstream
5
5
  * can consume, the buffer will grow. If the buffer size exceeds the `closeAt` threshold, the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effectionx/stream-helpers",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "author": "engineering@frontside.com",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,9 +22,14 @@
22
22
  "require": "./script/test-helpers.js"
23
23
  }
24
24
  },
25
+ "scripts": {},
25
26
  "engines": {
26
27
  "node": ">= 16"
27
28
  },
28
29
  "sideEffects": false,
30
+ "dependencies": {
31
+ "@effectionx/signals": "^0.1.0",
32
+ "effection": "^3"
33
+ },
29
34
  "_generatedBy": "dnt@dev"
30
35
  }
package/script/batch.d.ts CHANGED
@@ -16,6 +16,6 @@ export interface BatchOptions {
16
16
  * @param options.maxSize - The maximum size of a batch.
17
17
  * @returns A stream of arrays of items from the source stream.
18
18
  */
19
- export declare function batch(options: RequireAtLeastOne<BatchOptions>): <T>(stream: Stream<T, never>) => Stream<T[], never>;
19
+ export declare function batch(options: RequireAtLeastOne<BatchOptions>): <T>(stream: Stream<T, never>) => Stream<Readonly<T[]>, never>;
20
20
  export {};
21
21
  //# sourceMappingURL=batch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../src/batch.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAGlE,KAAK,iBAAiB,CAAC,CAAC,EAAE,IAAI,SAAS,MAAM,CAAC,GAAG,MAAM,CAAC,IACpD,IAAI,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,GAC/B;KACC,C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B,CAAC,YAAY,CAAC,GACvC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CA4C/D"}
package/script/batch.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.batch = batch;
4
4
  const effection_1 = require("effection");
5
- const signals_js_1 = require("./signals.js");
5
+ const signals_1 = require("@effectionx/signals");
6
6
  /**
7
7
  * Creates batches of items from the source stream. The batches can be created either by
8
8
  * specifying a maximum time or a maximum size. If both are specified, the batch will be
@@ -17,13 +17,13 @@ function batch(options) {
17
17
  return function (stream) {
18
18
  return {
19
19
  *[Symbol.iterator]() {
20
- let batch = yield* (0, signals_js_1.createArraySignal)([]);
20
+ let batch = yield* (0, signals_1.createArraySignal)([]);
21
21
  yield* (0, effection_1.spawn)(function* () {
22
22
  for (let item of yield* (0, effection_1.each)(stream)) {
23
23
  batch.push(item);
24
24
  if (options.maxSize && batch.length >= options.maxSize) {
25
25
  // wait until it's drained
26
- yield* (0, signals_js_1.is)(batch, (batch) => batch.length === 0);
26
+ yield* (0, signals_1.is)(batch, (batch) => batch.length === 0);
27
27
  }
28
28
  yield* effection_1.each.next();
29
29
  }
@@ -35,10 +35,10 @@ function batch(options) {
35
35
  }
36
36
  return {
37
37
  *next() {
38
- yield* (0, signals_js_1.is)(batch, (batch) => batch.length >= 1);
38
+ yield* (0, signals_1.is)(batch, (batch) => batch.length >= 1);
39
39
  if (options.maxTime && options.maxSize) {
40
40
  yield* (0, effection_1.race)([
41
- (0, signals_js_1.is)(batch, (batch) => batch.length === options.maxSize),
41
+ (0, signals_1.is)(batch, (batch) => batch.length === options.maxSize),
42
42
  (0, effection_1.sleep)(options.maxTime),
43
43
  ]);
44
44
  }
@@ -46,7 +46,7 @@ function batch(options) {
46
46
  yield* (0, effection_1.sleep)(options.maxTime);
47
47
  }
48
48
  else if (options.maxSize) {
49
- yield* (0, signals_js_1.is)(batch, (batch) => batch.length === options.maxSize);
49
+ yield* (0, signals_1.is)(batch, (batch) => batch.length === options.maxSize);
50
50
  }
51
51
  return { done: false, value: drain() };
52
52
  },
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useFaucet = useFaucet;
4
4
  const effection_1 = require("effection");
5
- const signals_js_1 = require("../signals.js");
5
+ const signals_1 = require("@effectionx/signals");
6
6
  /**
7
7
  * Creates a stream that can be used to test the behavior of streams that use backpressure.
8
8
  * It's useful in tests where it can be used as a source stream. This function is used to create
@@ -48,19 +48,19 @@ const signals_js_1 = require("../signals.js");
48
48
  */
49
49
  function* useFaucet(options) {
50
50
  let signal = (0, effection_1.createSignal)();
51
- let open = yield* (0, signals_js_1.createBoolean)(options.open);
51
+ let open = yield* (0, signals_1.createBooleanSignal)(options.open);
52
52
  return {
53
53
  [Symbol.iterator]: signal[Symbol.iterator],
54
54
  *pour(items) {
55
55
  if (Array.isArray(items)) {
56
56
  for (let i of items) {
57
- yield* (0, signals_js_1.is)(open, (open) => open);
57
+ yield* (0, signals_1.is)(open, (open) => open);
58
58
  signal.send(i);
59
59
  }
60
60
  }
61
61
  else {
62
62
  yield* items(function* (item) {
63
- yield* (0, signals_js_1.is)(open, (open) => open);
63
+ yield* (0, signals_1.is)(open, (open) => open);
64
64
  signal.send(item);
65
65
  });
66
66
  }
package/script/tracker.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTracker = createTracker;
4
4
  const effection_1 = require("effection");
5
- const signals_js_1 = require("./signals.js");
5
+ const signals_1 = require("@effectionx/signals");
6
6
  /**
7
7
  * Creates a tracker that can be used to verify that all items that entered the stream
8
8
  * eventually exit the stream. This is helpful when you want to ensure that all items
@@ -10,10 +10,10 @@ const signals_js_1 = require("./signals.js");
10
10
  */
11
11
  function createTracker() {
12
12
  return (0, effection_1.resource)(function* (provide) {
13
- const tracked = yield* (0, signals_js_1.createSetSignal)();
13
+ const tracked = yield* (0, signals_1.createSetSignal)();
14
14
  yield* provide({
15
15
  *[Symbol.iterator]() {
16
- yield* (0, signals_js_1.is)(tracked, (set) => set.size === 0);
16
+ yield* (0, signals_1.is)(tracked, (set) => set.size === 0);
17
17
  },
18
18
  passthrough() {
19
19
  return function (stream) {
package/script/valve.d.ts CHANGED
@@ -1,8 +1,23 @@
1
1
  import { type Operation, type Stream } from "effection";
2
+ /**
3
+ * Options for the valve.
4
+ */
2
5
  export interface ValveOptions {
6
+ /**
7
+ * The buffer size when {@link ValveOptions#open} method is called.
8
+ */
3
9
  openAt: number;
10
+ /**
11
+ * The buffer size when {@link ValveOptions#close} method is called.
12
+ */
4
13
  closeAt: number;
14
+ /**
15
+ * The operation to resume the upstream.
16
+ */
5
17
  open(): Operation<void>;
18
+ /**
19
+ * The operation to pause the upstream.
20
+ */
6
21
  close(): Operation<void>;
7
22
  }
8
23
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"valve.d.ts","sourceRoot":"","sources":["../src/valve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,SAAS,EAAS,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAGrE,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;IACxB,KAAK,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CACnB,OAAO,EAAE,YAAY,GACpB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAkCnD"}
1
+ {"version":3,"file":"valve.d.ts","sourceRoot":"","sources":["../src/valve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,SAAS,EAAS,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAGrE;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;IACxB;;OAEG;IACH,KAAK,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CACnB,OAAO,EAAE,YAAY,GACpB,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAkCnD"}
package/script/valve.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.valve = valve;
4
4
  const effection_1 = require("effection");
5
- const signals_js_1 = require("./signals.js");
5
+ const signals_1 = require("@effectionx/signals");
6
6
  /**
7
7
  * This function buffers incoming items, if the upstream is producing faster than the downstream
8
8
  * can consume, the buffer will grow. If the buffer size exceeds the `closeAt` threshold, the
@@ -20,7 +20,7 @@ function valve(options) {
20
20
  return function (stream) {
21
21
  return {
22
22
  *[Symbol.iterator]() {
23
- const buffer = yield* (0, signals_js_1.createArraySignal)([]);
23
+ const buffer = yield* (0, signals_1.createArraySignal)([]);
24
24
  let open = true;
25
25
  yield* (0, effection_1.spawn)(function* () {
26
26
  for (const item of yield* (0, effection_1.each)(stream)) {
package/esm/signals.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import { type Operation, type Stream } from "effection";
2
- interface ValueStream<T> extends Stream<T, void> {
3
- valueOf(): T;
4
- }
5
- interface Settable<T> {
6
- set(value: T): T;
7
- }
8
- export interface SettableValue<T> extends Settable<T>, ValueStream<T> {
9
- }
10
- interface ArraySignal<T> extends SettableValue<T[]> {
11
- push(item: T): number;
12
- shift(): Operation<T>;
13
- valueOf(): T[];
14
- get length(): number;
15
- }
16
- export declare function createArraySignal<T>(initial: Iterable<T>): Operation<ArraySignal<T>>;
17
- export declare function is<T>(array: ValueStream<T>, predicate: (item: T) => boolean): Generator<any, void, any>;
18
- export interface BooleanSignal extends SettableValue<boolean> {
19
- }
20
- export declare function createBoolean(initial?: boolean): any;
21
- export declare function createSetSignal<T>(initial?: Array<T>): any;
22
- export {};
23
- //# sourceMappingURL=signals.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["../src/signals.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,SAAS,EAEd,KAAK,MAAM,EACZ,MAAM,WAAW,CAAC;AAGnB,UAAU,WAAW,CAAC,CAAC,CAAE,SAAQ,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC;IAC9C,OAAO,IAAI,CAAC,CAAC;CACd;AAED,UAAU,QAAQ,CAAC,CAAC;IAClB,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;CAClB;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC;CAAG;AAExE,UAAU,WAAW,CAAC,CAAC,CAAE,SAAQ,aAAa,CAAC,CAAC,EAAE,CAAC;IACjD,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC;IACtB,KAAK,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;IACtB,OAAO,IAAI,CAAC,EAAE,CAAC;IACf,IAAI,MAAM,IAAI,MAAM,CAAC;CACtB;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,GACnB,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAwC3B;AAED,wBAAiB,EAAE,CAAC,CAAC,EACnB,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EACrB,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,6BAahC;AAED,MAAM,WAAW,aAAc,SAAQ,aAAa,CAAC,OAAO,CAAC;CAC5D;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,OAAe,OA0BrD;AASD,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,GAAE,KAAK,CAAC,CAAC,CAAM,OAwCxD"}
package/esm/signals.js DELETED
@@ -1,119 +0,0 @@
1
- import { createSignal, each, resource, } from "effection";
2
- import { List, Set } from "immutable";
3
- export function createArraySignal(initial) {
4
- return resource(function* (provide) {
5
- const signal = createSignal();
6
- const ref = {
7
- current: List.of(...initial),
8
- };
9
- const array = {
10
- [Symbol.iterator]: signal[Symbol.iterator],
11
- set(value) {
12
- ref.current = List.of(...value);
13
- signal.send(ref.current.toArray());
14
- return ref.current.toArray();
15
- },
16
- push(item) {
17
- ref.current = ref.current.push(item);
18
- signal.send(ref.current.toArray());
19
- return ref.current.size;
20
- },
21
- *shift() {
22
- yield* is(array, (array) => array.length > 0);
23
- let value = ref.current.first();
24
- ref.current = ref.current.shift();
25
- signal.send(ref.current.toArray());
26
- return value;
27
- },
28
- valueOf() {
29
- return ref.current.toArray();
30
- },
31
- get length() {
32
- return ref.current.size;
33
- },
34
- };
35
- try {
36
- yield* provide(array);
37
- }
38
- finally {
39
- signal.close();
40
- }
41
- });
42
- }
43
- export function* is(array, predicate) {
44
- const result = predicate(array.valueOf());
45
- if (result) {
46
- return;
47
- }
48
- for (const value of yield* each(array)) {
49
- const result = predicate(value);
50
- if (result) {
51
- return;
52
- }
53
- yield* each.next();
54
- }
55
- }
56
- export function createBoolean(initial = false) {
57
- return resource(function* (provide) {
58
- const signal = createSignal();
59
- const ref = { current: initial };
60
- try {
61
- yield* provide({
62
- [Symbol.iterator]: signal[Symbol.iterator],
63
- set(value) {
64
- if (value !== ref.current) {
65
- ref.current = value;
66
- signal.send(ref.current);
67
- }
68
- return ref.current;
69
- },
70
- valueOf() {
71
- return ref.current;
72
- },
73
- });
74
- }
75
- finally {
76
- signal.close();
77
- }
78
- });
79
- }
80
- export function createSetSignal(initial = []) {
81
- return resource(function* (provide) {
82
- const signal = createSignal();
83
- const ref = { current: Set.of(...initial) };
84
- try {
85
- yield* provide({
86
- [Symbol.iterator]: signal[Symbol.iterator],
87
- set(value) {
88
- ref.current = Set.of(...value);
89
- signal.send(ref.current.toSet());
90
- return ref.current;
91
- },
92
- add(item) {
93
- ref.current = ref.current.add(item);
94
- signal.send(ref.current.toSet());
95
- return ref.current.toSet();
96
- },
97
- difference(items) {
98
- ref.current = ref.current.subtract(items);
99
- signal.send(ref.current.toSet());
100
- return ref.current.toSet();
101
- },
102
- delete(item) {
103
- if (ref.current.has(item)) {
104
- ref.current = ref.current.delete(item);
105
- signal.send(ref.current.toSet());
106
- return true;
107
- }
108
- return false;
109
- },
110
- valueOf() {
111
- return ref.current.toSet();
112
- },
113
- });
114
- }
115
- finally {
116
- signal.close();
117
- }
118
- });
119
- }
@@ -1,23 +0,0 @@
1
- import { type Operation, type Stream } from "effection";
2
- interface ValueStream<T> extends Stream<T, void> {
3
- valueOf(): T;
4
- }
5
- interface Settable<T> {
6
- set(value: T): T;
7
- }
8
- export interface SettableValue<T> extends Settable<T>, ValueStream<T> {
9
- }
10
- interface ArraySignal<T> extends SettableValue<T[]> {
11
- push(item: T): number;
12
- shift(): Operation<T>;
13
- valueOf(): T[];
14
- get length(): number;
15
- }
16
- export declare function createArraySignal<T>(initial: Iterable<T>): Operation<ArraySignal<T>>;
17
- export declare function is<T>(array: ValueStream<T>, predicate: (item: T) => boolean): Generator<any, void, any>;
18
- export interface BooleanSignal extends SettableValue<boolean> {
19
- }
20
- export declare function createBoolean(initial?: boolean): any;
21
- export declare function createSetSignal<T>(initial?: Array<T>): any;
22
- export {};
23
- //# sourceMappingURL=signals.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["../src/signals.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,SAAS,EAEd,KAAK,MAAM,EACZ,MAAM,WAAW,CAAC;AAGnB,UAAU,WAAW,CAAC,CAAC,CAAE,SAAQ,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC;IAC9C,OAAO,IAAI,CAAC,CAAC;CACd;AAED,UAAU,QAAQ,CAAC,CAAC;IAClB,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;CAClB;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC;CAAG;AAExE,UAAU,WAAW,CAAC,CAAC,CAAE,SAAQ,aAAa,CAAC,CAAC,EAAE,CAAC;IACjD,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC;IACtB,KAAK,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;IACtB,OAAO,IAAI,CAAC,EAAE,CAAC;IACf,IAAI,MAAM,IAAI,MAAM,CAAC;CACtB;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,GACnB,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAwC3B;AAED,wBAAiB,EAAE,CAAC,CAAC,EACnB,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EACrB,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,6BAahC;AAED,MAAM,WAAW,aAAc,SAAQ,aAAa,CAAC,OAAO,CAAC;CAC5D;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,OAAe,OA0BrD;AASD,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,GAAE,KAAK,CAAC,CAAC,CAAM,OAwCxD"}
package/script/signals.js DELETED
@@ -1,125 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createArraySignal = createArraySignal;
4
- exports.is = is;
5
- exports.createBoolean = createBoolean;
6
- exports.createSetSignal = createSetSignal;
7
- const effection_1 = require("effection");
8
- const immutable_1 = require("immutable");
9
- function createArraySignal(initial) {
10
- return (0, effection_1.resource)(function* (provide) {
11
- const signal = (0, effection_1.createSignal)();
12
- const ref = {
13
- current: immutable_1.List.of(...initial),
14
- };
15
- const array = {
16
- [Symbol.iterator]: signal[Symbol.iterator],
17
- set(value) {
18
- ref.current = immutable_1.List.of(...value);
19
- signal.send(ref.current.toArray());
20
- return ref.current.toArray();
21
- },
22
- push(item) {
23
- ref.current = ref.current.push(item);
24
- signal.send(ref.current.toArray());
25
- return ref.current.size;
26
- },
27
- *shift() {
28
- yield* is(array, (array) => array.length > 0);
29
- let value = ref.current.first();
30
- ref.current = ref.current.shift();
31
- signal.send(ref.current.toArray());
32
- return value;
33
- },
34
- valueOf() {
35
- return ref.current.toArray();
36
- },
37
- get length() {
38
- return ref.current.size;
39
- },
40
- };
41
- try {
42
- yield* provide(array);
43
- }
44
- finally {
45
- signal.close();
46
- }
47
- });
48
- }
49
- function* is(array, predicate) {
50
- const result = predicate(array.valueOf());
51
- if (result) {
52
- return;
53
- }
54
- for (const value of yield* (0, effection_1.each)(array)) {
55
- const result = predicate(value);
56
- if (result) {
57
- return;
58
- }
59
- yield* effection_1.each.next();
60
- }
61
- }
62
- function createBoolean(initial = false) {
63
- return (0, effection_1.resource)(function* (provide) {
64
- const signal = (0, effection_1.createSignal)();
65
- const ref = { current: initial };
66
- try {
67
- yield* provide({
68
- [Symbol.iterator]: signal[Symbol.iterator],
69
- set(value) {
70
- if (value !== ref.current) {
71
- ref.current = value;
72
- signal.send(ref.current);
73
- }
74
- return ref.current;
75
- },
76
- valueOf() {
77
- return ref.current;
78
- },
79
- });
80
- }
81
- finally {
82
- signal.close();
83
- }
84
- });
85
- }
86
- function createSetSignal(initial = []) {
87
- return (0, effection_1.resource)(function* (provide) {
88
- const signal = (0, effection_1.createSignal)();
89
- const ref = { current: immutable_1.Set.of(...initial) };
90
- try {
91
- yield* provide({
92
- [Symbol.iterator]: signal[Symbol.iterator],
93
- set(value) {
94
- ref.current = immutable_1.Set.of(...value);
95
- signal.send(ref.current.toSet());
96
- return ref.current;
97
- },
98
- add(item) {
99
- ref.current = ref.current.add(item);
100
- signal.send(ref.current.toSet());
101
- return ref.current.toSet();
102
- },
103
- difference(items) {
104
- ref.current = ref.current.subtract(items);
105
- signal.send(ref.current.toSet());
106
- return ref.current.toSet();
107
- },
108
- delete(item) {
109
- if (ref.current.has(item)) {
110
- ref.current = ref.current.delete(item);
111
- signal.send(ref.current.toSet());
112
- return true;
113
- }
114
- return false;
115
- },
116
- valueOf() {
117
- return ref.current.toSet();
118
- },
119
- });
120
- }
121
- finally {
122
- signal.close();
123
- }
124
- });
125
- }