@soffinal/stream 0.2.4 → 0.3.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.
Files changed (56) hide show
  1. package/README.md +135 -637
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +2 -2
  5. package/dist/index.js.map +10 -12
  6. package/dist/stream.d.ts +25 -6
  7. package/dist/stream.d.ts.map +1 -1
  8. package/dist/transformers/filter/filter.d.ts +18 -0
  9. package/dist/transformers/filter/filter.d.ts.map +1 -0
  10. package/dist/transformers/filter/index.d.ts +2 -0
  11. package/dist/transformers/filter/index.d.ts.map +1 -0
  12. package/dist/transformers/flat/flat.d.ts +3 -0
  13. package/dist/transformers/flat/flat.d.ts.map +1 -0
  14. package/dist/transformers/flat/index.d.ts +2 -0
  15. package/dist/transformers/flat/index.d.ts.map +1 -0
  16. package/dist/transformers/gate/gate.d.ts +43 -0
  17. package/dist/transformers/gate/gate.d.ts.map +1 -0
  18. package/dist/transformers/gate/index.d.ts +2 -0
  19. package/dist/transformers/gate/index.d.ts.map +1 -0
  20. package/dist/transformers/index.d.ts +6 -4
  21. package/dist/transformers/index.d.ts.map +1 -1
  22. package/dist/transformers/map/index.d.ts +2 -0
  23. package/dist/transformers/map/index.d.ts.map +1 -0
  24. package/dist/transformers/map/map.d.ts +14 -0
  25. package/dist/transformers/map/map.d.ts.map +1 -0
  26. package/dist/transformers/merge/index.d.ts +2 -0
  27. package/dist/transformers/merge/index.d.ts.map +1 -0
  28. package/dist/transformers/merge/merge.d.ts +3 -0
  29. package/dist/transformers/merge/merge.d.ts.map +1 -0
  30. package/dist/transformers/state/index.d.ts +2 -0
  31. package/dist/transformers/state/index.d.ts.map +1 -0
  32. package/dist/transformers/state/state.d.ts +35 -0
  33. package/dist/transformers/state/state.d.ts.map +1 -0
  34. package/package.json +15 -17
  35. package/dist/reactive/index.d.ts +0 -5
  36. package/dist/reactive/index.d.ts.map +0 -1
  37. package/dist/reactive/list.d.ts +0 -171
  38. package/dist/reactive/list.d.ts.map +0 -1
  39. package/dist/reactive/map.d.ts +0 -107
  40. package/dist/reactive/map.d.ts.map +0 -1
  41. package/dist/reactive/set.d.ts +0 -102
  42. package/dist/reactive/set.d.ts.map +0 -1
  43. package/dist/reactive/state.d.ts +0 -79
  44. package/dist/reactive/state.d.ts.map +0 -1
  45. package/dist/transformers/filter.d.ts +0 -96
  46. package/dist/transformers/filter.d.ts.map +0 -1
  47. package/dist/transformers/flat.d.ts +0 -31
  48. package/dist/transformers/flat.d.ts.map +0 -1
  49. package/dist/transformers/map.d.ts +0 -106
  50. package/dist/transformers/map.d.ts.map +0 -1
  51. package/dist/transformers/merge.d.ts +0 -33
  52. package/dist/transformers/merge.d.ts.map +0 -1
  53. package/src/transformers/filter.md +0 -326
  54. package/src/transformers/flat.md +0 -56
  55. package/src/transformers/map.md +0 -430
  56. package/src/transformers/merge.md +0 -79
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../../src/transformers/merge/merge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EAC1E,GAAG,OAAO,EAAE,OAAO,GAClB,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CA0BpF"}
@@ -0,0 +1,2 @@
1
+ export * from "./state";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transformers/state/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { Stream } from "../../stream";
2
+ /**
3
+ * Stream with reactive state management via getter/setter.
4
+ *
5
+ * @template T - The type of values in the stream
6
+ */
7
+ export type State<T> = Stream<T> & {
8
+ state: {
9
+ value: T;
10
+ };
11
+ };
12
+ /**
13
+ * Adds `.state.value` getter/setter to a stream for reactive state management.
14
+ *
15
+ * @template T - The type of values in the stream
16
+ * @param initialValue - Initial state value
17
+ * @returns Transformer that adds state behavior
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const counter = new Stream<number>().pipe(state(0));
22
+ * counter.listen(n => console.log(n));
23
+ * counter.state.value = 5; // Triggers listener
24
+ * console.log(counter.state.value); // 5
25
+ * ```
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const source = new Stream<number>();
30
+ * const stateful = source.pipe(state(0));
31
+ * source.push(10); // Updates stateful.state.value to 10
32
+ * ```
33
+ */
34
+ export declare function state<T>(initialValue: T): Stream.Transformer<Stream<T>, Stream<T>>;
35
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/transformers/state/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;;;;GAIG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG;IACjC,KAAK,EAAE;QACL,KAAK,EAAE,CAAC,CAAC;KACV,CAAC;CACH,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CA0BlF"}
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@soffinal/stream",
3
+ "version": "0.3.0",
4
+ "author": "Soffinal <smari.sofiane@gmail.com>",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/soffinal/stream.git"
8
+ },
9
+ "main": "./dist/index.js",
3
10
  "module": "./dist/index.js",
4
- "version": "0.2.4",
5
- "description": "Type-safe event emitters that scale",
6
- "type": "module",
7
11
  "devDependencies": {
8
12
  "@types/bun": "latest"
9
13
  },
@@ -16,6 +20,12 @@
16
20
  "types": "./dist/index.d.ts"
17
21
  }
18
22
  },
23
+ "description": "Composable reactive primitives for TypeScript",
24
+ "files": [
25
+ "dist",
26
+ "src/transformers/*.md",
27
+ "README.md"
28
+ ],
19
29
  "keywords": [
20
30
  "reactive",
21
31
  "streams",
@@ -26,19 +36,7 @@
26
36
  "emitter",
27
37
  "adaptive constraints"
28
38
  ],
29
- "author": "Soffinal <smari.sofiane@gmail.com>",
30
39
  "license": "MIT",
31
- "repository": {
32
- "type": "git",
33
- "url": "git+https://github.com/soffinal/stream.git"
34
- },
35
- "main": "./dist/index.js",
36
- "types": "./dist/index.d.ts",
37
- "files": [
38
- "dist",
39
- "src/transformers/*.md",
40
- "README.md",
41
- "CHANGELOG.md",
42
- "LICENSE"
43
- ]
40
+ "type": "module",
41
+ "types": "./dist/index.d.ts"
44
42
  }
@@ -1,5 +0,0 @@
1
- export * from "./list.ts";
2
- export * from "./map.ts";
3
- export * from "./set.ts";
4
- export * from "./state.ts";
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/reactive/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
@@ -1,171 +0,0 @@
1
- import { Stream } from "../stream.ts";
2
- /**
3
- * A reactive List that provides array-like functionality with stream-based mutation events.
4
- * Emits events when items are inserted, deleted, or the list is cleared.
5
- * Supports negative indexing with modulo wrapping.
6
- * @template VALUE - The type of values stored in the list
7
- *
8
- * @see {@link Stream} - Complete copy-paste transformers library
9
- *
10
- * @example
11
- * ```typescript
12
- * const todos = new List<string>();
13
- *
14
- * // Listen to insertions
15
- * todos.insert.listen(([index, item]) => {
16
- * console.log(`Added "${item}" at index ${index}`);
17
- * });
18
- *
19
- * // Listen to deletions
20
- * todos.delete.listen(([index, item]) => {
21
- * console.log(`Removed "${item}" from index ${index}`);
22
- * });
23
- *
24
- * todos.insert(0, "Buy milk"); //Added "Buy milk" at index 0
25
- * todos.insert(1, "Walk dog"); //Added "Walk dog" at index 1
26
- * todos.insert(-1, "kechma haja"); //Added "kechma haja" at index 2
27
- * todos[0] = "Buy organic milk"; // Added "Buy organic milk" at index 0
28
- * ```
29
- */
30
- export declare class List<VALUE> implements Iterable<VALUE> {
31
- private _items;
32
- private _insertStream?;
33
- private _deleteStream?;
34
- private _clearStream?;
35
- [index: number]: VALUE | undefined;
36
- /**
37
- * Inserts a value at the specified index and emits the insertion event.
38
- * Negative indices are handled specially for insertion positioning.
39
- *
40
- * @see {@link Stream} - Complete copy-paste transformers library
41
- *
42
- * @example
43
- * ```typescript
44
- * const list = new List([1, 2, 3]);
45
- * list.insert.listen(([index, value]) => console.log(`Inserted ${value} at ${index}`));
46
- *
47
- * list.insert(1, 99); // Inserted 99 at 1 → [1, 99, 2, 3]
48
- * list.insert(-1, 88); // Insert at end → [1, 99, 2, 3, 88]
49
- * ```
50
- */
51
- insert: ((index: number, value: VALUE) => this) & Stream<[number, VALUE]>;
52
- /**
53
- * Deletes a value at the specified index and emits the deletion event.
54
- * Returns the deleted value or undefined if index is invalid.
55
- *
56
- * @see {@link Stream} - Complete copy-paste transformers library
57
- *
58
- * @example
59
- * ```typescript
60
- * const list = new List(['a', 'b', 'c']);
61
- * list.delete.listen(([index, value]) => console.log(`Deleted ${value} from ${index}`));
62
- *
63
- * const deleted = list.delete(1); // Deleted b from 1
64
- * console.log(deleted); // 'b'
65
- * ```
66
- */
67
- delete: ((index: number) => VALUE | undefined) & Stream<[number, VALUE]>;
68
- /**
69
- * Clears all items from the list and emits the clear event.
70
- * Only emits if the list was not already empty.
71
- *
72
- * @see {@link Stream} - Complete copy-paste transformers library
73
- *
74
- * @example
75
- * ```typescript
76
- * const list = new List([1, 2, 3]);
77
- * list.clear.listen(() => console.log('List cleared'));
78
- *
79
- * list.clear(); // List cleared
80
- * list.clear(); // No emission (already empty)
81
- * ```
82
- */
83
- clear: (() => void) & Stream<void>;
84
- /**
85
- * Creates a new reactive List.
86
- *
87
- * @param items - Optional iterable of initial items
88
- *
89
- * @see {@link Stream} - Complete copy-paste transformers library
90
- *
91
- * @example
92
- * ```typescript
93
- * // Empty list
94
- * const list = new List<number>();
95
- *
96
- * // With initial items
97
- * const todos = new List(['Buy milk', 'Walk dog']);
98
- *
99
- * // Listen to changes
100
- * todos.insert.listen(([index, item]) => updateUI(index, item));
101
- * todos.delete.listen(([index, item]) => removeFromUI(index));
102
- *
103
- * // Index access with modulo wrapping
104
- * console.log(todos[0]); // 'Buy milk'
105
- * console.log(todos[-1]); // 'Walk dog' (last item)
106
- * ```
107
- */
108
- constructor(items?: Iterable<VALUE>);
109
- /**
110
- * Gets the value at the specified index without modulo wrapping.
111
- *
112
- * @param index - The index to access
113
- * @returns The value at the index or undefined
114
- *
115
- * @see {@link Stream} - Complete copy-paste transformers library
116
- *
117
- * @example
118
- * ```typescript
119
- * const list = new List([10, 20, 30]);
120
- * console.log(list.get(1)); // 20
121
- * console.log(list.get(5)); // undefined
122
- * ```
123
- */
124
- get(index: number): VALUE | undefined;
125
- /**
126
- * Gets the current length of the list.
127
- *
128
- * @see {@link Stream} - Complete copy-paste transformers library
129
- *
130
- * @example
131
- * ```typescript
132
- * const list = new List([1, 2, 3]);
133
- * console.log(list.length); // 3
134
- *
135
- * list.insert(0, 0);
136
- * console.log(list.length); // 4
137
- * ```
138
- */
139
- get length(): number;
140
- /**
141
- * Returns an iterator for the list values.
142
- *
143
- * @see {@link Stream} - Complete copy-paste transformers library
144
- *
145
- * @example
146
- * ```typescript
147
- * const list = new List([1, 2, 3]);
148
- * for (const value of list.values()) {
149
- * console.log(value); // 1, 2, 3
150
- * }
151
- * ```
152
- */
153
- values(): IterableIterator<VALUE>;
154
- /**
155
- * Makes the list iterable.
156
- *
157
- * @see {@link Stream} - Complete copy-paste transformers library
158
- *
159
- * @example
160
- * ```typescript
161
- * const list = new List(['a', 'b', 'c']);
162
- * for (const item of list) {
163
- * console.log(item); // 'a', 'b', 'c'
164
- * }
165
- *
166
- * const array = [...list]; // ['a', 'b', 'c']
167
- * ```
168
- */
169
- [Symbol.iterator](): IterableIterator<VALUE>;
170
- }
171
- //# sourceMappingURL=list.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/reactive/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,IAAI,CAAC,KAAK,CAAE,YAAW,QAAQ,CAAC,KAAK,CAAC;IACjD,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,aAAa,CAAC,CAA0B;IAChD,OAAO,CAAC,aAAa,CAAC,CAA0B;IAChD,OAAO,CAAC,YAAY,CAAC,CAAe;IAEpC,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAAC;IAEnC;;;;;;;;;;;;;;OAcG;IACK,MAAM,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IAElF;;;;;;;;;;;;;;OAcG;IACK,MAAM,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,KAAK,GAAG,SAAS,CAAC,GAAG,MAAM,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IAEjF;;;;;;;;;;;;;;OAcG;IACK,KAAK,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAE3C;;;;;;;;;;;;;;;;;;;;;;;OAuBG;gBACS,KAAK,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC;IAiGnC;;;;;;;;;;;;;;OAcG;IACH,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS;IAIrC;;;;;;;;;;;;;OAaG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IACD;;;;;;;;;;;;OAYG;IACH,MAAM,IAAI,gBAAgB,CAAC,KAAK,CAAC;IAGjC;;;;;;;;;;;;;;OAcG;IACH,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,KAAK,CAAC;CAG7C"}
@@ -1,107 +0,0 @@
1
- import { Stream } from "../stream.ts";
2
- /**
3
- * A reactive Map that extends the native Map with stream-based mutation events.
4
- * Emits events when entries are set, deleted, or the map is cleared.
5
- *
6
- * @template KEY - The type of keys in the map
7
- * @template VALUE - The type of values in the map
8
- *
9
- * @see {@link Stream} - Complete copy-paste transformers library
10
- *
11
- * @example
12
- * ```typescript
13
- * const cache = new Map<string, any>();
14
- *
15
- * // Listen to cache updates
16
- * cache.set.listen(([key, value]) => {
17
- * console.log(`Cache updated: ${key} = ${value}`);
18
- * });
19
- *
20
- * // Listen to cache evictions
21
- * cache.delete.listen(([key, value]) => {
22
- * console.log(`Cache evicted: ${key}`);
23
- * });
24
- *
25
- * cache.set('user:123', { name: 'John' });
26
- * cache.delete('user:123');
27
- * ```
28
- */
29
- export declare class Map<KEY, VALUE> extends globalThis.Map<KEY, VALUE> {
30
- protected _setStream?: Stream<[KEY, VALUE]>;
31
- protected _deleteStream?: Stream<[KEY, VALUE]>;
32
- protected _clearStream?: Stream<void>;
33
- /**
34
- * Sets a key-value pair in the map and emits the entry to listeners.
35
- * Only emits if the value actually changes (not same key-value pair).
36
- *
37
- * @see {@link Stream} - Complete copy-paste transformers library
38
- *
39
- * @example
40
- * ```typescript
41
- * const config = new Map<string, string>();
42
- * config.set.listen(([key, value]) => console.log(`Set: ${key}=${value}`));
43
- *
44
- * config.set('theme', 'dark'); // Set: theme=dark
45
- * config.set('theme', 'dark'); // No emission (same value)
46
- * config.set('theme', 'light'); // Set: theme=light
47
- * ```
48
- */
49
- set: ((key: KEY, value: VALUE) => this) & Stream<[KEY, VALUE]>;
50
- /**
51
- * Deletes a key from the map and emits the deleted entry to listeners.
52
- * Only emits if the key was actually deleted (existed in map).
53
- *
54
- * @see {@link Stream} - Complete copy-paste transformers library
55
- *
56
- * @example
57
- * ```typescript
58
- * const users = new Map([['alice', { age: 30 }], ['bob', { age: 25 }]]);
59
- * users.delete.listen(([key, value]) => console.log(`Removed: ${key}`));
60
- *
61
- * users.delete('alice'); // Removed: alice
62
- * users.delete('charlie'); // No emission (didn't exist)
63
- * ```
64
- */
65
- delete: ((key: KEY) => boolean) & Stream<[KEY, VALUE]>;
66
- /**
67
- * Clears all entries from the map and emits to listeners.
68
- * Only emits if the map was not already empty.
69
- *
70
- * @see {@link Stream} - Complete copy-paste transformers library
71
- *
72
- * @example
73
- * ```typescript
74
- * const store = new Map([['a', 1], ['b', 2]]);
75
- * store.clear.listen(() => console.log('Store cleared'));
76
- *
77
- * store.clear(); // Store cleared
78
- * store.clear(); // No emission (already empty)
79
- * ```
80
- */
81
- clear: (() => void) & Stream<void>;
82
- /**
83
- * Creates a new reactive Map.
84
- *
85
- * @param entries - Optional iterable of initial key-value pairs
86
- *
87
- * @see {@link Stream} - Complete copy-paste transformers library
88
- *
89
- * @example
90
- * ```typescript
91
- * // Empty map
92
- * const cache = new Map<string, any>();
93
- *
94
- * // With initial entries
95
- * const config = new Map([
96
- * ['theme', 'dark'],
97
- * ['lang', 'en']
98
- * ]);
99
- *
100
- * // Listen to changes
101
- * config.set.listen(([key, value]) => saveConfig(key, value));
102
- * config.delete.listen(([key]) => removeConfig(key));
103
- * ```
104
- */
105
- constructor(entries?: Iterable<[KEY, VALUE]>);
106
- }
107
- //# sourceMappingURL=map.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"map.d.ts","sourceRoot":"","sources":["../../src/reactive/map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,GAAG,CAAC,GAAG,EAAE,KAAK,CAAE,SAAQ,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC;IAC7D,SAAS,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IAC5C,SAAS,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IAC/C,SAAS,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IAEtC;;;;;;;;;;;;;;;OAeG;IACK,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IAEvE;;;;;;;;;;;;;;OAcG;IACK,MAAM,EAAE,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IAE/D;;;;;;;;;;;;;;OAcG;IACK,KAAK,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAE3C;;;;;;;;;;;;;;;;;;;;;;OAsBG;gBACS,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;CAuD7C"}
@@ -1,102 +0,0 @@
1
- import { Stream } from "../stream.ts";
2
- /**
3
- * A reactive Set that extends the native Set with stream-based mutation events.
4
- * Emits events when items are added, deleted, or the set is cleared.
5
- *
6
- * @template VALUE - The type of values stored in the set
7
- *
8
- * @see {@link Stream} - Complete copy-paste transformers library
9
- *
10
- * @example
11
- * ```typescript
12
- * const activeUsers = new Set<string>();
13
- *
14
- * // Listen to additions
15
- * activeUsers.add.listen(userId => {
16
- * console.log(`User ${userId} came online`);
17
- * });
18
- *
19
- * // Listen to deletions
20
- * activeUsers.delete.listen(userId => {
21
- * console.log(`User ${userId} went offline`);
22
- * });
23
- *
24
- * activeUsers.add('alice'); // User alice came online
25
- * activeUsers.delete('alice'); // User alice went offline
26
- * ```
27
- */
28
- export declare class Set<VALUE> extends globalThis.Set<VALUE> {
29
- protected _addStream?: Stream<VALUE>;
30
- protected _deleteStream?: Stream<VALUE>;
31
- protected _clearStream?: Stream<void>;
32
- /**
33
- * Adds a value to the set and emits the value to listeners.
34
- * Only emits if the value is actually added (not a duplicate).
35
- *
36
- * @see {@link Stream} - Complete copy-paste transformers library
37
- *
38
- * @example
39
- * ```typescript
40
- * const tags = new Set<string>();
41
- * tags.add.listen(tag => console.log('Added:', tag));
42
- *
43
- * tags.add('javascript'); // Added: javascript
44
- * tags.add('javascript'); // No emission (duplicate)
45
- * ```
46
- */
47
- add: ((value: VALUE) => this) & Stream<VALUE>;
48
- /**
49
- * Deletes a value from the set and emits the value to listeners.
50
- * Only emits if the value was actually deleted (existed in set).
51
- *
52
- * @see {@link Stream} - Complete copy-paste transformers library
53
- *
54
- * @example
55
- * ```typescript
56
- * const items = new Set(['a', 'b', 'c']);
57
- * items.delete.listen(item => console.log('Removed:', item));
58
- *
59
- * items.delete('b'); // Removed: b
60
- * items.delete('x'); // No emission (didn't exist)
61
- * ```
62
- */
63
- delete: ((value: VALUE) => boolean) & Stream<VALUE>;
64
- /**
65
- * Clears all values from the set and emits to listeners.
66
- * Only emits if the set was not already empty.
67
- *
68
- * @see {@link Stream} - Complete copy-paste transformers library
69
- *
70
- * @example
71
- * ```typescript
72
- * const cache = new Set([1, 2, 3]);
73
- * cache.clear.listen(() => console.log('Cache cleared'));
74
- *
75
- * cache.clear(); // Cache cleared
76
- * cache.clear(); // No emission (already empty)
77
- * ```
78
- */
79
- clear: (() => void) & Stream<void>;
80
- /**
81
- * Creates a new reactive Set.
82
- *
83
- * @param values - Optional iterable of initial values
84
- *
85
- * @see {@link Stream} - Complete copy-paste transformers library
86
- *
87
- * @example
88
- * ```typescript
89
- * // Empty set
90
- * const tags = new Set<string>();
91
- *
92
- * // With initial values
93
- * const colors = new Set(['red', 'green', 'blue']);
94
- *
95
- * // Listen to changes
96
- * colors.add.listen(color => updateUI(color));
97
- * colors.delete.listen(color => removeFromUI(color));
98
- * ```
99
- */
100
- constructor(values?: Iterable<VALUE>);
101
- }
102
- //# sourceMappingURL=set.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"set.d.ts","sourceRoot":"","sources":["../../src/reactive/set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,GAAG,CAAC,KAAK,CAAE,SAAQ,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC;IACnD,SAAS,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IACrC,SAAS,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IACxC,SAAS,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IAEtC;;;;;;;;;;;;;;OAcG;IACK,GAAG,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAEtD;;;;;;;;;;;;;;OAcG;IACK,MAAM,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAE5D;;;;;;;;;;;;;;OAcG;IACK,KAAK,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAE3C;;;;;;;;;;;;;;;;;;;OAmBG;gBACS,MAAM,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC;CAqDrC"}
@@ -1,79 +0,0 @@
1
- import { Stream } from "../stream.ts";
2
- /**
3
- * A reactive state container that extends Stream to provide stateful value management.
4
- *
5
- * @template VALUE - The type of the state value
6
- *
7
- * @see {@link Stream} - Complete copy-paste transformers library
8
- *
9
- * @example
10
- * ```typescript
11
- * // Basic state
12
- * const counter = new State(0);
13
- * counter.listen(value => console.log('Counter:', value));
14
- * counter.value = 5; // Counter: 5
15
- *
16
- * // State from stream
17
- * const source = new Stream<number>();
18
- * const state = new State(0, source);
19
- * state.listen(value => console.log('State:', value));
20
- * source.push(1, 2, 3); // State: 1, State: 2, State: 3
21
- *
22
- * // State from transformed stream
23
- * const filtered = source.pipe(filter({}, (_, v) => [v > 0, {}]));
24
- * const derivedState = new State(-1, filtered);
25
- * ```
26
- */
27
- export declare class State<VALUE = unknown> extends Stream<VALUE> {
28
- protected _value: VALUE;
29
- constructor(initialValue: VALUE);
30
- constructor(initialValue: VALUE, stream: Stream.FunctionGenerator<VALUE> | Stream<VALUE>);
31
- /**
32
- * Updates the state with one or more values sequentially.
33
- * Each value triggers listeners and updates the current state.
34
- *
35
- * @param values - Values to set as state
36
- *
37
- * @see {@link Stream} - Complete copy-paste transformers library
38
- *
39
- * @example
40
- * ```typescript
41
- * const state = new State(0);
42
- * state.listen(v => console.log(v));
43
- *
44
- * state.push(1, 2, 3); // Logs: 1, 2, 3
45
- * console.log(state.value); // 3
46
- * ```
47
- */
48
- push(...values: VALUE[]): void;
49
- /**
50
- * Gets the current state value.
51
- *
52
- * @see {@link Stream} - Complete copy-paste transformers library
53
- *
54
- * @example
55
- * ```typescript
56
- * const state = new State('hello');
57
- * console.log(state.value); // 'hello'
58
- * ```
59
- */
60
- get value(): VALUE;
61
- /**
62
- * Sets the current state value and notifies all listeners.
63
- *
64
- * @param value - The new state value
65
- *
66
- * @see {@link Stream} - Complete copy-paste transformers library
67
- *
68
- * @example
69
- * ```typescript
70
- * const state = new State(0);
71
- * state.listen(v => console.log('New value:', v));
72
- *
73
- * state.value = 42; // New value: 42
74
- * state.value = 100; // New value: 100
75
- * ```
76
- */
77
- set value(value: VALUE);
78
- }
79
- //# sourceMappingURL=state.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/reactive/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,KAAK,CAAC,KAAK,GAAG,OAAO,CAAE,SAAQ,MAAM,CAAC,KAAK,CAAC;IACvD,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC;gBACZ,YAAY,EAAE,KAAK;gBACnB,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;IAmBxF;;;;;;;;;;;;;;;;OAgBG;IACM,IAAI,CAAC,GAAG,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI;IAKvC;;;;;;;;;;OAUG;IACH,IAAI,KAAK,IAAI,KAAK,CAEjB;IACD;;;;;;;;;;;;;;;OAeG;IACH,IAAI,KAAK,CAAC,KAAK,EAAE,KAAK,EAGrB;CACF"}