@fluixi/reactive 1.0.0-alpha.53

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 (176) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +343 -0
  3. package/dist/cdn/reactive.cjs +1 -0
  4. package/dist/cdn/reactive.d.ts +11 -0
  5. package/dist/cdn/reactive.d.ts.map +1 -0
  6. package/dist/cdn/reactive.global.js +1 -0
  7. package/dist/cdn/reactive.js +10 -0
  8. package/dist/cdn/reactive.mjs +1 -0
  9. package/dist/cdn/signal.cjs +1 -0
  10. package/dist/cdn/signal.d.ts +19 -0
  11. package/dist/cdn/signal.d.ts.map +1 -0
  12. package/dist/cdn/signal.global.js +1 -0
  13. package/dist/cdn/signal.js +18 -0
  14. package/dist/cdn/signal.mjs +1 -0
  15. package/dist/index.cjs +1 -0
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +1 -0
  19. package/dist/index.mjs +1 -0
  20. package/dist/lib/index.cjs +1 -0
  21. package/dist/lib/index.d.ts +5 -0
  22. package/dist/lib/index.d.ts.map +1 -0
  23. package/dist/lib/index.js +4 -0
  24. package/dist/lib/index.mjs +1 -0
  25. package/dist/lib/observable/index.cjs +1 -0
  26. package/dist/lib/observable/index.d.ts +4 -0
  27. package/dist/lib/observable/index.d.ts.map +1 -0
  28. package/dist/lib/observable/index.js +3 -0
  29. package/dist/lib/observable/index.mjs +1 -0
  30. package/dist/lib/observable/observable.cjs +1 -0
  31. package/dist/lib/observable/observable.d.ts +383 -0
  32. package/dist/lib/observable/observable.d.ts.map +1 -0
  33. package/dist/lib/observable/observable.js +339 -0
  34. package/dist/lib/observable/observable.mjs +1 -0
  35. package/dist/lib/observable/subscription.cjs +1 -0
  36. package/dist/lib/observable/subscription.d.ts +70 -0
  37. package/dist/lib/observable/subscription.d.ts.map +1 -0
  38. package/dist/lib/observable/subscription.js +190 -0
  39. package/dist/lib/observable/subscription.mjs +1 -0
  40. package/dist/lib/observable/types.cjs +1 -0
  41. package/dist/lib/observable/types.d.ts +44 -0
  42. package/dist/lib/observable/types.d.ts.map +1 -0
  43. package/dist/lib/observable/types.js +1 -0
  44. package/dist/lib/observable/types.mjs +0 -0
  45. package/dist/lib/signal/cached-resource.cjs +1 -0
  46. package/dist/lib/signal/cached-resource.d.ts +94 -0
  47. package/dist/lib/signal/cached-resource.d.ts.map +1 -0
  48. package/dist/lib/signal/cached-resource.js +257 -0
  49. package/dist/lib/signal/cached-resource.mjs +1 -0
  50. package/dist/lib/signal/graph/children.cjs +1 -0
  51. package/dist/lib/signal/graph/children.d.ts +2 -0
  52. package/dist/lib/signal/graph/children.d.ts.map +1 -0
  53. package/dist/lib/signal/graph/children.js +30 -0
  54. package/dist/lib/signal/graph/children.mjs +1 -0
  55. package/dist/lib/signal/graph/compat.cjs +1 -0
  56. package/dist/lib/signal/graph/compat.d.ts +64 -0
  57. package/dist/lib/signal/graph/compat.d.ts.map +1 -0
  58. package/dist/lib/signal/graph/compat.js +178 -0
  59. package/dist/lib/signal/graph/compat.mjs +1 -0
  60. package/dist/lib/signal/graph/core.cjs +1 -0
  61. package/dist/lib/signal/graph/core.d.ts +95 -0
  62. package/dist/lib/signal/graph/core.d.ts.map +1 -0
  63. package/dist/lib/signal/graph/core.js +254 -0
  64. package/dist/lib/signal/graph/core.mjs +1 -0
  65. package/dist/lib/signal/graph/derived.cjs +1 -0
  66. package/dist/lib/signal/graph/derived.d.ts +14 -0
  67. package/dist/lib/signal/graph/derived.d.ts.map +1 -0
  68. package/dist/lib/signal/graph/derived.js +81 -0
  69. package/dist/lib/signal/graph/derived.mjs +1 -0
  70. package/dist/lib/signal/graph/detect.cjs +1 -0
  71. package/dist/lib/signal/graph/detect.d.ts +16 -0
  72. package/dist/lib/signal/graph/detect.d.ts.map +1 -0
  73. package/dist/lib/signal/graph/detect.js +36 -0
  74. package/dist/lib/signal/graph/detect.mjs +1 -0
  75. package/dist/lib/signal/graph/error-boundary.cjs +1 -0
  76. package/dist/lib/signal/graph/error-boundary.d.ts +16 -0
  77. package/dist/lib/signal/graph/error-boundary.d.ts.map +1 -0
  78. package/dist/lib/signal/graph/error-boundary.js +34 -0
  79. package/dist/lib/signal/graph/error-boundary.mjs +1 -0
  80. package/dist/lib/signal/graph/index.cjs +1 -0
  81. package/dist/lib/signal/graph/index.d.ts +21 -0
  82. package/dist/lib/signal/graph/index.d.ts.map +1 -0
  83. package/dist/lib/signal/graph/index.js +20 -0
  84. package/dist/lib/signal/graph/index.mjs +1 -0
  85. package/dist/lib/signal/graph/resource.cjs +1 -0
  86. package/dist/lib/signal/graph/resource.d.ts +36 -0
  87. package/dist/lib/signal/graph/resource.d.ts.map +1 -0
  88. package/dist/lib/signal/graph/resource.js +156 -0
  89. package/dist/lib/signal/graph/resource.mjs +1 -0
  90. package/dist/lib/signal/graph/runtime.cjs +1 -0
  91. package/dist/lib/signal/graph/runtime.d.ts +56 -0
  92. package/dist/lib/signal/graph/runtime.d.ts.map +1 -0
  93. package/dist/lib/signal/graph/runtime.js +277 -0
  94. package/dist/lib/signal/graph/runtime.mjs +1 -0
  95. package/dist/lib/signal/graph/signal-next.cjs +1 -0
  96. package/dist/lib/signal/graph/signal-next.d.ts +37 -0
  97. package/dist/lib/signal/graph/signal-next.d.ts.map +1 -0
  98. package/dist/lib/signal/graph/signal-next.js +41 -0
  99. package/dist/lib/signal/graph/signal-next.mjs +1 -0
  100. package/dist/lib/signal/graph/ssr-hooks.cjs +1 -0
  101. package/dist/lib/signal/graph/ssr-hooks.d.ts +28 -0
  102. package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -0
  103. package/dist/lib/signal/graph/ssr-hooks.js +45 -0
  104. package/dist/lib/signal/graph/ssr-hooks.mjs +1 -0
  105. package/dist/lib/signal/graph/state.cjs +1 -0
  106. package/dist/lib/signal/graph/state.d.ts +43 -0
  107. package/dist/lib/signal/graph/state.d.ts.map +1 -0
  108. package/dist/lib/signal/graph/state.js +37 -0
  109. package/dist/lib/signal/graph/state.mjs +1 -0
  110. package/dist/lib/signal/graph/suspense.cjs +1 -0
  111. package/dist/lib/signal/graph/suspense.d.ts +13 -0
  112. package/dist/lib/signal/graph/suspense.d.ts.map +1 -0
  113. package/dist/lib/signal/graph/suspense.js +36 -0
  114. package/dist/lib/signal/graph/suspense.mjs +1 -0
  115. package/dist/lib/signal/index-legacy.cjs +1 -0
  116. package/dist/lib/signal/index-legacy.d.ts +12 -0
  117. package/dist/lib/signal/index-legacy.d.ts.map +1 -0
  118. package/dist/lib/signal/index-legacy.js +11 -0
  119. package/dist/lib/signal/index-legacy.mjs +1 -0
  120. package/dist/lib/signal/index.cjs +1 -0
  121. package/dist/lib/signal/index.d.ts +12 -0
  122. package/dist/lib/signal/index.d.ts.map +1 -0
  123. package/dist/lib/signal/index.js +11 -0
  124. package/dist/lib/signal/index.mjs +1 -0
  125. package/dist/lib/signal/list.cjs +1 -0
  126. package/dist/lib/signal/list.d.ts +39 -0
  127. package/dist/lib/signal/list.d.ts.map +1 -0
  128. package/dist/lib/signal/list.js +172 -0
  129. package/dist/lib/signal/list.mjs +1 -0
  130. package/dist/lib/signal/signal.cjs +1 -0
  131. package/dist/lib/signal/signal.d.ts +295 -0
  132. package/dist/lib/signal/signal.d.ts.map +1 -0
  133. package/dist/lib/signal/signal.js +1219 -0
  134. package/dist/lib/signal/signal.mjs +1 -0
  135. package/dist/lib/signal/types.cjs +1 -0
  136. package/dist/lib/signal/types.d.ts +133 -0
  137. package/dist/lib/signal/types.d.ts.map +1 -0
  138. package/dist/lib/signal/types.js +38 -0
  139. package/dist/lib/signal/types.mjs +1 -0
  140. package/dist/lib/signal/utilities.cjs +1 -0
  141. package/dist/lib/signal/utilities.d.ts +355 -0
  142. package/dist/lib/signal/utilities.d.ts.map +1 -0
  143. package/dist/lib/signal/utilities.js +504 -0
  144. package/dist/lib/signal/utilities.mjs +1 -0
  145. package/dist/lib/store/index.cjs +1 -0
  146. package/dist/lib/store/index.d.ts +14 -0
  147. package/dist/lib/store/index.d.ts.map +1 -0
  148. package/dist/lib/store/index.js +11 -0
  149. package/dist/lib/store/index.mjs +1 -0
  150. package/dist/lib/store/setter.types.cjs +1 -0
  151. package/dist/lib/store/setter.types.d.ts +79 -0
  152. package/dist/lib/store/setter.types.d.ts.map +1 -0
  153. package/dist/lib/store/setter.types.js +65 -0
  154. package/dist/lib/store/setter.types.mjs +0 -0
  155. package/dist/lib/store/store.cjs +1 -0
  156. package/dist/lib/store/store.d.ts +86 -0
  157. package/dist/lib/store/store.d.ts.map +1 -0
  158. package/dist/lib/store/store.js +442 -0
  159. package/dist/lib/store/store.mjs +1 -0
  160. package/dist/lib/store/types.cjs +1 -0
  161. package/dist/lib/store/types.d.ts +57 -0
  162. package/dist/lib/store/types.d.ts.map +1 -0
  163. package/dist/lib/store/types.js +1 -0
  164. package/dist/lib/store/types.mjs +0 -0
  165. package/dist/lib/store/utils.cjs +1 -0
  166. package/dist/lib/store/utils.d.ts +13 -0
  167. package/dist/lib/store/utils.d.ts.map +1 -0
  168. package/dist/lib/store/utils.js +29 -0
  169. package/dist/lib/store/utils.mjs +1 -0
  170. package/dist/lib/subject.cjs +1 -0
  171. package/dist/lib/subject.d.ts +14 -0
  172. package/dist/lib/subject.d.ts.map +1 -0
  173. package/dist/lib/subject.js +169 -0
  174. package/dist/lib/subject.mjs +1 -0
  175. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  176. package/package.json +114 -0
@@ -0,0 +1,504 @@
1
+ /**
2
+ * @fileoverview Signal Utility Functions
3
+ * @description Common utility functions for transforming and combining signals
4
+ * @version 1.0.0
5
+ */
6
+ import { createSignal, createMemo, createEffect } from './graph/compat.js';
7
+ import { Observable } from '../observable/observable.js';
8
+ // ============================================================================
9
+ // TRANSFORMATION UTILITIES
10
+ // ============================================================================
11
+ /**
12
+ * Transform a signal value through a mapping function
13
+ * @template T - Input signal type
14
+ * @template U - Output signal type
15
+ * @param signal - Source signal to transform
16
+ * @param fn - Mapping function to apply to signal value
17
+ * @param options - Memo options for equality checking
18
+ * @returns New accessor with transformed value
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const count = createSignal(5);
23
+ * const doubled = map(count[0], x => x * 2);
24
+ * console.log(doubled()); // 10
25
+ * ```
26
+ */
27
+ export function mapSignal(signal, fn, options) {
28
+ return createMemo(() => fn(signal()), undefined, options);
29
+ }
30
+ /**
31
+ * Filter an array signal using a predicate function
32
+ * @template T - Array element type
33
+ * @param signal - Source signal containing array
34
+ * @param predicate - Filter function to test each element
35
+ * @param options - Memo options for equality checking
36
+ * @returns New accessor with filtered array
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const [numbers] = createSignal([1, 2, 3, 4, 5]);
41
+ * const evens = filter(numbers, x => x % 2 === 0);
42
+ * console.log(evens()); // [2, 4]
43
+ * ```
44
+ */
45
+ export function filterSignal(signal, predicate, options) {
46
+ return createMemo(() => signal().filter(predicate), undefined, options);
47
+ }
48
+ /**
49
+ * Reduce an array signal to a single value
50
+ * @template T - Array element type
51
+ * @template U - Accumulator type
52
+ * @param signal - Source signal containing array
53
+ * @param reducer - Reducer function
54
+ * @param initialValue - Initial accumulator value
55
+ * @param options - Memo options for equality checking
56
+ * @returns New accessor with reduced value
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const [numbers] = createSignal([1, 2, 3, 4, 5]);
61
+ * const sum = reduce(numbers, (acc, x) => acc + x, 0);
62
+ * console.log(sum()); // 15
63
+ * ```
64
+ */
65
+ export function reduceSignal(signal, reducer, initialValue, options) {
66
+ return createMemo(() => signal().reduce(reducer, initialValue), undefined, options);
67
+ }
68
+ /**
69
+ * Find first element in array signal matching predicate
70
+ * @template T - Array element type
71
+ * @param signal - Source signal containing array
72
+ * @param predicate - Predicate function to test elements
73
+ * @param options - Memo options for equality checking
74
+ * @returns New accessor with found element or undefined
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const [users] = createSignal([{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]);
79
+ * const user = find(users, u => u.id === 2);
80
+ * console.log(user()?.name); // 'Bob'
81
+ * ```
82
+ */
83
+ export function findSignal(signal, predicate, options) {
84
+ return createMemo(() => signal().find(predicate), undefined, options);
85
+ }
86
+ /**
87
+ * Check if any element in array signal matches predicate
88
+ * @template T - Array element type
89
+ * @param signal - Source signal containing array
90
+ * @param predicate - Predicate function to test elements
91
+ * @param options - Memo options for equality checking
92
+ * @returns New accessor returning boolean
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const [numbers] = createSignal([1, 2, 3, 4, 5]);
97
+ * const hasEven = some(numbers, x => x % 2 === 0);
98
+ * console.log(hasEven()); // true
99
+ * ```
100
+ */
101
+ export function someSignal(signal, predicate, options) {
102
+ return createMemo(() => signal().some(predicate), undefined, options);
103
+ }
104
+ /**
105
+ * Check if all elements in array signal match predicate
106
+ * @template T - Array element type
107
+ * @param signal - Source signal containing array
108
+ * @param predicate - Predicate function to test elements
109
+ * @param options - Memo options for equality checking
110
+ * @returns New accessor returning boolean
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const [numbers] = createSignal([2, 4, 6, 8]);
115
+ * const allEven = every(numbers, x => x % 2 === 0);
116
+ * console.log(allEven()); // true
117
+ * ```
118
+ */
119
+ export function everySignal(signal, predicate, options) {
120
+ return createMemo(() => signal().every(predicate), undefined, options);
121
+ }
122
+ /**
123
+ * Sort an array signal
124
+ * @template T - Array element type
125
+ * @param signal - Source signal containing array
126
+ * @param compareFn - Optional compare function for sorting
127
+ * @param options - Memo options for equality checking
128
+ * @returns New accessor with sorted array
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const [numbers] = createSignal([3, 1, 4, 1, 5]);
133
+ * const sorted = sort(numbers);
134
+ * console.log(sorted()); // [1, 1, 3, 4, 5]
135
+ * ```
136
+ */
137
+ export function sortSignal(signal, compareFn, options) {
138
+ return createMemo(() => [...signal()].sort(compareFn), undefined, options);
139
+ }
140
+ /**
141
+ * Get unique values from array signal
142
+ * @template T - Array element type
143
+ * @param signal - Source signal containing array
144
+ * @param options - Memo options for equality checking
145
+ * @returns New accessor with unique values
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * const [numbers] = createSignal([1, 2, 2, 3, 3, 3, 4]);
150
+ * const unique = distinct(numbers);
151
+ * console.log(unique()); // [1, 2, 3, 4]
152
+ * ```
153
+ */
154
+ export function distinctSignal(signal, options) {
155
+ return createMemo(() => [...new Set(signal())], undefined, options);
156
+ }
157
+ // ============================================================================
158
+ // COMBINATION UTILITIES
159
+ // ============================================================================
160
+ /**
161
+ * Combine multiple signals into a single computed signal
162
+ * @template T - Tuple type of signal values
163
+ * @template U - Result type
164
+ * @param signals - Array of signals to combine
165
+ * @param combiner - Function to combine signal values
166
+ * @param options - Memo options for equality checking
167
+ * @returns New accessor with combined value
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * const [a] = createSignal(1);
172
+ * const [b] = createSignal(2);
173
+ * const sum = combine([a, b], ([x, y]) => x + y);
174
+ * console.log(sum()); // 3
175
+ * ```
176
+ */
177
+ export function combineSignal(signals, combiner, options) {
178
+ return createMemo(() => {
179
+ const values = signals.map((s) => s());
180
+ return combiner(values);
181
+ }, undefined, options);
182
+ }
183
+ /**
184
+ * Combine multiple signals into observable
185
+ */
186
+ export function combineSignals(...signals) {
187
+ return new Observable((observer) => {
188
+ const getValues = () => signals.map((s) => (typeof s === 'function' ? s() : s.get()));
189
+ const disposers = signals.map((signal) => {
190
+ if (typeof signal === 'function' && signal.subscribe) {
191
+ return signal.subscribe(() => {
192
+ observer.next(getValues());
193
+ });
194
+ }
195
+ else if (typeof signal !== 'function') {
196
+ return signal.subscribe(() => {
197
+ observer.next(getValues());
198
+ });
199
+ }
200
+ return createEffect(() => {
201
+ observer.next(getValues());
202
+ });
203
+ });
204
+ return () => {
205
+ disposers.forEach((dispose) => {
206
+ if (typeof dispose === 'function')
207
+ dispose();
208
+ else if (dispose && typeof dispose.unsubscribe === 'function') {
209
+ dispose.unsubscribe();
210
+ }
211
+ });
212
+ };
213
+ });
214
+ // return {
215
+ // subscribe(
216
+ // observerOrNext?: ((value: T) => void) | Partial<SignalObserver<T>>,
217
+ // error?: (error: any) => void,
218
+ // complete?: () => void
219
+ // ): Subscription {
220
+ // const observer = typeof observerOrNext === 'function'
221
+ // ? { next: observerOrNext, error, complete }
222
+ // : observerOrNext || {};
223
+ // const getValues = () => signals.map(s =>
224
+ // typeof s === 'function' ? s() : s.get()
225
+ // ) as T;
226
+ // if (observer.next) {
227
+ // observer.next(getValues());
228
+ // }
229
+ // const disposers = signals.map(signal => {
230
+ // if (typeof signal === 'function' && (signal as any).subscribe) {
231
+ // return (signal as any).subscribe(() => {
232
+ // if (observer.next) {
233
+ // observer.next(getValues());
234
+ // }
235
+ // });
236
+ // } else if (typeof signal !== 'function') {
237
+ // return signal.subscribe(() => {
238
+ // if (observer.next) {
239
+ // observer.next(getValues());
240
+ // }
241
+ // });
242
+ // }
243
+ // return createEffect(() => {
244
+ // getValues();
245
+ // if (observer.next) {
246
+ // observer.next(getValues());
247
+ // }
248
+ // });
249
+ // });
250
+ // return {
251
+ // unsubscribe: () => {
252
+ // disposers.forEach(dispose => {
253
+ // if (typeof dispose === 'function') dispose();
254
+ // else if (dispose && typeof dispose.unsubscribe === 'function') {
255
+ // dispose.unsubscribe();
256
+ // }
257
+ // });
258
+ // },
259
+ // closed: false
260
+ // };
261
+ // },
262
+ // pipe(...operators: any[]): Observable<any> {
263
+ // throw new Error('Pipe requires RxJS');
264
+ // }
265
+ // };
266
+ }
267
+ // export function isSignal<T>(fn: any): fn is () => T {
268
+ // return typeof fn === 'function' && fn.length === 0;
269
+ // }
270
+ // export function isEffect(fn: any): fn is SignalObserver {
271
+ // return typeof fn === 'function' && 'dependencies' in fn;
272
+ // }
273
+ /**
274
+ * Merge two signals, returning value from first truthy signal
275
+ * @template T - Signal value type
276
+ * @param primary - Primary signal
277
+ * @param fallback - Fallback signal if primary is falsy
278
+ * @param options - Memo options for equality checking
279
+ * @returns New accessor with merged value
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * const [user] = createSignal(null);
284
+ * const [guest] = createSignal({ name: 'Guest' });
285
+ * const current = merge(user, guest);
286
+ * console.log(current()?.name); // 'Guest'
287
+ * ```
288
+ */
289
+ export function mergeSignal(primary, fallback, options) {
290
+ return createMemo(() => primary() || fallback(), undefined, options);
291
+ }
292
+ /**
293
+ * Combine two signals using a binary operator
294
+ * @template T - First signal type
295
+ * @template U - Second signal type
296
+ * @template V - Result type
297
+ * @param a - First signal
298
+ * @param b - Second signal
299
+ * @param operator - Binary operator function
300
+ * @param options - Memo options for equality checking
301
+ * @returns New accessor with combined value
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * const [x] = createSignal(5);
306
+ * const [y] = createSignal(3);
307
+ * const product = zip(x, y, (a, b) => a * b);
308
+ * console.log(product()); // 15
309
+ * ```
310
+ */
311
+ export function zipSignal(a, b, operator, options) {
312
+ return createMemo(() => operator(a(), b()), undefined, options);
313
+ }
314
+ // ============================================================================
315
+ // SELECTION UTILITIES
316
+ // ============================================================================
317
+ /**
318
+ * Select a derived value from a signal with custom equality
319
+ * Only updates when selected value changes according to equals function
320
+ * @template T - Signal type
321
+ * @template U - Selected value type
322
+ * @param signal - Source signal
323
+ * @param selector - Function to select value from signal
324
+ * @param equals - Optional equality function (defaults to Object.is)
325
+ * @returns New accessor with selected value
326
+ *
327
+ * @example
328
+ * ```typescript
329
+ * const [user] = createSignal({ id: 1, name: 'Alice', age: 30 });
330
+ * const userName = select(user, u => u.name);
331
+ * // Only updates when name changes, not when age changes
332
+ * ```
333
+ */
334
+ export function selectSignal(signal, selector, equals) {
335
+ return createMemo(() => selector(signal()), undefined, {
336
+ equals,
337
+ internal: true,
338
+ });
339
+ }
340
+ /**
341
+ * Pick specific properties from an object signal
342
+ * @template T - Object type
343
+ * @template K - Property keys
344
+ * @param signal - Source signal containing object
345
+ * @param keys - Array of property keys to pick
346
+ * @param options - Memo options for equality checking
347
+ * @returns New accessor with picked properties
348
+ *
349
+ * @example
350
+ * ```typescript
351
+ * const [user] = createSignal({ id: 1, name: 'Alice', age: 30, email: 'alice@example.com' });
352
+ * const userData = pick(user, ['name', 'email']);
353
+ * console.log(userData()); // { name: 'Alice', email: 'alice@example.com' }
354
+ * ```
355
+ */
356
+ export function pickSignal(signal, keys, options) {
357
+ return createMemo(() => {
358
+ const obj = signal();
359
+ const result = {};
360
+ for (const key of keys) {
361
+ result[key] = obj[key];
362
+ }
363
+ return result;
364
+ }, undefined, options);
365
+ }
366
+ /**
367
+ * Omit specific properties from an object signal
368
+ * @template T - Object type
369
+ * @template K - Property keys to omit
370
+ * @param signal - Source signal containing object
371
+ * @param keys - Array of property keys to omit
372
+ * @param options - Memo options for equality checking
373
+ * @returns New accessor with omitted properties
374
+ *
375
+ * @example
376
+ * ```typescript
377
+ * const [user] = createSignal({ id: 1, name: 'Alice', age: 30, password: 'secret' });
378
+ * const safeUser = omit(user, ['password']);
379
+ * console.log(safeUser()); // { id: 1, name: 'Alice', age: 30 }
380
+ * ```
381
+ */
382
+ export function omitSignal(signal, keys, options) {
383
+ return createMemo(() => {
384
+ const obj = signal();
385
+ const result = { ...obj };
386
+ for (const key of keys) {
387
+ delete result[key];
388
+ }
389
+ return result;
390
+ }, undefined, options);
391
+ }
392
+ // ============================================================================
393
+ // CONDITIONAL UTILITIES
394
+ // ============================================================================
395
+ /**
396
+ * Conditionally compute signal based on condition
397
+ * @template T - Result type
398
+ * @param condition - Condition signal or accessor
399
+ * @param whenTrue - Accessor to use when condition is true
400
+ * @param whenFalse - Accessor to use when condition is false
401
+ * @param options - Memo options for equality checking
402
+ * @returns New accessor with conditional value
403
+ *
404
+ * @example
405
+ * ```typescript
406
+ * const [isLoggedIn] = createSignal(false);
407
+ * const [user] = createSignal({ name: 'Alice' });
408
+ * const [guest] = createSignal({ name: 'Guest' });
409
+ * const currentUser = when(isLoggedIn, user, guest);
410
+ * console.log(currentUser()?.name); // 'Guest'
411
+ * ```
412
+ */
413
+ export function whenSignal(condition, whenTrue, whenFalse, options) {
414
+ return createMemo(() => (condition() ? whenTrue() : whenFalse()), undefined, options);
415
+ }
416
+ /**
417
+ * Compute signal only when condition is true, otherwise return undefined
418
+ * @template T - Result type
419
+ * @param condition - Condition signal or accessor
420
+ * @param accessor - Accessor to use when condition is true
421
+ * @param options - Memo options for equality checking
422
+ * @returns New accessor with conditional value or undefined
423
+ *
424
+ * @example
425
+ * ```typescript
426
+ * const [showDetails] = createSignal(false);
427
+ * const [details] = createSignal({ info: 'Details here' });
428
+ * const visibleDetails = guard(showDetails, details);
429
+ * console.log(visibleDetails()); // undefined (when showDetails is false)
430
+ * ```
431
+ */
432
+ export function guardSignal(condition, accessor, options) {
433
+ return createMemo(() => (condition() ? accessor() : undefined), undefined, options);
434
+ }
435
+ // ============================================================================
436
+ // TIMING UTILITIES
437
+ // ============================================================================
438
+ /**
439
+ * Debounce a signal - only update after delay period with no changes
440
+ * @template T - Signal type
441
+ * @param signal - Source signal to debounce
442
+ * @param delay - Delay in milliseconds
443
+ * @param options - Memo options for equality checking
444
+ * @returns New accessor with debounced value
445
+ *
446
+ * @example
447
+ * ```typescript
448
+ * const [search] = createSignal('');
449
+ * const debouncedSearch = debounce(search, 300);
450
+ * // debouncedSearch only updates 300ms after last search change
451
+ * ```
452
+ */
453
+ export function debounceSignal(signal, delay, options) {
454
+ const [debounced, setDebounced] = createSignal(signal());
455
+ let timeoutId;
456
+ createMemo(() => {
457
+ const value = signal();
458
+ clearTimeout(timeoutId);
459
+ timeoutId = setTimeout(() => setDebounced(() => value), delay);
460
+ });
461
+ return debounced;
462
+ }
463
+ /**
464
+ * Throttle a signal - limit update frequency
465
+ * @template T - Signal type
466
+ * @param signal - Source signal to throttle
467
+ * @param delay - Minimum delay between updates in milliseconds
468
+ * @param options - Memo options for equality checking
469
+ * @returns New accessor with throttled value
470
+ *
471
+ * @example
472
+ * ```typescript
473
+ * const [scroll] = createSignal(0);
474
+ * const throttledScroll = throttle(scroll, 100);
475
+ * // throttledScroll updates at most once per 100ms
476
+ * ```
477
+ */
478
+ export function throttleSignal(signal, delay, options) {
479
+ const [throttled, setThrottled] = createSignal(signal());
480
+ let lastUpdate = 0;
481
+ let timeoutId;
482
+ createMemo(() => {
483
+ const value = signal();
484
+ const now = Date.now();
485
+ if (now - lastUpdate >= delay) {
486
+ lastUpdate = now;
487
+ setThrottled(() => value);
488
+ }
489
+ else {
490
+ clearTimeout(timeoutId);
491
+ timeoutId = setTimeout(() => {
492
+ lastUpdate = Date.now();
493
+ setThrottled(() => value);
494
+ }, delay - (now - lastUpdate));
495
+ }
496
+ });
497
+ return throttled;
498
+ }
499
+ export function readSignal(signal) {
500
+ let value = signal;
501
+ while (typeof value === 'function')
502
+ value = value();
503
+ return value;
504
+ }
@@ -0,0 +1 @@
1
+ var M="__fluixi_signal_next_state__",B=t=>{typeof queueMicrotask=="function"?queueMicrotask(t):Promise.resolve().then(t)},s=globalThis[M]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:B,onSuspend:null,onError:null};var _=0,F=1,d=2,h=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(s.untracked)return;let e=s.consumer;e&&((this.observers??=new Set).add(e),(e.sources??=new Set).add(this))}},b=class extends h{constructor(e,r){super(),this._value=e,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){return this.track(),this._value}set(e){if(!this._equals(this._value,e)){if(this._value=e,this.version++,this.observers)for(let r of[...this.observers])r.markDirty(d);m(this)}}peek(){return this._value}},l=class extends h{constructor(r,n){super();this._threw=!1;this._initialized=!1;this.state=d;this.sources=null;this._fn=r,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){if(s.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===F&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===d)break}(this.state===d||!this._initialized)&&this.recompute(),this.state=_}recompute(){if(this.sources){for(let a of this.sources)a.observers?.delete(this);this.sources.clear()}let r=s.consumer,n=s.untracked;s.consumer=this,s.untracked=!1;let o,i=!1,u;try{o=this._fn()}catch(a){i=!0,u=a,o=this._value}finally{s.consumer=r,s.untracked=n}let p=!this._initialized||this._threw!==i||(i?u!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=i,this._error=u,this._value=o,p){if(this.version++,this.observers)for(let a of[...this.observers])a.markDirty(d);m(this)}}markDirty(r){if(this.state>=r)return;let n=this.state===_;if(this.state=r,n){if(this.observers)for(let o of[...this.observers])o.markDirty(F);m(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function m(t){if(t.watchers)for(let e of[...t.watchers])e._notify(t)}var T=class{constructor(e){this._watched=new Set;this._pending=new Set;this._notifyFn=e}watch(...e){for(let r of e)this._watched.add(r),(r.watchers??=new Set).add(this)}unwatch(...e){for(let r of e)this._watched.delete(r),r.watchers?.delete(this),this._pending.delete(r)}getPending(){let e=[...this._pending];return this._pending.clear(),e}_notify(e){if(!this._watched.has(e)||this._pending.has(e))return;let r=this._pending.size===0;this._pending.add(e),r&&this._notifyFn()}};function I(t){return{cleanups:null,owned:null,parent:t,contexts:null}}function k(t){return s.onSuspend?(s.onSuspend(t,s.owner),!0):!1}function C(){return s.owner}function x(t,e){let r=s.owner;s.owner=t;try{return e()}finally{s.owner=r}}function w(t){if(t.owned){for(let e=t.owned.length-1;e>=0;e--)w(t.owned[e]);t.owned=null}if(t.cleanups){for(let e=t.cleanups.length-1;e>=0;e--)t.cleanups[e]();t.cleanups=null}}function P(t){s.hostSchedule=t??(e=>{Promise.resolve().then(e)})}function K(t){t.queued||(t.queued=!0,s.queue.push(t),!s.scheduled&&s.batchDepth===0&&(s.scheduled=!0,s.hostSchedule(S)))}function S(){if(s.scheduled=!1,s.flushing)return;s.flushing=!0;let t=0;try{for(;s.queue.length;){if(++t>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let e=s.queue;s.queue=[];for(let r of e)r.queued=!1,r.disposed||r.run()}}finally{s.flushing=!1}}function U(){s.batchDepth===0&&S()}var O=class{constructor(e){this.queued=!1;this.disposed=!1;this.owner=I(s.owner),s.owner&&(s.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new l(()=>{w(this.owner),x(this.owner,()=>{let r=e();typeof r=="function"&&(this.owner.cleanups??=[]).push(r)})}),this.watcher=new T(()=>K(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(e){if(e&&typeof e.then=="function"&&s.onSuspend){s.onSuspend(e,this.owner);return}if(s.onError&&s.onError(e,this.owner))return;throw e}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),w(this.owner))}};function E(t){let e=new O(t);return()=>e.dispose()}function G(t){return!!t&&typeof t.then=="function"}P(()=>{});var D=Symbol.for("signal"),V=Symbol.for("memo"),j=Symbol.for("signal-node");function A(t,e){let r=new b(t,{equals:e?.equals}),n=(()=>r.get()),o=(i=>{let u=typeof i=="function"?i(r.peek()):i;return r.set(u),U(),u});return Object.defineProperty(n,D,{value:!0,enumerable:!0}),Object.defineProperty(n,j,{value:{get value(){return r.peek()},get version(){return r.version}},enumerable:!1}),[n,o]}function c(t,e,r){let n=e,o=C(),i=new l(()=>x(o,()=>{try{return n=t(n)}catch(p){if(G(p))return k(p),n;throw p}}),{equals:r?.equals}),u=(()=>i.get());return Object.defineProperty(u,D,{value:!0,enumerable:!0}),Object.defineProperty(u,V,{value:!0,enumerable:!0}),u}function R(t,e){let r=e;return E(()=>{r=t(r)})}import{isObject as H}from"@fluixi/utils/object";import{isFunction as q}from"@fluixi/utils/functions";var f=class t{constructor(e){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;e&&(this._subscriptions=[e])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:e,_subscriptions:r}=this;if(e instanceof t)e.remove(this);else if(e!==null)for(let n of e)n.remove(this);if(r){for(let n of r)if(q(n)&&!(n instanceof t))try{n()}catch(o){console.error("Error in unsubscribe function:",o)}else if(H(n)&&typeof n.unsubscribe=="function")try{n.unsubscribe()}catch(o){console.error("Error unsubscribing child:",o)}this._subscriptions=null}}add(e){if(!e||e===this)return this;if(e.closed)return this;let{_closed:r,_subscriptions:n}=this;if(r){if(q(e))try{e()}catch(o){console.error("Error in unsubscribe function:",o)}else if(e.unsubscribe)try{e.unsubscribe()}catch(o){console.error("Error unsubscribing:",o)}return this}return n||(this._subscriptions=[]),this._subscriptions.push(e),e instanceof t&&e._addParent(this),this}remove(e){let{_subscriptions:r}=this;if(!r)return;let n=r.indexOf(e);n!==-1&&(r.splice(n,1),e._removeParent(this))}_addParent(e){let{_parentOrParents:r}=this;r?Array.isArray(r)?r.push(e):this._parentOrParents=[r,e]:this._parentOrParents=e}_removeParent(e){let{_parentOrParents:r}=this;if(r===e)this._parentOrParents=null;else if(Array.isArray(r)){let n=r.indexOf(e);n!==-1&&(r.splice(n,1),r.length===1&&(this._parentOrParents=r[0]))}}};var v=class extends f{constructor(r,n,o){super();this.isStopped=!1;let i;r?typeof r=="object"?i=r:i={next:r,error:n,complete:o}:i={},this.destination=i}next(r){if(!this.isStopped&&this.destination.next)try{this.destination.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(r)}catch(n){throw n}else throw r;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(r){this.error(r);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},g=class extends v{constructor(r,n,o,i){super(r,n,o);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=i||null}next(r){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(r)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};var y=class extends f{constructor(e){if(super(),e)this._subscribe=e;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(e,r,n){let o;e instanceof v?o=e:o=new g(e,r,n);let{_subscribe:i}=this;try{let u=i.call(this,o);u&&(typeof u=="function"||typeof u.unsubscribe=="function")&&o.add(u)}catch(u){o.error(u)}return o}pipe(...e){return e.length===0?this:e.reduce((r,n)=>n(r),this)}toPromise(){return new Promise((e,r)=>{let n;this.subscribe({next:o=>n=o,error:r,complete:()=>e(n)})})}};function ce(t,e,r){return c(()=>e(t()),void 0,r)}function ae(t,e,r){return c(()=>t().filter(e),void 0,r)}function pe(t,e,r,n){return c(()=>t().reduce(e,r),void 0,n)}function le(t,e,r){return c(()=>t().find(e),void 0,r)}function de(t,e,r){return c(()=>t().some(e),void 0,r)}function fe(t,e,r){return c(()=>t().every(e),void 0,r)}function he(t,e,r){return c(()=>[...t()].sort(e),void 0,r)}function be(t,e){return c(()=>[...new Set(t())],void 0,e)}function Te(t,e,r){return c(()=>{let n=t.map(o=>o());return e(n)},void 0,r)}function ve(...t){return new y(e=>{let r=()=>t.map(o=>typeof o=="function"?o():o.get()),n=t.map(o=>typeof o=="function"&&o.subscribe?o.subscribe(()=>{e.next(r())}):typeof o!="function"?o.subscribe(()=>{e.next(r())}):R(()=>{e.next(r())}));return()=>{n.forEach(o=>{typeof o=="function"?o():o&&typeof o.unsubscribe=="function"&&o.unsubscribe()})}})}function ye(t,e,r){return c(()=>t()||e(),void 0,r)}function me(t,e,r,n){return c(()=>r(t(),e()),void 0,n)}function we(t,e,r){return c(()=>e(t()),void 0,{equals:r,internal:!0})}function Oe(t,e,r){return c(()=>{let n=t(),o={};for(let i of e)o[i]=n[i];return o},void 0,r)}function xe(t,e,r){return c(()=>{let o={...t()};for(let i of e)delete o[i];return o},void 0,r)}function Se(t,e,r,n){return c(()=>t()?e():r(),void 0,n)}function Ae(t,e,r){return c(()=>t()?e():void 0,void 0,r)}function ge(t,e,r){let[n,o]=A(t()),i;return c(()=>{let u=t();clearTimeout(i),i=setTimeout(()=>o(()=>u),e)}),n}function _e(t,e,r){let[n,o]=A(t()),i=0,u;return c(()=>{let p=t(),a=Date.now();a-i>=e?(i=a,o(()=>p)):(clearTimeout(u),u=setTimeout(()=>{i=Date.now(),o(()=>p)},e-(a-i)))}),n}function Fe(t){let e=t;for(;typeof e=="function";)e=e();return e}export{Te as combineSignal,ve as combineSignals,ge as debounceSignal,be as distinctSignal,fe as everySignal,ae as filterSignal,le as findSignal,Ae as guardSignal,ce as mapSignal,ye as mergeSignal,xe as omitSignal,Oe as pickSignal,Fe as readSignal,pe as reduceSignal,we as selectSignal,de as someSignal,he as sortSignal,_e as throttleSignal,Se as whenSignal,me as zipSignal};
@@ -0,0 +1 @@
1
+ "use strict";var x=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var nt=Object.prototype.hasOwnProperty;var ot=(e,t)=>{for(var r in t)x(e,r,{get:t[r],enumerable:!0})},st=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of rt(t))!nt.call(e,o)&&o!==r&&x(e,o,{get:()=>t[o],enumerable:!(n=et(t,o))||n.enumerable});return e};var it=e=>st(x({},"__esModule",{value:!0}),e);var ut={};ot(ut,{$NAME:()=>W,$NODE:()=>u,$RAW:()=>m,$SELF:()=>T,$STORE:()=>C,$TRACK:()=>S,Store:()=>y,StoreAPI:()=>Q,createComputedStore:()=>z,createMutableStore:()=>N,createStore:()=>w,createStoreEffect:()=>L,createStoreMemo:()=>X,getNode:()=>Y,getStoreNode:()=>G,isStore:()=>q,isStoreProxy:()=>h,modifiable:()=>J,produceUtil:()=>Z,reconcileUtil:()=>tt,untrackStore:()=>U,unwrap:()=>l,wrap:()=>k});module.exports=it(ut);var s=require("@fluixi/reactive/signal"),m=Symbol("store-raw"),u=Symbol("store-node"),R=Symbol("store-has"),T=Symbol("store-self"),S=Symbol("store-track"),W=Symbol("store-name"),C=Symbol("store-store"),M=new WeakMap,v=new WeakMap;function B(e){let[t,r]=(0,s.createSignal)(e),n=t;return n.$=r,n}function A(e){let t=M.get(e);return t||M.set(e,t={keys:new Map}),t}function E(e,t,r){let n=e.keys.get(t);return n||e.keys.set(t,n=B(r)),n}function D(e){let t=A(e);(t.all||(t.all=B()))()}function _(e,t){e.$(typeof t=="function"?()=>t:t)}function F(e){if(e==null||typeof e!="object")return!1;if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function b(e){if(!F(e))return e;let t=v.get(e);if(t)return t;let r=new Proxy(e,at);return v.set(e,r),r}var at={get(e,t,r){if(t===m||t===u)return e;if(t===s.$PROXY)return r;if(t===R)return a=>a in e;if(t==="__proxy")return!0;if(t===S||t===T)return D(e),r;let n=e[t];if(typeof n=="function"&&!Object.prototype.hasOwnProperty.call(e,t))return n;let o=Object.getOwnPropertyDescriptor(e,t);if(o&&o.get)return o.get.call(r);let i=E(A(e),t,n)();return F(i)?b(i):i},set(){return!0},deleteProperty(e,t){return t in e&&p(e,t,void 0),!0},has(e,t){return t===m||t===s.$PROXY||t===u||t===R||t===T||t===S?!0:(E(A(e),t,e[t])(),t in e)},ownKeys(e){return D(e),Reflect.ownKeys(e)},getOwnPropertyDescriptor(e,t){return Reflect.getOwnPropertyDescriptor(e,t)}};function p(e,t,r){if(e[t]===r&&(r!==void 0||t in e))return;let o=Array.isArray(e),i=o?e.length:0;r===void 0?delete e[t]:e[t]=r;let a=A(e),c=a.keys.get(t);if(c&&_(c,r),o&&e.length!==i){let d=a.keys.get("length");d&&_(d,e.length)}a.all&&a.all.$(void 0)}function K(e,t){return typeof e=="function"?e(t):e}function j(e,t){for(let r of Object.keys(t)){let n=t[r],o=e[r];n&&typeof n=="object"&&!Array.isArray(n)&&o&&typeof o=="object"&&!Array.isArray(o)?j(o,n):p(e,r,n)}}function P(e){let t=[],r=e.replace(/\[([^\]]*)\]/g,".$1");for(let n of r.split("."))n.length&&t.push(n);return t}function H(e,t,r){let n=t.length-1;for(let i=0;i<n;i++){let a=t[i];if(a==="*"){let d=t.slice(i+1);if(Array.isArray(e))for(let O=0;O<e.length;O++)H(e[O],d,r);return}let c=e[a];(c==null||typeof c!="object")&&(c=/^\d+$/.test(t[i+1])?[]:{},p(e,a,c)),e=c}let o=t[n];if(o==="*"){if(Array.isArray(e))for(let i=0;i<e.length;i++)p(e,i,K(r,e[i]));return}p(e,o,K(r,e[o]))}function g(e,t,r){H(e,P(t),r)}function ct(e,t){let r=t[0];if(typeof r=="function"&&t.length===1){let n=r(e);n&&n!==e&&j(e,n);return}if(Array.isArray(r)&&t.length===1){for(let n of r)Array.isArray(n)&&g(e,n[0],n[1]);return}if(r&&typeof r=="object"&&!Array.isArray(r)&&t.length===1){j(e,r);return}if(Array.isArray(t[1])&&t.length>=3){g(e,`${r}.${t[1].join(".")}`,t[2]);return}g(e,String(r),t[1])}function I(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(I);let t={};for(let r of Object.keys(e))t[r]=I(e[r]);return t}function f(e,t){let r=e;for(let n of P(t)){if(r==null)return;r=r[n]}return r}var y=class{constructor(t,r={immutable:!0}){this.options=r;this.root=t,this.set=((...n)=>(0,s.batch)(()=>ct(this.root,n)))}get state(){return b(this.root)}get proxy(){return b(this.root)}get accessor(){return(()=>b(this.root))}unwrap(){return this.root}getNode(t){return this.root&&this.root[t]}get(t){if(t==null||t==="")return l(this.state);let r=this.state;for(let n of P(t)){if(r==null)return;r=r[n]}return l(r)}select(t){return(0,s.createMemo)(()=>t(this.state))}subscribe(t){return(0,s.createEffect)(()=>t(this.state))}watch(t,r){let n;return(0,s.createEffect)(()=>{let o=t(this.state);Object.is(o,n)||(r(o,n),n=o)})}reactive(t){return(0,s.createMemo)(()=>this.state[t])}produce(t){this.set((r=>{let n=I(r);return t(n),n}))}reconcile(t,r={}){this.set(t)}push(t,...r){let n=f(this.root,t);this.set(t,n.concat(r))}pop(t){let r=f(this.root,t).slice(),n=r.pop();return this.set(t,r),n}shift(t){let r=f(this.root,t).slice(),n=r.shift();return this.set(t,r),n}splice(t,r,n,...o){let i=f(this.root,t).slice(),a=i.splice(r,n,...o);return this.set(t,i),a}insert(t,r,n){let o=f(this.root,t).slice();o.splice(r,0,n),this.set(t,o)}removeAt(t,r){let n=f(this.root,t).slice(),o=n.splice(r,1);return this.set(t,n),o}toObservable(){let[t]=(0,s.createSignal)(this.state);return t.toObservable()}dispose(){}},yt=["get","select","watch","subscribe","produce","reconcile","push","pop","shift","splice","insert","removeAt","unwrap","toObservable"];function V(e,t){for(let r of yt)e[r]=t[r].bind(t);e.$=t.reactive.bind(t)}function w(e,t={immutable:!0}){let r=new y(e,t);return V(r.set,r),[r.proxy,r.set]}function N(e,t={}){return new y(e,{...t,immutable:!1})}function z(e,t={}){let r=new y(e(),t);return(0,s.createEffect)(()=>r.set(e())),r}function L(e,t,r){return(0,s.createEffect)(()=>r(t(e)))}function X(e,t,r){return(0,s.createMemo)(()=>t(e),void 0,r)}function k(e,t={}){let r=new y(e,t),n=(()=>r.proxy);return V(n,r),n}function l(e){if(e==null||typeof e!="object")return e;let t=e[m];return t!==void 0?t:e}function U(e){return(0,s.untrack)(()=>l(e))}function q(e){return h(e)}function Y(e){return h(e)?e[u]:null}function G(e){return e&&typeof e=="object"&&u in e?e[u]:null}function h(e){return!!e&&typeof e=="object"&&(s.$PROXY in e||e.__proxy===!0)}function J(e){return e}var Q=Object.freeze({createStore:w,createMutableStore:N,batch:s.batch,unwrap:l,untrackStore:U});function $(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map($);let t={};for(let r of Object.keys(e))t[r]=$(e[r]);return t}function Z(e){return t=>{let r=$(t);return e(r),r}}function tt(e,t={}){return()=>e}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Fine-grained reactive store: a plain state tree with per-key signals.
3
+ *
4
+ * Each object carries a lazily-grown map of key signals (kept in a WeakMap off the
5
+ * raw target) plus one iteration signal. The proxy intercepts reads so they
6
+ * subscribe at key granularity; the setter writes straight to the raw target and
7
+ * pokes only the keys that changed. Memos stay lazy, effects run eagerly, and
8
+ * batching coalesces updates.
9
+ */
10
+ export { createStore, createMutableStore, createComputedStore, createStoreEffect, createStoreMemo, wrap, unwrap, getStoreNode, isStoreProxy, modifiable, untrackStore, StoreAPI, $RAW, $NODE, $TRACK, $NAME, $STORE, $SELF, Store, isStore, getNode, } from './store.js';
11
+ export type { StoreSetter, StoreAccessor, StoreOptions, Immutable, } from './store.js';
12
+ export { produce as produceUtil, reconcile as reconcileUtil } from './utils.js';
13
+ export type { ReconcileOptions, Producer } from './types.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/store/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,IAAI,EACJ,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,MAAM,EACN,KAAK,EACL,MAAM,EACN,KAAK,EACL,KAAK,EACL,OAAO,EACP,OAAO,GACR,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,WAAW,EACX,aAAa,EACb,YAAY,EACZ,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhF,YAAY,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Fine-grained reactive store: a plain state tree with per-key signals.
3
+ *
4
+ * Each object carries a lazily-grown map of key signals (kept in a WeakMap off the
5
+ * raw target) plus one iteration signal. The proxy intercepts reads so they
6
+ * subscribe at key granularity; the setter writes straight to the raw target and
7
+ * pokes only the keys that changed. Memos stay lazy, effects run eagerly, and
8
+ * batching coalesces updates.
9
+ */
10
+ export { createStore, createMutableStore, createComputedStore, createStoreEffect, createStoreMemo, wrap, unwrap, getStoreNode, isStoreProxy, modifiable, untrackStore, StoreAPI, $RAW, $NODE, $TRACK, $NAME, $STORE, $SELF, Store, isStore, getNode, } from './store.js';
11
+ export { produce as produceUtil, reconcile as reconcileUtil } from './utils.js';
@@ -0,0 +1 @@
1
+ import{$PROXY as h,batch as _,createEffect as d,createMemo as O,createSignal as K,untrack as L}from"@fluixi/reactive/signal";var b=Symbol("store-raw"),u=Symbol("store-node"),U=Symbol("store-has"),x=Symbol("store-self"),g=Symbol("store-track"),X=Symbol("store-name"),k=Symbol("store-store"),$=new WeakMap,R=new WeakMap;function W(e){let[t,r]=K(e),n=t;return n.$=r,n}function T(e){let t=$.get(e);return t||$.set(e,t={keys:new Map}),t}function M(e,t,r){let n=e.keys.get(t);return n||e.keys.set(t,n=W(r)),n}function v(e){let t=T(e);(t.all||(t.all=W()))()}function E(e,t){e.$(typeof t=="function"?()=>t:t)}function C(e){if(e==null||typeof e!="object")return!1;if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function m(e){if(!C(e))return e;let t=R.get(e);if(t)return t;let r=new Proxy(e,q);return R.set(e,r),r}var q={get(e,t,r){if(t===b||t===u)return e;if(t===h)return r;if(t===U)return i=>i in e;if(t==="__proxy")return!0;if(t===g||t===x)return v(e),r;let n=e[t];if(typeof n=="function"&&!Object.prototype.hasOwnProperty.call(e,t))return n;let o=Object.getOwnPropertyDescriptor(e,t);if(o&&o.get)return o.get.call(r);let s=M(T(e),t,n)();return C(s)?m(s):s},set(){return!0},deleteProperty(e,t){return t in e&&f(e,t,void 0),!0},has(e,t){return t===b||t===h||t===u||t===U||t===x||t===g?!0:(M(T(e),t,e[t])(),t in e)},ownKeys(e){return v(e),Reflect.ownKeys(e)},getOwnPropertyDescriptor(e,t){return Reflect.getOwnPropertyDescriptor(e,t)}};function f(e,t,r){if(e[t]===r&&(r!==void 0||t in e))return;let o=Array.isArray(e),s=o?e.length:0;r===void 0?delete e[t]:e[t]=r;let i=T(e),a=i.keys.get(t);if(a&&E(a,r),o&&e.length!==s){let p=i.keys.get("length");p&&E(p,e.length)}i.all&&i.all.$(void 0)}function D(e,t){return typeof e=="function"?e(t):e}function j(e,t){for(let r of Object.keys(t)){let n=t[r],o=e[r];n&&typeof n=="object"&&!Array.isArray(n)&&o&&typeof o=="object"&&!Array.isArray(o)?j(o,n):f(e,r,n)}}function P(e){let t=[],r=e.replace(/\[([^\]]*)\]/g,".$1");for(let n of r.split("."))n.length&&t.push(n);return t}function B(e,t,r){let n=t.length-1;for(let s=0;s<n;s++){let i=t[s];if(i==="*"){let p=t.slice(s+1);if(Array.isArray(e))for(let S=0;S<e.length;S++)B(e[S],p,r);return}let a=e[i];(a==null||typeof a!="object")&&(a=/^\d+$/.test(t[s+1])?[]:{},f(e,i,a)),e=a}let o=t[n];if(o==="*"){if(Array.isArray(e))for(let s=0;s<e.length;s++)f(e,s,D(r,e[s]));return}f(e,o,D(r,e[o]))}function A(e,t,r){B(e,P(t),r)}function Y(e,t){let r=t[0];if(typeof r=="function"&&t.length===1){let n=r(e);n&&n!==e&&j(e,n);return}if(Array.isArray(r)&&t.length===1){for(let n of r)Array.isArray(n)&&A(e,n[0],n[1]);return}if(r&&typeof r=="object"&&!Array.isArray(r)&&t.length===1){j(e,r);return}if(Array.isArray(t[1])&&t.length>=3){A(e,`${r}.${t[1].join(".")}`,t[2]);return}A(e,String(r),t[1])}function I(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(I);let t={};for(let r of Object.keys(e))t[r]=I(e[r]);return t}function y(e,t){let r=e;for(let n of P(t)){if(r==null)return;r=r[n]}return r}var c=class{constructor(t,r={immutable:!0}){this.options=r;this.root=t,this.set=((...n)=>_(()=>Y(this.root,n)))}get state(){return m(this.root)}get proxy(){return m(this.root)}get accessor(){return(()=>m(this.root))}unwrap(){return this.root}getNode(t){return this.root&&this.root[t]}get(t){if(t==null||t==="")return l(this.state);let r=this.state;for(let n of P(t)){if(r==null)return;r=r[n]}return l(r)}select(t){return O(()=>t(this.state))}subscribe(t){return d(()=>t(this.state))}watch(t,r){let n;return d(()=>{let o=t(this.state);Object.is(o,n)||(r(o,n),n=o)})}reactive(t){return O(()=>this.state[t])}produce(t){this.set((r=>{let n=I(r);return t(n),n}))}reconcile(t,r={}){this.set(t)}push(t,...r){let n=y(this.root,t);this.set(t,n.concat(r))}pop(t){let r=y(this.root,t).slice(),n=r.pop();return this.set(t,r),n}shift(t){let r=y(this.root,t).slice(),n=r.shift();return this.set(t,r),n}splice(t,r,n,...o){let s=y(this.root,t).slice(),i=s.splice(r,n,...o);return this.set(t,s),i}insert(t,r,n){let o=y(this.root,t).slice();o.splice(r,0,n),this.set(t,o)}removeAt(t,r){let n=y(this.root,t).slice(),o=n.splice(r,1);return this.set(t,n),o}toObservable(){let[t]=K(this.state);return t.toObservable()}dispose(){}},G=["get","select","watch","subscribe","produce","reconcile","push","pop","shift","splice","insert","removeAt","unwrap","toObservable"];function F(e,t){for(let r of G)e[r]=t[r].bind(t);e.$=t.reactive.bind(t)}function H(e,t={immutable:!0}){let r=new c(e,t);return F(r.set,r),[r.proxy,r.set]}function V(e,t={}){return new c(e,{...t,immutable:!1})}function J(e,t={}){let r=new c(e(),t);return d(()=>r.set(e())),r}function Q(e,t,r){return d(()=>r(t(e)))}function Z(e,t,r){return O(()=>t(e),void 0,r)}function tt(e,t={}){let r=new c(e,t),n=(()=>r.proxy);return F(n,r),n}function l(e){if(e==null||typeof e!="object")return e;let t=e[b];return t!==void 0?t:e}function z(e){return L(()=>l(e))}function et(e){return w(e)}function rt(e){return w(e)?e[u]:null}function nt(e){return e&&typeof e=="object"&&u in e?e[u]:null}function w(e){return!!e&&typeof e=="object"&&(h in e||e.__proxy===!0)}function ot(e){return e}var st=Object.freeze({createStore:H,createMutableStore:V,batch:_,unwrap:l,untrackStore:z});function N(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(N);let t={};for(let r of Object.keys(e))t[r]=N(e[r]);return t}function it(e){return t=>{let r=N(t);return e(r),r}}function at(e,t={}){return()=>e}export{X as $NAME,u as $NODE,b as $RAW,x as $SELF,k as $STORE,g as $TRACK,c as Store,st as StoreAPI,J as createComputedStore,V as createMutableStore,H as createStore,Q as createStoreEffect,Z as createStoreMemo,rt as getNode,nt as getStoreNode,et as isStore,w as isStoreProxy,ot as modifiable,it as produceUtil,at as reconcileUtil,z as untrackStore,l as unwrap,tt as wrap};
@@ -0,0 +1 @@
1
+ "use strict";var a=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var s=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of d(e))!l.call(t,r)&&r!==i&&a(t,r,{get:()=>e[r],enumerable:!(n=o(e,r))||n.enumerable});return t};var T=t=>s(a({},"__esModule",{value:!0}),t);var x={};module.exports=T(x);