@xaendar/core 0.9.30 → 0.9.31
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/dist/signals.d.ts +195 -3
- package/dist/xaendar-core.d.ts +192 -0
- package/package.json +3 -3
package/dist/signals.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { EffectOptions } from '
|
|
2
|
-
import { NoArgsVoidFunction } from '
|
|
3
|
-
import { SignalOptions } from '
|
|
1
|
+
import { EffectOptions } from '@xaendar/signals';
|
|
2
|
+
import { NoArgsVoidFunction } from '@xaendar/types';
|
|
3
|
+
import { SignalOptions } from '@xaendar/signals';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* A read-only reactive value derived from other signals.
|
|
@@ -179,3 +179,195 @@ export { Signal_2 as Signal }
|
|
|
179
179
|
export declare const untracked: typeof Signal.subtle.untrack;
|
|
180
180
|
|
|
181
181
|
export { }
|
|
182
|
+
|
|
183
|
+
declare global {
|
|
184
|
+
namespace Signal {
|
|
185
|
+
/**
|
|
186
|
+
* A mutable Signal that holds a value and notifies dependents when it changes.
|
|
187
|
+
*
|
|
188
|
+
* @template T The type of the value held by this Signal.
|
|
189
|
+
*/
|
|
190
|
+
class State<T = any> {
|
|
191
|
+
/**
|
|
192
|
+
* Creates a new `State` signal.
|
|
193
|
+
*
|
|
194
|
+
* @param initialValue - The initial value of the signal.
|
|
195
|
+
* @param options - Optional configuration:
|
|
196
|
+
* - `equals` — custom equality function; defaults to `Object.is`.
|
|
197
|
+
* - `watched` — called when the signal gains its first sink.
|
|
198
|
+
* - `unwatched` — called when the signal loses its last sink.
|
|
199
|
+
*/
|
|
200
|
+
constructor(value: T, options?: { equals?: (a: T, b: T) => boolean, watched?: () => void, unwatched?: () => void });
|
|
201
|
+
/**
|
|
202
|
+
* Returns the current value of the signal, registering this Signal as a
|
|
203
|
+
* source of the innermost `Computed` currently being evaluated (if any).
|
|
204
|
+
*
|
|
205
|
+
* @throws If `frozen` is `true` — reads are forbidden while a protected
|
|
206
|
+
* callback (`notify`, `watched`, `unwatched`) is executing.
|
|
207
|
+
*/
|
|
208
|
+
get(): T;
|
|
209
|
+
/**
|
|
210
|
+
* Updates the signal's value and propagates changes to all dependent
|
|
211
|
+
* sinks.
|
|
212
|
+
*
|
|
213
|
+
* If `equals(currentValue, newValue)` returns `true` the call is a no-op
|
|
214
|
+
* and no propagation occurs. Otherwise the value is updated, all direct
|
|
215
|
+
* `Computed` sinks are marked dirty, indirect ones checked, and
|
|
216
|
+
* each reachable `Watcher` has its `notify` callback invoked synchronously
|
|
217
|
+
* (with `frozen = true`).
|
|
218
|
+
*
|
|
219
|
+
* @param newValue - The new value to set.
|
|
220
|
+
* @throws If `frozen` is `true` — writes are forbidden while a protected
|
|
221
|
+
* callback is executing.
|
|
222
|
+
*/
|
|
223
|
+
set(newValue: T): void;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* A read-only Signal whose value is derived lazily from other Signals.
|
|
228
|
+
*
|
|
229
|
+
* The value is recomputed only when explicitly read and only if one or more
|
|
230
|
+
* of its (recursive) dependencies have changed since the last evaluation.
|
|
231
|
+
* The result is cached and reused until the Signal becomes stale again.
|
|
232
|
+
*
|
|
233
|
+
* @template T The type of the computed value.
|
|
234
|
+
*/
|
|
235
|
+
class Computed<T = any> {
|
|
236
|
+
/**
|
|
237
|
+
* Creates a new `Computed` signal.
|
|
238
|
+
*
|
|
239
|
+
* The Signal starts in the dirty state with an uninitialised value, so
|
|
240
|
+
* the callback will be invoked on the first `get()`.
|
|
241
|
+
*
|
|
242
|
+
* @param computeFn - Pure function evaluated lazily to produce the value.
|
|
243
|
+
* @param options - Optional configuration:
|
|
244
|
+
* - `equals` — custom equality function; defaults to `Object.is`.
|
|
245
|
+
*/
|
|
246
|
+
constructor(computeFn: () => T, options?: { equals?: (a: T, b: T) => boolean, watched?: () => void, unwatched?: () => void });
|
|
247
|
+
/**
|
|
248
|
+
* Returns the current value of this Signal, re-evaluating the callback if
|
|
249
|
+
* the cached value may be stale.
|
|
250
|
+
*
|
|
251
|
+
* Registers this Signal as a source of any outer `Computed` currently
|
|
252
|
+
* being evaluated (automatic dependency tracking).
|
|
253
|
+
*
|
|
254
|
+
* @returns The current computed value, or a boxed error object if the last
|
|
255
|
+
* evaluation threw.
|
|
256
|
+
* @throws If `frozen` is `true`.
|
|
257
|
+
* @throws If the Signal is in the computing state (cyclic dependency).
|
|
258
|
+
*/
|
|
259
|
+
get(): T | { isError: true, value: Error };
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
namespace subtle {
|
|
263
|
+
/**
|
|
264
|
+
* Executes a function without tracking any dependencies.
|
|
265
|
+
* @param fn - The function to execute without tracking.
|
|
266
|
+
* @returns The result of the function execution.
|
|
267
|
+
*/
|
|
268
|
+
function untrack<T>(fn: () => T): T;
|
|
269
|
+
/**
|
|
270
|
+
* Returns the currently active `Computed` instance being evaluated, or `null`.
|
|
271
|
+
* @returns The currently active `Computed` instance, or `null` if none is being evaluated.
|
|
272
|
+
*/
|
|
273
|
+
function currentComputed(): Computed | null;
|
|
274
|
+
/**
|
|
275
|
+
* Returns the ordered list of all Signals which the given `Computed` or
|
|
276
|
+
* `Watcher` referenced during its last evaluation.
|
|
277
|
+
*
|
|
278
|
+
* - For a `Computed`, these are the Signals read inside its callback.
|
|
279
|
+
* - For a `Watcher`, these are the Signals it is currently watching.
|
|
280
|
+
*
|
|
281
|
+
* @param s - The `Computed` or `Watcher` to introspect.
|
|
282
|
+
* @returns An array of `State` and `Computed` instances.
|
|
283
|
+
*/
|
|
284
|
+
function introspectSources(s: Computed | Watcher): (State | Computed)[];
|
|
285
|
+
/**
|
|
286
|
+
* Returns the direct dependents of the given Signal — Watchers that contain
|
|
287
|
+
* it, plus any `Computed` Signals which read it during their last evaluation
|
|
288
|
+
* (if that `Computed` is recursively watched).
|
|
289
|
+
*
|
|
290
|
+
* @param signal - The `State` or `Computed` Signal to introspect.
|
|
291
|
+
* @returns An array of `Computed` and `Watcher` instances.
|
|
292
|
+
*/
|
|
293
|
+
function introspectSinks(signal: State | Computed): (Computed | Watcher)[];
|
|
294
|
+
/**
|
|
295
|
+
* Returns `true` if the given Signal is 'live' — i.e. it is watched by a
|
|
296
|
+
* `Watcher`, or it is read by a `Computed` Signal which is (recursively)
|
|
297
|
+
* live.
|
|
298
|
+
*
|
|
299
|
+
* @param signal - The `State` or `Computed` Signal to check.
|
|
300
|
+
* @returns `true` if the Signal has at least one sink.
|
|
301
|
+
*/
|
|
302
|
+
function hasSinks(signal: State | Computed): boolean;
|
|
303
|
+
/**
|
|
304
|
+
* Returns `true` if the given node is 'reactive' — i.e. it depends on some
|
|
305
|
+
* other Signal. A `Computed` where `hasSources` is `false` will always
|
|
306
|
+
* return the same constant.
|
|
307
|
+
*
|
|
308
|
+
* @param s - The `Computed` or `Watcher` to check.
|
|
309
|
+
* @returns `true` if the node has at least one source.
|
|
310
|
+
*/
|
|
311
|
+
function hasSources(s: Computed | Watcher): boolean;
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* A `Watcher` observes a set of Signals and fires a `notify` callback
|
|
315
|
+
* synchronously when any of their (recursive) dependencies change.
|
|
316
|
+
*
|
|
317
|
+
* It is the low-level primitive on top of which frameworks implement
|
|
318
|
+
* effects and scheduling. It does not hold a value and has no generic
|
|
319
|
+
* type parameter.
|
|
320
|
+
*/
|
|
321
|
+
class Watcher {
|
|
322
|
+
/**
|
|
323
|
+
* Creates a new Watcher.
|
|
324
|
+
*
|
|
325
|
+
* The Watcher starts in the waiting state with an empty signals set.
|
|
326
|
+
*
|
|
327
|
+
* @param notify - Called synchronously (with `frozen = true`) the
|
|
328
|
+
* first time a watched dependency changes after each `watch` call. No
|
|
329
|
+
* Signals may be read or written inside this callback.
|
|
330
|
+
*/
|
|
331
|
+
constructor(notify: () => void);
|
|
332
|
+
/**
|
|
333
|
+
* Adds the given Signals to the watched set and transitions the Watcher to
|
|
334
|
+
* the watching state.
|
|
335
|
+
*
|
|
336
|
+
* For each newly-watched Signal, the Watcher is registered as a sink and —
|
|
337
|
+
* if it is the first sink — the sink registration is propagated recursively
|
|
338
|
+
* up through the Signal's sources, building the live dependency chain.
|
|
339
|
+
*
|
|
340
|
+
* @param signals - One or more Signals to start watching.
|
|
341
|
+
* @throws If `frozen` is `true` at the time of the call.
|
|
342
|
+
*/
|
|
343
|
+
watch(...signals: (State | Computed)[]): void;
|
|
344
|
+
/**
|
|
345
|
+
* Removes the given Signals from the watched set.
|
|
346
|
+
*
|
|
347
|
+
* For each removed Signal, the Watcher is unregistered as a sink. If the
|
|
348
|
+
* Signal's sink set becomes empty as a result, the removal is propagated
|
|
349
|
+
* recursively up through its sources, tearing down the live dependency
|
|
350
|
+
* chain and allowing garbage collection of unwatched nodes.
|
|
351
|
+
*
|
|
352
|
+
* @param signals - One or more Signals to stop watching.
|
|
353
|
+
* @throws If `frozen` is `true` at the time of the call.
|
|
354
|
+
* @throws If any of the given Signals is not currently being watched.
|
|
355
|
+
*/
|
|
356
|
+
unwatch(...signals: (State | Computed)[]): void;
|
|
357
|
+
/**
|
|
358
|
+
* Returns the subset of watched Signals that are `Computed` instances
|
|
359
|
+
* currently in a `~dirty~` or `~checked~` state, meaning they may have a
|
|
360
|
+
* stale value that has not yet been re-evaluated.
|
|
361
|
+
*
|
|
362
|
+
* Typically called inside the microtask scheduled by the `notify` callback
|
|
363
|
+
* to know which Signals need to be pulled.
|
|
364
|
+
*
|
|
365
|
+
* @returns An array of `Computed` signals that are dirty or checked.
|
|
366
|
+
*
|
|
367
|
+
* @see Signal algorithms — 'Method: Signal.subtle.Watcher.prototype.getPending()'
|
|
368
|
+
*/
|
|
369
|
+
getPending(): Computed<unknown>[];
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
package/dist/xaendar-core.d.ts
CHANGED
|
@@ -652,3 +652,195 @@ export declare type WebComponentDecoratorParams = {
|
|
|
652
652
|
};
|
|
653
653
|
|
|
654
654
|
export { }
|
|
655
|
+
|
|
656
|
+
declare global {
|
|
657
|
+
namespace Signal {
|
|
658
|
+
/**
|
|
659
|
+
* A mutable Signal that holds a value and notifies dependents when it changes.
|
|
660
|
+
*
|
|
661
|
+
* @template T The type of the value held by this Signal.
|
|
662
|
+
*/
|
|
663
|
+
class State<T = any> {
|
|
664
|
+
/**
|
|
665
|
+
* Creates a new `State` signal.
|
|
666
|
+
*
|
|
667
|
+
* @param initialValue - The initial value of the signal.
|
|
668
|
+
* @param options - Optional configuration:
|
|
669
|
+
* - `equals` — custom equality function; defaults to `Object.is`.
|
|
670
|
+
* - `watched` — called when the signal gains its first sink.
|
|
671
|
+
* - `unwatched` — called when the signal loses its last sink.
|
|
672
|
+
*/
|
|
673
|
+
constructor(value: T, options?: { equals?: (a: T, b: T) => boolean, watched?: () => void, unwatched?: () => void });
|
|
674
|
+
/**
|
|
675
|
+
* Returns the current value of the signal, registering this Signal as a
|
|
676
|
+
* source of the innermost `Computed` currently being evaluated (if any).
|
|
677
|
+
*
|
|
678
|
+
* @throws If `frozen` is `true` — reads are forbidden while a protected
|
|
679
|
+
* callback (`notify`, `watched`, `unwatched`) is executing.
|
|
680
|
+
*/
|
|
681
|
+
get(): T;
|
|
682
|
+
/**
|
|
683
|
+
* Updates the signal's value and propagates changes to all dependent
|
|
684
|
+
* sinks.
|
|
685
|
+
*
|
|
686
|
+
* If `equals(currentValue, newValue)` returns `true` the call is a no-op
|
|
687
|
+
* and no propagation occurs. Otherwise the value is updated, all direct
|
|
688
|
+
* `Computed` sinks are marked dirty, indirect ones checked, and
|
|
689
|
+
* each reachable `Watcher` has its `notify` callback invoked synchronously
|
|
690
|
+
* (with `frozen = true`).
|
|
691
|
+
*
|
|
692
|
+
* @param newValue - The new value to set.
|
|
693
|
+
* @throws If `frozen` is `true` — writes are forbidden while a protected
|
|
694
|
+
* callback is executing.
|
|
695
|
+
*/
|
|
696
|
+
set(newValue: T): void;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* A read-only Signal whose value is derived lazily from other Signals.
|
|
701
|
+
*
|
|
702
|
+
* The value is recomputed only when explicitly read and only if one or more
|
|
703
|
+
* of its (recursive) dependencies have changed since the last evaluation.
|
|
704
|
+
* The result is cached and reused until the Signal becomes stale again.
|
|
705
|
+
*
|
|
706
|
+
* @template T The type of the computed value.
|
|
707
|
+
*/
|
|
708
|
+
class Computed<T = any> {
|
|
709
|
+
/**
|
|
710
|
+
* Creates a new `Computed` signal.
|
|
711
|
+
*
|
|
712
|
+
* The Signal starts in the dirty state with an uninitialised value, so
|
|
713
|
+
* the callback will be invoked on the first `get()`.
|
|
714
|
+
*
|
|
715
|
+
* @param computeFn - Pure function evaluated lazily to produce the value.
|
|
716
|
+
* @param options - Optional configuration:
|
|
717
|
+
* - `equals` — custom equality function; defaults to `Object.is`.
|
|
718
|
+
*/
|
|
719
|
+
constructor(computeFn: () => T, options?: { equals?: (a: T, b: T) => boolean, watched?: () => void, unwatched?: () => void });
|
|
720
|
+
/**
|
|
721
|
+
* Returns the current value of this Signal, re-evaluating the callback if
|
|
722
|
+
* the cached value may be stale.
|
|
723
|
+
*
|
|
724
|
+
* Registers this Signal as a source of any outer `Computed` currently
|
|
725
|
+
* being evaluated (automatic dependency tracking).
|
|
726
|
+
*
|
|
727
|
+
* @returns The current computed value, or a boxed error object if the last
|
|
728
|
+
* evaluation threw.
|
|
729
|
+
* @throws If `frozen` is `true`.
|
|
730
|
+
* @throws If the Signal is in the computing state (cyclic dependency).
|
|
731
|
+
*/
|
|
732
|
+
get(): T | { isError: true, value: Error };
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
namespace subtle {
|
|
736
|
+
/**
|
|
737
|
+
* Executes a function without tracking any dependencies.
|
|
738
|
+
* @param fn - The function to execute without tracking.
|
|
739
|
+
* @returns The result of the function execution.
|
|
740
|
+
*/
|
|
741
|
+
function untrack<T>(fn: () => T): T;
|
|
742
|
+
/**
|
|
743
|
+
* Returns the currently active `Computed` instance being evaluated, or `null`.
|
|
744
|
+
* @returns The currently active `Computed` instance, or `null` if none is being evaluated.
|
|
745
|
+
*/
|
|
746
|
+
function currentComputed(): Computed | null;
|
|
747
|
+
/**
|
|
748
|
+
* Returns the ordered list of all Signals which the given `Computed` or
|
|
749
|
+
* `Watcher` referenced during its last evaluation.
|
|
750
|
+
*
|
|
751
|
+
* - For a `Computed`, these are the Signals read inside its callback.
|
|
752
|
+
* - For a `Watcher`, these are the Signals it is currently watching.
|
|
753
|
+
*
|
|
754
|
+
* @param s - The `Computed` or `Watcher` to introspect.
|
|
755
|
+
* @returns An array of `State` and `Computed` instances.
|
|
756
|
+
*/
|
|
757
|
+
function introspectSources(s: Computed | Watcher): (State | Computed)[];
|
|
758
|
+
/**
|
|
759
|
+
* Returns the direct dependents of the given Signal — Watchers that contain
|
|
760
|
+
* it, plus any `Computed` Signals which read it during their last evaluation
|
|
761
|
+
* (if that `Computed` is recursively watched).
|
|
762
|
+
*
|
|
763
|
+
* @param signal - The `State` or `Computed` Signal to introspect.
|
|
764
|
+
* @returns An array of `Computed` and `Watcher` instances.
|
|
765
|
+
*/
|
|
766
|
+
function introspectSinks(signal: State | Computed): (Computed | Watcher)[];
|
|
767
|
+
/**
|
|
768
|
+
* Returns `true` if the given Signal is 'live' — i.e. it is watched by a
|
|
769
|
+
* `Watcher`, or it is read by a `Computed` Signal which is (recursively)
|
|
770
|
+
* live.
|
|
771
|
+
*
|
|
772
|
+
* @param signal - The `State` or `Computed` Signal to check.
|
|
773
|
+
* @returns `true` if the Signal has at least one sink.
|
|
774
|
+
*/
|
|
775
|
+
function hasSinks(signal: State | Computed): boolean;
|
|
776
|
+
/**
|
|
777
|
+
* Returns `true` if the given node is 'reactive' — i.e. it depends on some
|
|
778
|
+
* other Signal. A `Computed` where `hasSources` is `false` will always
|
|
779
|
+
* return the same constant.
|
|
780
|
+
*
|
|
781
|
+
* @param s - The `Computed` or `Watcher` to check.
|
|
782
|
+
* @returns `true` if the node has at least one source.
|
|
783
|
+
*/
|
|
784
|
+
function hasSources(s: Computed | Watcher): boolean;
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* A `Watcher` observes a set of Signals and fires a `notify` callback
|
|
788
|
+
* synchronously when any of their (recursive) dependencies change.
|
|
789
|
+
*
|
|
790
|
+
* It is the low-level primitive on top of which frameworks implement
|
|
791
|
+
* effects and scheduling. It does not hold a value and has no generic
|
|
792
|
+
* type parameter.
|
|
793
|
+
*/
|
|
794
|
+
class Watcher {
|
|
795
|
+
/**
|
|
796
|
+
* Creates a new Watcher.
|
|
797
|
+
*
|
|
798
|
+
* The Watcher starts in the waiting state with an empty signals set.
|
|
799
|
+
*
|
|
800
|
+
* @param notify - Called synchronously (with `frozen = true`) the
|
|
801
|
+
* first time a watched dependency changes after each `watch` call. No
|
|
802
|
+
* Signals may be read or written inside this callback.
|
|
803
|
+
*/
|
|
804
|
+
constructor(notify: () => void);
|
|
805
|
+
/**
|
|
806
|
+
* Adds the given Signals to the watched set and transitions the Watcher to
|
|
807
|
+
* the watching state.
|
|
808
|
+
*
|
|
809
|
+
* For each newly-watched Signal, the Watcher is registered as a sink and —
|
|
810
|
+
* if it is the first sink — the sink registration is propagated recursively
|
|
811
|
+
* up through the Signal's sources, building the live dependency chain.
|
|
812
|
+
*
|
|
813
|
+
* @param signals - One or more Signals to start watching.
|
|
814
|
+
* @throws If `frozen` is `true` at the time of the call.
|
|
815
|
+
*/
|
|
816
|
+
watch(...signals: (State | Computed)[]): void;
|
|
817
|
+
/**
|
|
818
|
+
* Removes the given Signals from the watched set.
|
|
819
|
+
*
|
|
820
|
+
* For each removed Signal, the Watcher is unregistered as a sink. If the
|
|
821
|
+
* Signal's sink set becomes empty as a result, the removal is propagated
|
|
822
|
+
* recursively up through its sources, tearing down the live dependency
|
|
823
|
+
* chain and allowing garbage collection of unwatched nodes.
|
|
824
|
+
*
|
|
825
|
+
* @param signals - One or more Signals to stop watching.
|
|
826
|
+
* @throws If `frozen` is `true` at the time of the call.
|
|
827
|
+
* @throws If any of the given Signals is not currently being watched.
|
|
828
|
+
*/
|
|
829
|
+
unwatch(...signals: (State | Computed)[]): void;
|
|
830
|
+
/**
|
|
831
|
+
* Returns the subset of watched Signals that are `Computed` instances
|
|
832
|
+
* currently in a `~dirty~` or `~checked~` state, meaning they may have a
|
|
833
|
+
* stale value that has not yet been re-evaluated.
|
|
834
|
+
*
|
|
835
|
+
* Typically called inside the microtask scheduled by the `notify` callback
|
|
836
|
+
* to know which Signals need to be pulled.
|
|
837
|
+
*
|
|
838
|
+
* @returns An array of `Computed` signals that are dirty or checked.
|
|
839
|
+
*
|
|
840
|
+
* @see Signal algorithms — 'Method: Signal.subtle.Watcher.prototype.getPending()'
|
|
841
|
+
*/
|
|
842
|
+
getPending(): Computed<unknown>[];
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xaendar/core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.31",
|
|
4
4
|
"description": "A library containing core utils such as webcomponent base classes and theming support",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@xaendar/signals": "0.9.
|
|
26
|
-
"@xaendar/types": "0.9.
|
|
25
|
+
"@xaendar/signals": "0.9.31",
|
|
26
|
+
"@xaendar/types": "0.9.31"
|
|
27
27
|
}
|
|
28
28
|
}
|