@effectionx/signals 0.4.1 → 0.5.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/array.test.ts +103 -0
- package/array.ts +100 -0
- package/boolean.test.ts +76 -0
- package/boolean.ts +38 -0
- package/{esm → dist}/array.d.ts +1 -1
- package/dist/array.d.ts.map +1 -0
- package/{esm → dist}/array.js +2 -1
- package/{script → dist}/boolean.d.ts +1 -1
- package/dist/boolean.d.ts.map +1 -0
- package/{esm → dist}/helpers.d.ts +1 -1
- package/dist/helpers.d.ts.map +1 -0
- package/dist/mod.d.ts +6 -0
- package/dist/mod.d.ts.map +1 -0
- package/{script → dist}/set.d.ts +1 -1
- package/dist/set.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts.map +1 -0
- package/helpers.test.ts +30 -0
- package/helpers.ts +25 -0
- package/mod.ts +5 -0
- package/package.json +22 -18
- package/set.test.ts +76 -0
- package/set.ts +90 -0
- package/tsconfig.json +14 -0
- package/types.ts +25 -0
- package/esm/array.d.ts.map +0 -1
- package/esm/boolean.d.ts +0 -6
- package/esm/boolean.d.ts.map +0 -1
- package/esm/helpers.d.ts.map +0 -1
- package/esm/mod.d.ts +0 -6
- package/esm/mod.d.ts.map +0 -1
- package/esm/package.json +0 -3
- package/esm/set.d.ts +0 -39
- package/esm/set.d.ts.map +0 -1
- package/esm/types.d.ts.map +0 -1
- package/script/array.d.ts +0 -44
- package/script/array.d.ts.map +0 -1
- package/script/array.js +0 -62
- package/script/boolean.d.ts.map +0 -1
- package/script/boolean.js +0 -32
- package/script/helpers.d.ts +0 -10
- package/script/helpers.d.ts.map +0 -1
- package/script/helpers.js +0 -23
- package/script/mod.d.ts +0 -6
- package/script/mod.d.ts.map +0 -1
- package/script/mod.js +0 -21
- package/script/package.json +0 -3
- package/script/set.d.ts.map +0 -1
- package/script/set.js +0 -58
- package/script/types.d.ts +0 -25
- package/script/types.d.ts.map +0 -1
- package/script/types.js +0 -2
- /package/{esm → dist}/boolean.js +0 -0
- /package/{esm → dist}/helpers.js +0 -0
- /package/{esm → dist}/mod.js +0 -0
- /package/{esm → dist}/set.js +0 -0
- /package/{esm → dist}/types.d.ts +0 -0
- /package/{esm → dist}/types.js +0 -0
package/package.json
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectionx/signals",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/mod.js",
|
|
6
|
+
"types": "./dist/mod.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"development": "./mod.ts",
|
|
10
|
+
"default": "./dist/mod.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"effection": "^3 || ^4"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"immutable": "^5"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
4
20
|
"author": "engineering@frontside.com",
|
|
5
21
|
"repository": {
|
|
6
22
|
"type": "git",
|
|
7
23
|
"url": "git+https://github.com/thefrontside/effectionx.git"
|
|
8
24
|
},
|
|
9
|
-
"license": "MIT",
|
|
10
25
|
"bugs": {
|
|
11
26
|
"url": "https://github.com/thefrontside/effectionx/issues"
|
|
12
27
|
},
|
|
13
|
-
"main": "./script/mod.js",
|
|
14
|
-
"module": "./esm/mod.js",
|
|
15
|
-
"exports": {
|
|
16
|
-
".": {
|
|
17
|
-
"import": "./esm/mod.js",
|
|
18
|
-
"require": "./script/mod.js"
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"scripts": {},
|
|
22
28
|
"engines": {
|
|
23
|
-
"node": ">=
|
|
29
|
+
"node": ">= 22"
|
|
24
30
|
},
|
|
25
31
|
"sideEffects": false,
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"_generatedBy": "dnt@dev"
|
|
31
|
-
}
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@effectionx/bdd": "workspace:*"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/set.test.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { describe, it } from "@effectionx/bdd";
|
|
2
|
+
import { expect } from "expect";
|
|
3
|
+
import { each, spawn } from "effection";
|
|
4
|
+
import { createSetSignal } from "./set.ts";
|
|
5
|
+
import { Set } from "immutable";
|
|
6
|
+
|
|
7
|
+
describe("createSetSignal", () => {
|
|
8
|
+
it("should create a set signal", function* () {
|
|
9
|
+
const set = yield* createSetSignal<number>([]);
|
|
10
|
+
|
|
11
|
+
set.add(1);
|
|
12
|
+
|
|
13
|
+
expect(set.valueOf().toArray()).toEqual([1]);
|
|
14
|
+
});
|
|
15
|
+
describe("set", () => {
|
|
16
|
+
it("should set the value of the set", function* () {
|
|
17
|
+
const set = yield* createSetSignal<number>([1, 2, 3]);
|
|
18
|
+
|
|
19
|
+
set.set(Set.of(4, 5, 6));
|
|
20
|
+
|
|
21
|
+
expect(set.valueOf().toArray()).toEqual([4, 5, 6]);
|
|
22
|
+
});
|
|
23
|
+
it("should not update if the set is the same", function* () {
|
|
24
|
+
const set = yield* createSetSignal<number>([1, 2, 3]);
|
|
25
|
+
|
|
26
|
+
const updates: number[][] = [];
|
|
27
|
+
|
|
28
|
+
yield* spawn(function* () {
|
|
29
|
+
for (const update of yield* each(set)) {
|
|
30
|
+
updates.push(update.toArray());
|
|
31
|
+
yield* each.next();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
set.set(Set.of(1, 2, 3));
|
|
36
|
+
|
|
37
|
+
expect(updates).toEqual([]);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe("difference", () => {
|
|
41
|
+
it("should return a new set with the items that are in the current set but not in the given iterable", function* () {
|
|
42
|
+
const set = yield* createSetSignal<number>([1, 2, 3]);
|
|
43
|
+
|
|
44
|
+
set.difference([2, 3, 4]);
|
|
45
|
+
|
|
46
|
+
expect(set.valueOf().toArray()).toEqual([1]);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe("delete", () => {
|
|
50
|
+
it("should remove an item from the set", function* () {
|
|
51
|
+
const set = yield* createSetSignal<number>([1, 2, 3]);
|
|
52
|
+
|
|
53
|
+
set.delete(2);
|
|
54
|
+
|
|
55
|
+
expect(set.valueOf().toArray()).toEqual([1, 3]);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe("add", () => {
|
|
59
|
+
it("should add an item to the set", function* () {
|
|
60
|
+
const set = yield* createSetSignal<number>([1, 2, 3]);
|
|
61
|
+
|
|
62
|
+
set.add(4);
|
|
63
|
+
|
|
64
|
+
expect(set.valueOf().toArray()).toEqual([1, 2, 3, 4]);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
describe("update", () => {
|
|
68
|
+
it("updates the value of the signal", function* () {
|
|
69
|
+
const set = yield* createSetSignal<number>([1, 2, 3]);
|
|
70
|
+
|
|
71
|
+
set.update((set) => set.add(4));
|
|
72
|
+
|
|
73
|
+
expect(set.valueOf().toArray()).toEqual([1, 2, 3, 4]);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
package/set.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { createSignal, type Operation, resource } from "effection";
|
|
2
|
+
import type { ValueSignal } from "./types.ts";
|
|
3
|
+
import { is, Set } from "immutable";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A signal that represents a Set.
|
|
7
|
+
*/
|
|
8
|
+
export interface SetSignal<T> extends ValueSignal<Set<T>> {
|
|
9
|
+
/**
|
|
10
|
+
* Adds an item to the Set.
|
|
11
|
+
* @param item - The item to add to the Set.
|
|
12
|
+
* @returns The Set.
|
|
13
|
+
*/
|
|
14
|
+
add(item: T): Set<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Removes an item from the Set.
|
|
17
|
+
* @param item - The item to remove from the Set.
|
|
18
|
+
* @returns `true` if the item was removed, `false` otherwise.
|
|
19
|
+
*/
|
|
20
|
+
delete(item: T): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Returns a new Set with the items that are in the current Set but not in the given iterable.
|
|
23
|
+
* @param items - The items to remove from the Set.
|
|
24
|
+
* @returns A new Set with the items that are in the current Set but not in the given iterable.
|
|
25
|
+
*/
|
|
26
|
+
difference(items: Iterable<T>): Set<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the Set value
|
|
29
|
+
* @returns The Set.
|
|
30
|
+
*/
|
|
31
|
+
valueOf(): Set<T>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Creates a signal that represents a set. Adding and removing items from the set will
|
|
36
|
+
* push a new value through the stream.
|
|
37
|
+
* @param initial - The initial value of the set.
|
|
38
|
+
* @returns A signal that represents a set.
|
|
39
|
+
*/
|
|
40
|
+
export function createSetSignal<T>(
|
|
41
|
+
initial: Array<T> = [],
|
|
42
|
+
): Operation<SetSignal<T>> {
|
|
43
|
+
return resource(function* (provide) {
|
|
44
|
+
const signal = createSignal<Set<T>, void>();
|
|
45
|
+
|
|
46
|
+
const ref = { current: Set.of<T>(...initial) };
|
|
47
|
+
|
|
48
|
+
function set(value: Iterable<T>) {
|
|
49
|
+
if (is(ref.current, value)) {
|
|
50
|
+
return ref.current;
|
|
51
|
+
}
|
|
52
|
+
ref.current = Set.of<T>(...value);
|
|
53
|
+
signal.send(ref.current);
|
|
54
|
+
return ref.current;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
yield* provide({
|
|
59
|
+
[Symbol.iterator]: signal[Symbol.iterator],
|
|
60
|
+
set,
|
|
61
|
+
update(updater) {
|
|
62
|
+
return set(updater(ref.current));
|
|
63
|
+
},
|
|
64
|
+
add(item) {
|
|
65
|
+
ref.current = ref.current.add(item);
|
|
66
|
+
signal.send(ref.current);
|
|
67
|
+
return ref.current;
|
|
68
|
+
},
|
|
69
|
+
difference(items) {
|
|
70
|
+
ref.current = ref.current.subtract(items);
|
|
71
|
+
signal.send(ref.current);
|
|
72
|
+
return ref.current;
|
|
73
|
+
},
|
|
74
|
+
delete(item) {
|
|
75
|
+
if (ref.current.has(item)) {
|
|
76
|
+
ref.current = ref.current.delete(item);
|
|
77
|
+
signal.send(ref.current);
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
},
|
|
82
|
+
valueOf() {
|
|
83
|
+
return ref.current.toSet();
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
} finally {
|
|
87
|
+
signal.close();
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
package/tsconfig.json
ADDED
package/types.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Stream } from "effection";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A signal is a stream with set, update, and valueOf methods.
|
|
5
|
+
* Subscribing to a signal will yield the current value of the signal.
|
|
6
|
+
*/
|
|
7
|
+
export interface ValueSignal<T> extends Stream<T, void> {
|
|
8
|
+
/**
|
|
9
|
+
* Set the value of the signal.
|
|
10
|
+
* @param value - The value to set the signal to.
|
|
11
|
+
* @returns The value of the signal.
|
|
12
|
+
*/
|
|
13
|
+
set(value: T): T;
|
|
14
|
+
/**
|
|
15
|
+
* Update the value of the signal.
|
|
16
|
+
* @param updater - The updater function.
|
|
17
|
+
* @returns The value of the signal.
|
|
18
|
+
*/
|
|
19
|
+
update(updater: (value: T) => T): T;
|
|
20
|
+
/**
|
|
21
|
+
* Get the current value of the signal.
|
|
22
|
+
* @returns The current value of the signal.
|
|
23
|
+
*/
|
|
24
|
+
valueOf(): Readonly<T>;
|
|
25
|
+
}
|
package/esm/array.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../src/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,SAAS,EAAY,MAAM,WAAW,CAAC;AAInE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,CAAE,SAAQ,WAAW,CAAC,CAAC,EAAE,CAAC;IACtD;;;;;OAKG;IACH,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,KAAK,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;IACtB;;;;OAIG;IACH,OAAO,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;IACzB;;;;OAIG;IACH,IAAI,MAAM,IAAI,MAAM,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,GACnB,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAiD3B"}
|
package/esm/boolean.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type Operation } from "effection";
|
|
2
|
-
import type { ValueSignal } from "./types.js";
|
|
3
|
-
export interface BooleanSignal extends ValueSignal<boolean> {
|
|
4
|
-
}
|
|
5
|
-
export declare function createBooleanSignal(initial?: boolean): Operation<BooleanSignal>;
|
|
6
|
-
//# sourceMappingURL=boolean.d.ts.map
|
package/esm/boolean.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../src/boolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,SAAS,EAAY,MAAM,WAAW,CAAC;AAEnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,aAAc,SAAQ,WAAW,CAAC,OAAO,CAAC;CAAG;AAE9D,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,OAAe,GACvB,SAAS,CAAC,aAAa,CAAC,CA+B1B"}
|
package/esm/helpers.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;GAKG;AACH,wBAAiB,EAAE,CAAC,CAAC,EACnB,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,GAC9B,SAAS,CAAC,IAAI,CAAC,CAYjB"}
|
package/esm/mod.d.ts
DELETED
package/esm/mod.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
package/esm/package.json
DELETED
package/esm/set.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { type Operation } from "effection";
|
|
2
|
-
import type { ValueSignal } from "./types.js";
|
|
3
|
-
import { Set } from "immutable";
|
|
4
|
-
/**
|
|
5
|
-
* A signal that represents a Set.
|
|
6
|
-
*/
|
|
7
|
-
export interface SetSignal<T> extends ValueSignal<Set<T>> {
|
|
8
|
-
/**
|
|
9
|
-
* Adds an item to the Set.
|
|
10
|
-
* @param item - The item to add to the Set.
|
|
11
|
-
* @returns The Set.
|
|
12
|
-
*/
|
|
13
|
-
add(item: T): Set<T>;
|
|
14
|
-
/**
|
|
15
|
-
* Removes an item from the Set.
|
|
16
|
-
* @param item - The item to remove from the Set.
|
|
17
|
-
* @returns `true` if the item was removed, `false` otherwise.
|
|
18
|
-
*/
|
|
19
|
-
delete(item: T): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Returns a new Set with the items that are in the current Set but not in the given iterable.
|
|
22
|
-
* @param items - The items to remove from the Set.
|
|
23
|
-
* @returns A new Set with the items that are in the current Set but not in the given iterable.
|
|
24
|
-
*/
|
|
25
|
-
difference(items: Iterable<T>): Set<T>;
|
|
26
|
-
/**
|
|
27
|
-
* Returns the Set value
|
|
28
|
-
* @returns The Set.
|
|
29
|
-
*/
|
|
30
|
-
valueOf(): Set<T>;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Creates a signal that represents a set. Adding and removing items from the set will
|
|
34
|
-
* push a new value through the stream.
|
|
35
|
-
* @param initial - The initial value of the set.
|
|
36
|
-
* @returns A signal that represents a set.
|
|
37
|
-
*/
|
|
38
|
-
export declare function createSetSignal<T>(initial?: Array<T>): Operation<SetSignal<T>>;
|
|
39
|
-
//# sourceMappingURL=set.d.ts.map
|
package/esm/set.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../src/set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,SAAS,EAAY,MAAM,WAAW,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAM,GAAG,EAAE,MAAM,WAAW,CAAC;AAEpC;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,CAAE,SAAQ,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvD;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IACrB;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC;IACzB;;;;OAIG;IACH,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IACvC;;;OAGG;IACH,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,OAAO,GAAE,KAAK,CAAC,CAAC,CAAM,GACrB,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAgDzB"}
|
package/esm/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC;;;GAGG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,CAAE,SAAQ,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC;IACrD;;;;OAIG;IACH,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;IACjB;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpC;;;OAGG;IACH,OAAO,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC;CACxB"}
|
package/script/array.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { type Operation } from "effection";
|
|
2
|
-
import type { ValueSignal } from "./types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Interface for return value of {@link createArraySignal}.
|
|
5
|
-
*/
|
|
6
|
-
export interface ArraySignal<T> extends ValueSignal<T[]> {
|
|
7
|
-
/**
|
|
8
|
-
* Pushes a new value onto the end of the array.
|
|
9
|
-
*
|
|
10
|
-
* @param item - The value to push onto the array.
|
|
11
|
-
* @returns The new length of the array.
|
|
12
|
-
*/
|
|
13
|
-
push(...args: T[]): number;
|
|
14
|
-
/**
|
|
15
|
-
* Removes the first value from the array and returns it.
|
|
16
|
-
* If the array is empty, the operation will block until a value is available.
|
|
17
|
-
*
|
|
18
|
-
* @returns The first value from the array.
|
|
19
|
-
*/
|
|
20
|
-
shift(): Operation<T>;
|
|
21
|
-
/**
|
|
22
|
-
* Returns the current value of the array.
|
|
23
|
-
*
|
|
24
|
-
* @returns The current value of the array.
|
|
25
|
-
*/
|
|
26
|
-
valueOf(): Readonly<T[]>;
|
|
27
|
-
/**
|
|
28
|
-
* Returns the length of the array.
|
|
29
|
-
*
|
|
30
|
-
* @returns The length of the array.
|
|
31
|
-
*/
|
|
32
|
-
get length(): number;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* A signal for an immutable array value. The stream emits the
|
|
36
|
-
* current value of the array and new values when the array is updated. The array
|
|
37
|
-
* is immutable and cannot be changed. Instead, the value is replaced with a new
|
|
38
|
-
* value.
|
|
39
|
-
*
|
|
40
|
-
* @param initial - The initial value of the signal.
|
|
41
|
-
* @returns A stream of immutable array values.
|
|
42
|
-
*/
|
|
43
|
-
export declare function createArraySignal<T>(initial: Iterable<T>): Operation<ArraySignal<T>>;
|
|
44
|
-
//# sourceMappingURL=array.d.ts.map
|
package/script/array.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../src/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,SAAS,EAAY,MAAM,WAAW,CAAC;AAInE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,CAAE,SAAQ,WAAW,CAAC,CAAC,EAAE,CAAC;IACtD;;;;;OAKG;IACH,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,KAAK,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;IACtB;;;;OAIG;IACH,OAAO,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;IACzB;;;;OAIG;IACH,IAAI,MAAM,IAAI,MAAM,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,GACnB,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAiD3B"}
|
package/script/array.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createArraySignal = createArraySignal;
|
|
4
|
-
const effection_1 = require("effection");
|
|
5
|
-
const immutable_1 = require("immutable");
|
|
6
|
-
const helpers_js_1 = require("./helpers.js");
|
|
7
|
-
/**
|
|
8
|
-
* A signal for an immutable array value. The stream emits the
|
|
9
|
-
* current value of the array and new values when the array is updated. The array
|
|
10
|
-
* is immutable and cannot be changed. Instead, the value is replaced with a new
|
|
11
|
-
* value.
|
|
12
|
-
*
|
|
13
|
-
* @param initial - The initial value of the signal.
|
|
14
|
-
* @returns A stream of immutable array values.
|
|
15
|
-
*/
|
|
16
|
-
function createArraySignal(initial) {
|
|
17
|
-
return (0, effection_1.resource)(function* (provide) {
|
|
18
|
-
const signal = (0, effection_1.createSignal)();
|
|
19
|
-
const ref = {
|
|
20
|
-
current: immutable_1.List.of(...initial),
|
|
21
|
-
};
|
|
22
|
-
function set(value) {
|
|
23
|
-
if (ref.current.equals(immutable_1.List.of(...value))) {
|
|
24
|
-
return ref.current.toArray();
|
|
25
|
-
}
|
|
26
|
-
ref.current = immutable_1.List.of(...value);
|
|
27
|
-
signal.send(ref.current.toArray());
|
|
28
|
-
return ref.current.toArray();
|
|
29
|
-
}
|
|
30
|
-
const array = {
|
|
31
|
-
[Symbol.iterator]: signal[Symbol.iterator],
|
|
32
|
-
set,
|
|
33
|
-
update(updater) {
|
|
34
|
-
return set(updater(ref.current.toArray()));
|
|
35
|
-
},
|
|
36
|
-
push(...args) {
|
|
37
|
-
ref.current = ref.current.push(...args);
|
|
38
|
-
signal.send(ref.current.toArray());
|
|
39
|
-
return ref.current.size;
|
|
40
|
-
},
|
|
41
|
-
*shift() {
|
|
42
|
-
yield* (0, helpers_js_1.is)(array, (array) => array.length > 0);
|
|
43
|
-
let value = ref.current.first();
|
|
44
|
-
ref.current = ref.current.shift();
|
|
45
|
-
signal.send(ref.current.toArray());
|
|
46
|
-
return value;
|
|
47
|
-
},
|
|
48
|
-
valueOf() {
|
|
49
|
-
return ref.current.toArray();
|
|
50
|
-
},
|
|
51
|
-
get length() {
|
|
52
|
-
return ref.current.size;
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
try {
|
|
56
|
-
yield* provide(array);
|
|
57
|
-
}
|
|
58
|
-
finally {
|
|
59
|
-
signal.close();
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
package/script/boolean.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../src/boolean.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,SAAS,EAAY,MAAM,WAAW,CAAC;AAEnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,WAAW,aAAc,SAAQ,WAAW,CAAC,OAAO,CAAC;CAAG;AAE9D,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,OAAe,GACvB,SAAS,CAAC,aAAa,CAAC,CA+B1B"}
|
package/script/boolean.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createBooleanSignal = createBooleanSignal;
|
|
4
|
-
const effection_1 = require("effection");
|
|
5
|
-
function createBooleanSignal(initial = false) {
|
|
6
|
-
return (0, effection_1.resource)(function* (provide) {
|
|
7
|
-
const signal = (0, effection_1.createSignal)();
|
|
8
|
-
const ref = { current: initial };
|
|
9
|
-
function set(value) {
|
|
10
|
-
if (value !== ref.current) {
|
|
11
|
-
ref.current = value;
|
|
12
|
-
signal.send(ref.current);
|
|
13
|
-
}
|
|
14
|
-
return ref.current;
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
yield* provide({
|
|
18
|
-
[Symbol.iterator]: signal[Symbol.iterator],
|
|
19
|
-
set,
|
|
20
|
-
update(updater) {
|
|
21
|
-
return set(updater(ref.current));
|
|
22
|
-
},
|
|
23
|
-
valueOf() {
|
|
24
|
-
return ref.current;
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
finally {
|
|
29
|
-
signal.close();
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
package/script/helpers.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type Operation } from "effection";
|
|
2
|
-
import type { ValueSignal } from "./types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Returns an operation that will wait until the value of the stream matches the predicate.
|
|
5
|
-
* @param stream - The stream to check.
|
|
6
|
-
* @param predicate - The predicate to check the value against.
|
|
7
|
-
* @returns An operation that will wait until the value of the stream matches the predicate.
|
|
8
|
-
*/
|
|
9
|
-
export declare function is<T>(stream: ValueSignal<T>, predicate: (item: T) => boolean): Operation<void>;
|
|
10
|
-
//# sourceMappingURL=helpers.d.ts.map
|
package/script/helpers.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;GAKG;AACH,wBAAiB,EAAE,CAAC,CAAC,EACnB,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,GAC9B,SAAS,CAAC,IAAI,CAAC,CAYjB"}
|
package/script/helpers.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.is = is;
|
|
4
|
-
const effection_1 = require("effection");
|
|
5
|
-
/**
|
|
6
|
-
* Returns an operation that will wait until the value of the stream matches the predicate.
|
|
7
|
-
* @param stream - The stream to check.
|
|
8
|
-
* @param predicate - The predicate to check the value against.
|
|
9
|
-
* @returns An operation that will wait until the value of the stream matches the predicate.
|
|
10
|
-
*/
|
|
11
|
-
function* is(stream, predicate) {
|
|
12
|
-
const result = predicate(stream.valueOf());
|
|
13
|
-
if (result) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
for (const value of yield* (0, effection_1.each)(stream)) {
|
|
17
|
-
const result = predicate(value);
|
|
18
|
-
if (result) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
yield* effection_1.each.next();
|
|
22
|
-
}
|
|
23
|
-
}
|
package/script/mod.d.ts
DELETED
package/script/mod.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
|
package/script/mod.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./boolean.js"), exports);
|
|
18
|
-
__exportStar(require("./array.js"), exports);
|
|
19
|
-
__exportStar(require("./set.js"), exports);
|
|
20
|
-
__exportStar(require("./helpers.js"), exports);
|
|
21
|
-
__exportStar(require("./types.js"), exports);
|
package/script/package.json
DELETED
package/script/set.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../src/set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,SAAS,EAAY,MAAM,WAAW,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAM,GAAG,EAAE,MAAM,WAAW,CAAC;AAEpC;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,CAAE,SAAQ,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACvD;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IACrB;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC;IACzB;;;;OAIG;IACH,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IACvC;;;OAGG;IACH,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,OAAO,GAAE,KAAK,CAAC,CAAC,CAAM,GACrB,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAgDzB"}
|
package/script/set.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSetSignal = createSetSignal;
|
|
4
|
-
const effection_1 = require("effection");
|
|
5
|
-
const immutable_1 = require("immutable");
|
|
6
|
-
/**
|
|
7
|
-
* Creates a signal that represents a set. Adding and removing items from the set will
|
|
8
|
-
* push a new value through the stream.
|
|
9
|
-
* @param initial - The initial value of the set.
|
|
10
|
-
* @returns A signal that represents a set.
|
|
11
|
-
*/
|
|
12
|
-
function createSetSignal(initial = []) {
|
|
13
|
-
return (0, effection_1.resource)(function* (provide) {
|
|
14
|
-
const signal = (0, effection_1.createSignal)();
|
|
15
|
-
const ref = { current: immutable_1.Set.of(...initial) };
|
|
16
|
-
function set(value) {
|
|
17
|
-
if ((0, immutable_1.is)(ref.current, value)) {
|
|
18
|
-
return ref.current;
|
|
19
|
-
}
|
|
20
|
-
ref.current = immutable_1.Set.of(...value);
|
|
21
|
-
signal.send(ref.current);
|
|
22
|
-
return ref.current;
|
|
23
|
-
}
|
|
24
|
-
try {
|
|
25
|
-
yield* provide({
|
|
26
|
-
[Symbol.iterator]: signal[Symbol.iterator],
|
|
27
|
-
set,
|
|
28
|
-
update(updater) {
|
|
29
|
-
return set(updater(ref.current));
|
|
30
|
-
},
|
|
31
|
-
add(item) {
|
|
32
|
-
ref.current = ref.current.add(item);
|
|
33
|
-
signal.send(ref.current);
|
|
34
|
-
return ref.current;
|
|
35
|
-
},
|
|
36
|
-
difference(items) {
|
|
37
|
-
ref.current = ref.current.subtract(items);
|
|
38
|
-
signal.send(ref.current);
|
|
39
|
-
return ref.current;
|
|
40
|
-
},
|
|
41
|
-
delete(item) {
|
|
42
|
-
if (ref.current.has(item)) {
|
|
43
|
-
ref.current = ref.current.delete(item);
|
|
44
|
-
signal.send(ref.current);
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
return false;
|
|
48
|
-
},
|
|
49
|
-
valueOf() {
|
|
50
|
-
return ref.current.toSet();
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
finally {
|
|
55
|
-
signal.close();
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
package/script/types.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { Stream } from "effection";
|
|
2
|
-
/**
|
|
3
|
-
* A signal is a stream with set, update, and valueOf methods.
|
|
4
|
-
* Subscribing to a signal will yield the current value of the signal.
|
|
5
|
-
*/
|
|
6
|
-
export interface ValueSignal<T> extends Stream<T, void> {
|
|
7
|
-
/**
|
|
8
|
-
* Set the value of the signal.
|
|
9
|
-
* @param value - The value to set the signal to.
|
|
10
|
-
* @returns The value of the signal.
|
|
11
|
-
*/
|
|
12
|
-
set(value: T): T;
|
|
13
|
-
/**
|
|
14
|
-
* Update the value of the signal.
|
|
15
|
-
* @param updater - The updater function.
|
|
16
|
-
* @returns The value of the signal.
|
|
17
|
-
*/
|
|
18
|
-
update(updater: (value: T) => T): T;
|
|
19
|
-
/**
|
|
20
|
-
* Get the current value of the signal.
|
|
21
|
-
* @returns The current value of the signal.
|
|
22
|
-
*/
|
|
23
|
-
valueOf(): Readonly<T>;
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=types.d.ts.map
|
package/script/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC;;;GAGG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,CAAE,SAAQ,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC;IACrD;;;;OAIG;IACH,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;IACjB;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpC;;;OAGG;IACH,OAAO,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC;CACxB"}
|