@ersbeth/picoflow 2.3.1 → 3.0.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 (70) hide show
  1. package/README.md +37 -12
  2. package/SKILL.md +130 -16
  3. package/dist/index.d.ts +767 -0
  4. package/dist/index.js +544 -0
  5. package/dist/inspect.d.ts +252 -0
  6. package/dist/inspect.js +300 -0
  7. package/dist/shared.d.ts +361 -0
  8. package/dist/shared.js +1496 -0
  9. package/dist/shared2.d.ts +93 -0
  10. package/dist/shared2.js +59 -0
  11. package/dist/shared3.d.ts +54 -0
  12. package/dist/shared3.js +17 -0
  13. package/dist/{types/converters/solid.d.ts → solid.d.ts} +10 -8
  14. package/dist/solid.js +63 -0
  15. package/package.json +38 -34
  16. package/dist/picoflow.js +0 -1283
  17. package/dist/types/api/base/flowConfig.d.ts +0 -17
  18. package/dist/types/api/base/flowDisposable.d.ts +0 -40
  19. package/dist/types/api/base/flowErrors.d.ts +0 -1
  20. package/dist/types/api/base/flowObservable.d.ts +0 -26
  21. package/dist/types/api/base/flowPrimitiveOptions.d.ts +0 -14
  22. package/dist/types/api/base/flowSubscribable.d.ts +0 -78
  23. package/dist/types/api/base/flowTracker.d.ts +0 -7
  24. package/dist/types/api/base/index.d.ts +0 -7
  25. package/dist/types/api/index.d.ts +0 -2
  26. package/dist/types/api/nodes/async/flowConstantAsync.d.ts +0 -32
  27. package/dist/types/api/nodes/async/flowDerivationAsync.d.ts +0 -37
  28. package/dist/types/api/nodes/async/flowStateAsync.d.ts +0 -42
  29. package/dist/types/api/nodes/async/flowWritableDerivationAsync.d.ts +0 -31
  30. package/dist/types/api/nodes/async/index.d.ts +0 -4
  31. package/dist/types/api/nodes/collections/flowArray.d.ts +0 -138
  32. package/dist/types/api/nodes/collections/flowMap.d.ts +0 -100
  33. package/dist/types/api/nodes/collections/index.d.ts +0 -2
  34. package/dist/types/api/nodes/flowEffect.d.ts +0 -28
  35. package/dist/types/api/nodes/flowSignal.d.ts +0 -26
  36. package/dist/types/api/nodes/flowValue.d.ts +0 -35
  37. package/dist/types/api/nodes/index.d.ts +0 -7
  38. package/dist/types/api/nodes/sync/flowConstant.d.ts +0 -30
  39. package/dist/types/api/nodes/sync/flowDerivation.d.ts +0 -37
  40. package/dist/types/api/nodes/sync/flowState.d.ts +0 -40
  41. package/dist/types/api/nodes/sync/flowWritableDerivation.d.ts +0 -29
  42. package/dist/types/api/nodes/sync/index.d.ts +0 -4
  43. package/dist/types/api/nodes/utils.d.ts +0 -22
  44. package/dist/types/base/dependenciesRegistry.d.ts +0 -1
  45. package/dist/types/base/dependentsRegistry.d.ts +0 -1
  46. package/dist/types/base/disposable.d.ts +0 -15
  47. package/dist/types/base/errors.d.ts +0 -31
  48. package/dist/types/base/executionStack.d.ts +0 -31
  49. package/dist/types/base/index.d.ts +0 -8
  50. package/dist/types/base/node.d.ts +0 -27
  51. package/dist/types/base/observable.d.ts +0 -34
  52. package/dist/types/base/observer.d.ts +0 -33
  53. package/dist/types/converters/index.d.ts +0 -1
  54. package/dist/types/index.d.ts +0 -2
  55. package/dist/types/nodes/actionNode.d.ts +0 -1
  56. package/dist/types/nodes/arrayNode.d.ts +0 -1
  57. package/dist/types/nodes/effectNode.d.ts +0 -1
  58. package/dist/types/nodes/index.d.ts +0 -8
  59. package/dist/types/nodes/mapNode.d.ts +0 -1
  60. package/dist/types/nodes/signalNode.d.ts +0 -1
  61. package/dist/types/nodes/valueAsyncNode.d.ts +0 -1
  62. package/dist/types/nodes/valueNode.d.ts +0 -1
  63. package/dist/types/nodes/valueSyncNode.d.ts +0 -1
  64. package/dist/types/schedulers/asyncResolver.d.ts +0 -1
  65. package/dist/types/schedulers/asyncScheduler.d.ts +0 -1
  66. package/dist/types/schedulers/index.d.ts +0 -4
  67. package/dist/types/schedulers/pendingError.d.ts +0 -1
  68. package/dist/types/schedulers/scheduler.d.ts +0 -1
  69. package/dist/types/schedulers/syncResolver.d.ts +0 -1
  70. package/dist/types/schedulers/syncScheduler.d.ts +0 -1
@@ -1,17 +0,0 @@
1
- /**
2
- * Installs a global handler for errors that escape the reactive flush.
3
- *
4
- * All reactive work — recomputing derivations, running effects — happens inside an
5
- * asynchronous flush. Without this hook, an error escaping the flush (an effect callback
6
- * that throws with no `onError`, or a feedback loop between two effects) becomes an
7
- * uncaught exception, which terminates a Node process. Installing a handler here makes
8
- * that error catchable instead.
9
- *
10
- * Defaults to `console.error`. The handler replaces any previously installed handler —
11
- * it is not additive.
12
- *
13
- * @param handler - Called with the error that escaped the flush.
14
- *
15
- * @public
16
- */
17
- export declare function onFlushError(handler: (error: unknown) => void): void;
@@ -1,40 +0,0 @@
1
- /**
2
- * Contract for resources that can be explicitly released to prevent memory leaks.
3
- *
4
- * All reactive primitives in PicoFlow implement this interface, allowing manual cleanup of subscriptions
5
- * and dependencies. Once disposed, the resource cannot be reused and will throw errors on further access.
6
- * Call `dispose()` when you no longer need a reactive primitive to free its resources.
7
- *
8
- * @public
9
- */
10
- export interface FlowDisposable {
11
- /**
12
- * Indicates whether this resource has been disposed.
13
- *
14
- * Returns `true` if `dispose()` has been called, `false` otherwise. Once disposed,
15
- * the resource is no longer usable and any operations on it will throw errors.
16
- */
17
- get disposed(): boolean;
18
- /**
19
- * Releases all resources held by this disposable object.
20
- *
21
- * Cleans up all subscriptions, dependencies, and internal state. After calling this method,
22
- * the resource enters a disposed state and cannot be reused. Any subsequent operations will
23
- * throw errors. This method should be called when you no longer need the reactive primitive
24
- * to prevent memory leaks.
25
- */
26
- dispose(): void;
27
- }
28
- /**
29
- * Type guard to check if an object implements the FlowDisposable interface.
30
- *
31
- * Useful for conditionally disposing objects that may or may not be disposable,
32
- * such as when cleaning up mixed collections of values. Returns true if the object
33
- * has a `dispose` method, providing type-safe access to disposal functionality.
34
- *
35
- * @param obj - The object to check
36
- * @returns True if the object implements FlowDisposable, false otherwise
37
- *
38
- * @public
39
- */
40
- export declare function isDisposable(obj: unknown): obj is FlowDisposable;
@@ -1 +0,0 @@
1
- export { PicoFlowCycleError, PicoFlowDisposedError, PicoFlowError, PicoFlowInternalError } from '../../base/errors.js';
@@ -1,26 +0,0 @@
1
- import { FlowDisposable } from './flowDisposable.js';
2
- import { FlowSubscribable } from './flowSubscribable.js';
3
- import { FlowTracker } from './flowTracker.js';
4
- /**
5
- * Contract for reactive primitives that emit changes and notify their dependents in the reactivity graph.
6
- * @public
7
- */
8
- export interface FlowObservable<T> extends FlowDisposable, FlowSubscribable<T> {
9
- /**
10
- * Establishes a reactive dependency without reading the value.
11
- *
12
- * Registers this observable as a dependency of the given tracker, allowing it to be notified
13
- * when changes occur. This enables dependency tracking without accessing the actual value.
14
- *
15
- * @param tracker - Tracker that records this observable as a dependency
16
- */
17
- watch(tracker: FlowTracker): void;
18
- /**
19
- * Manually triggers notifications to all dependents.
20
- *
21
- * Forces all dependents of this observable to be notified and re-executed, even if the
22
- * value hasn't actually changed. Useful for imperatively triggering updates when the
23
- * reactive system cannot detect changes automatically.
24
- */
25
- trigger(): void;
26
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * Optional per-instance settings accepted by the primitive factories (`state`, `derivation`,
3
- * `array`, `map`, `signal`, …).
4
- *
5
- * @public
6
- */
7
- export interface FlowPrimitiveOptions {
8
- /**
9
- * Identifies this primitive in error messages, e.g. `"[PicoFlow] Primitive \"$count\" is disposed"`
10
- * instead of the unnamed `"[PicoFlow] Primitive is disposed"`. Purely diagnostic — has no effect
11
- * on reactive behavior.
12
- */
13
- name?: string;
14
- }
@@ -1,78 +0,0 @@
1
- import { FlowEffect } from '../nodes/flowEffect.js';
2
- import { FlowTracker } from './flowTracker.js';
3
- /**
4
- * Function that tracks reactive dependencies and returns data.
5
- *
6
- * This function is called during effect execution with a tracker parameter that automatically
7
- * records any reactive values accessed. The tracker enables automatic dependency tracking without
8
- * explicit subscriptions. The returned data is passed to the `onData` callback.
9
- *
10
- * @param t - Tracker object that records dependencies when reactive values are accessed
11
- * @returns The computed data of type T
12
- *
13
- * @public
14
- */
15
- export type FlowDataTracker<T> = (t: FlowTracker) => T;
16
- /**
17
- * Callback invoked when new data is available.
18
- *
19
- * This callback runs each time the effect executes successfully, receiving the data returned
20
- * by the tracker function. It's called immediately on effect creation and then on every reactive
21
- * re-execution. Use this callback to perform side effects with the computed data.
22
- *
23
- * @param data - The computed data from the tracker function
24
- * @returns Always returns undefined (callbacks are for side effects)
25
- *
26
- * @public
27
- */
28
- export type FlowOnDataListener<T> = (data: T) => void;
29
- /**
30
- * Callback invoked when an error occurs during effect execution.
31
- *
32
- * If provided, this callback handles any errors thrown by the tracker function (except PendingError).
33
- * Without this callback, errors propagate and may crash the application. Use this for error logging,
34
- * recovery, or user feedback. The effect remains active and will retry on the next reactive trigger.
35
- *
36
- * @param error - The error that occurred, always normalized to an Error instance
37
- * @returns Always returns undefined (callbacks are for side effects)
38
- *
39
- * @public
40
- */
41
- export type FlowOnErrorListener = (error: Error) => void;
42
- /**
43
- * Callback invoked when an async computation is pending.
44
- *
45
- * This callback is triggered when the tracker function throws a PendingError, indicating that
46
- * async dependencies are still resolving. Use this to show loading states or pending indicators.
47
- * The effect will automatically re-execute once the async values settle.
48
- *
49
- * @returns Always returns undefined (callbacks are for side effects)
50
- *
51
- * @public
52
- */
53
- export type FlowOnPendingListener = () => void;
54
- /**
55
- * Contract for observables that can be subscribed to with lifecycle callbacks.
56
- *
57
- * This interface enables imperative subscription to reactive values, allowing manual control over
58
- * when effects run. The subscribe method returns a disposal function to stop the subscription.
59
- * Useful for integrating with non-reactive code or frameworks that manage subscriptions differently.
60
- *
61
- * @public
62
- */
63
- export interface FlowSubscribable<T> {
64
- /**
65
- * Subscribes to this observable with lifecycle callbacks.
66
- *
67
- * Creates an active subscription that executes immediately and then re-executes whenever
68
- * the observable's dependencies change. The subscription remains active until the returned
69
- * disposal function is called. The `onData` callback receives the computed value, while
70
- * `onError` handles errors and `onPending` signals async operations in progress.
71
- *
72
- * @param onData - Callback invoked with the computed data on each execution
73
- * @param onError - Optional callback for handling errors during execution
74
- * @param onPending - Optional callback invoked when async dependencies are pending
75
- * @returns A function to dispose the subscription and stop receiving updates
76
- */
77
- subscribe(onData: FlowOnDataListener<T>, onError?: FlowOnErrorListener, onPending?: FlowOnPendingListener): FlowEffect;
78
- }
@@ -1,7 +0,0 @@
1
- import { FlowDisposable } from './flowDisposable.js';
2
- /**
3
- * Contract for reactive computations that track dependencies and react to changes in the reactivity graph.
4
- * @public
5
- */
6
- export interface FlowTracker extends FlowDisposable {
7
- }
@@ -1,7 +0,0 @@
1
- export * from './flowConfig.js';
2
- export * from './flowDisposable.js';
3
- export * from './flowErrors.js';
4
- export * from './flowObservable.js';
5
- export * from './flowPrimitiveOptions.js';
6
- export * from './flowSubscribable.js';
7
- export * from './flowTracker.js';
@@ -1,2 +0,0 @@
1
- export * from './base/index.js';
2
- export * from './nodes/index.js';
@@ -1,32 +0,0 @@
1
- import { FlowPrimitiveOptions } from '../../base/flowPrimitiveOptions.js';
2
- import { FlowValue } from '../flowValue.js';
3
- /** Function that initializes a value asynchronously. */
4
- export type InitFunctionAsync<T> = () => Promise<T>;
5
- /**
6
- * Read-only reactive value that resolves once from a promise or async initializer.
7
- *
8
- * Async constants provide lazy initialization for asynchronous values. The promise or async initializer
9
- * runs once on first access, and the resolved value is cached forever. While pending, accessing the value
10
- * throws PendingError. Use for async operations that only need to run once, such as loading remote configuration,
11
- * fetching initial data, or computing expensive async resources.
12
- *
13
- * @public
14
- */
15
- export interface FlowConstantAsync<T> extends FlowValue<T> {
16
- }
17
- /**
18
- * Creates a constant reactive value from a promise or async initializer that resolves once and never recomputes.
19
- *
20
- * The promise or async initializer executes once on first access, and the resolved value is cached permanently.
21
- * While the promise is pending, any reactive computation that accesses the value will receive PendingError and
22
- * automatically retry once the promise resolves. Use for one-time async operations that don't depend on other
23
- * reactive values, such as loading configuration or fetching initial data.
24
- *
25
- * @param value - Promise to resolve, or async function that returns a promise on first access
26
- * @param options - Optional settings; `name` identifies this primitive in error messages
27
- * @returns A FlowConstantAsync that provides read-only access to the resolved value
28
- *
29
- * @public
30
- */
31
- export declare function constantAsync<T>(value: Promise<T>, options?: FlowPrimitiveOptions): FlowConstantAsync<T>;
32
- export declare function constantAsync<T>(initializer: InitFunctionAsync<T>, options?: FlowPrimitiveOptions): FlowConstantAsync<T>;
@@ -1,37 +0,0 @@
1
- import { FlowPrimitiveOptions, FlowTracker } from '../../base/index.js';
2
- import { FlowValue } from '../flowValue.js';
3
- import { NotPromise } from '../utils.js';
4
- /** Function that derives a value asynchronously from dependencies and optionally the previous value. */
5
- export type DerivationFunctionAsync<T> = (tracker: FlowTracker, previous?: NotPromise<T> | undefined) => Promise<T>;
6
- /**
7
- * Read-only reactive value that recomputes asynchronously when dependencies change.
8
- *
9
- * Async derivations track reactive values accessed during computation and automatically recompute when any
10
- * tracked dependency changes. The compute function returns a promise, and the resolved value is cached until
11
- * dependencies change. While recomputing, accessing the value throws PendingError. Use for values derived from
12
- * async operations like API calls, database queries, or any computation that depends on reactive state and
13
- * requires async work.
14
- *
15
- * @public
16
- */
17
- export interface FlowDerivationAsync<T> extends FlowValue<T> {
18
- /**
19
- * Forces the derivation to recompute even if dependencies haven't changed.
20
- */
21
- refresh(): void;
22
- }
23
- /**
24
- * Creates an async derived value that automatically recomputes when dependencies change.
25
- *
26
- * The async compute function tracks dependencies and returns a promise. When any tracked dependency changes,
27
- * the function runs again and returns a new promise. The resolved value is cached until the next change.
28
- * While the promise is pending, reactive computations that access this value receive PendingError and automatically
29
- * retry once resolved. Use for derived data from async sources like filtered API results or computed database queries.
30
- *
31
- * @param compute - Async function that accesses dependencies and returns a promise of the derived value
32
- * @param options - Optional settings; `name` identifies this primitive in error messages
33
- * @returns A FlowDerivationAsync that provides read-only access to the resolved computed value
34
- *
35
- * @public
36
- */
37
- export declare function derivationAsync<T>(compute: DerivationFunctionAsync<T>, options?: FlowPrimitiveOptions): FlowDerivationAsync<T>;
@@ -1,42 +0,0 @@
1
- import { FlowPrimitiveOptions } from '../../base/flowPrimitiveOptions.js';
2
- import { FlowValue } from '../flowValue.js';
3
- import { NotPromise } from '../utils.js';
4
- import { InitFunctionAsync } from './flowConstantAsync.js';
5
- /** Function that updates a value asynchronously based on the previous value. */
6
- export type UpdateFunctionAsync<T> = (previous: NotPromise<T> | undefined) => Promise<T>;
7
- /**
8
- * Writable reactive value that resolves promises and can be updated with new promises.
9
- *
10
- * Async state is the async equivalent of regular state. Unlike sync state, it accepts promises instead of
11
- * direct values. Set new promises or async updater functions to update the state. While a promise is pending,
12
- * accessing the value throws PendingError. Use for async data that changes imperatively, such as user-triggered
13
- * API calls, async form submissions, or any async operation that updates based on user actions.
14
- *
15
- * @public
16
- */
17
- export interface FlowStateAsync<T> extends FlowValue<T> {
18
- /**
19
- * Updates the state with a new promise or via an async updater function.
20
- * Notifies all dependents immediately (they will receive PendingError until resolved).
21
- *
22
- * @param promise - New promise to resolve, or async function that receives current value and returns a promise
23
- */
24
- set(promise: Promise<T>): void;
25
- set(updater: UpdateFunctionAsync<T>): void;
26
- }
27
- /**
28
- * Creates a mutable async reactive state that resolves promises and can be updated imperatively.
29
- *
30
- * State can be initialized with a direct promise or a lazy async initializer function. Update the state by
31
- * calling `set()` with a new promise or an async updater function. Changes propagate automatically to all
32
- * reactive computations that depend on this state. Use for async data that changes through user actions or
33
- * application logic, such as loading user profiles, fetching search results, or any async state updates.
34
- *
35
- * @param value - Initial promise to resolve, or lazy async initializer function
36
- * @param options - Optional settings; `name` identifies this primitive in error messages
37
- * @returns A FlowStateAsync that can be read and modified with promises
38
- *
39
- * @public
40
- */
41
- export declare function stateAsync<T>(value: Promise<T>, options?: FlowPrimitiveOptions): FlowStateAsync<T>;
42
- export declare function stateAsync<T>(initializer: InitFunctionAsync<T>, options?: FlowPrimitiveOptions): FlowStateAsync<T>;
@@ -1,31 +0,0 @@
1
- import { FlowPrimitiveOptions } from '../../base/flowPrimitiveOptions.js';
2
- import { DerivationFunctionAsync, FlowDerivationAsync } from './flowDerivationAsync.js';
3
- import { FlowStateAsync } from './flowStateAsync.js';
4
- /**
5
- * Writable reactive value that recomputes asynchronously when dependencies change, but can be manually overridden.
6
- *
7
- * Async writable derivations combine reactive async computation with manual control. They track dependencies and
8
- * recompute asynchronously like regular async derivations, but you can also call `set()` to override the computed
9
- * value with a new promise. While recomputing or pending, accessing the value throws PendingError. Use for computed
10
- * async values that users can edit, such as formatted async fields, calculated async totals that can be adjusted,
11
- * or any async value that is usually derived but sometimes needs manual correction.
12
- *
13
- * @public
14
- */
15
- export interface FlowWritableDerivationAsync<T> extends FlowStateAsync<T>, FlowDerivationAsync<T> {
16
- }
17
- /**
18
- * Creates an async derived value that recomputes automatically but can also be manually overridden.
19
- *
20
- * The async compute function tracks dependencies and returns a promise. When any tracked dependency changes,
21
- * the function runs again and returns a new promise. However, you can also call `set()` to override the computed
22
- * value with a new promise. Use for async values that are normally derived but need occasional manual adjustments,
23
- * such as editable async calculated fields or user-correctable async totals.
24
- *
25
- * @param compute - Async function that accesses dependencies and returns a promise of the derived value
26
- * @param options - Optional settings; `name` identifies this primitive in error messages
27
- * @returns A FlowWritableDerivationAsync that provides both reactive async computation and manual control
28
- *
29
- * @public
30
- */
31
- export declare function writableDerivationAsync<T>(compute: DerivationFunctionAsync<T>, options?: FlowPrimitiveOptions): FlowWritableDerivationAsync<T>;
@@ -1,4 +0,0 @@
1
- export * from './flowConstantAsync.js';
2
- export * from './flowDerivationAsync.js';
3
- export * from './flowStateAsync.js';
4
- export * from './flowWritableDerivationAsync.js';
@@ -1,138 +0,0 @@
1
- import { FlowPrimitiveOptions } from '../../base/flowPrimitiveOptions.js';
2
- import { FlowState } from '../sync/flowState.js';
3
- /**
4
- * Discriminated union representing all possible array mutation operations.
5
- *
6
- * Each mutation on a FlowArray emits an action describing what changed. This enables fine-grained
7
- * reactive tracking - you can observe the array itself or subscribe to `$lastAction` to react only
8
- * to specific mutations. Use this for optimized rendering, undo/redo systems, or any scenario where
9
- * you need to know exactly what changed rather than just that something changed.
10
- *
11
- * @public
12
- */
13
- export type FlowArrayAction<T> = {
14
- type: "set";
15
- setItems: T[];
16
- clearedItems: T[];
17
- } | {
18
- type: "update";
19
- index: number;
20
- setItem: T;
21
- clearedItem: T | undefined;
22
- } | {
23
- type: "push";
24
- addedItem: T;
25
- } | {
26
- type: "pop";
27
- removedItem: T | undefined;
28
- } | {
29
- type: "unshift";
30
- addedItem: T;
31
- } | {
32
- type: "shift";
33
- removedItem: T | undefined;
34
- } | {
35
- type: "splice";
36
- start: number;
37
- deleteCount: number;
38
- addedItems: T[];
39
- removedItems: T[];
40
- } | {
41
- type: "clear";
42
- clearedItems: T[];
43
- };
44
- /**
45
- * Reactive array with standard mutation methods and fine-grained change tracking.
46
- *
47
- * FlowArray behaves like a regular array but notifies dependents on mutations. It provides all standard
48
- * array mutation methods (push, pop, splice, etc.) and tracks each operation via the `$lastAction` signal.
49
- * This enables both coarse-grained reactivity (reacting to any change) and fine-grained reactivity (reacting
50
- * only to specific mutations). Use for lists that need reactive updates, such as todo lists, data tables,
51
- * or any collection that changes over time.
52
- *
53
- * @public
54
- */
55
- export interface FlowArray<T> extends FlowState<T[]> {
56
- /**
57
- * Replaces an item at a specific index.
58
- * Emits an "update" action to $lastAction.
59
- *
60
- * @param index - The index of the item to replace
61
- * @param item - The new item
62
- * @returns The previous item at that index
63
- */
64
- update(index: number, item: T): T | undefined;
65
- /**
66
- * Appends an item to the end of the array.
67
- * Emits a "push" action to $lastAction.
68
- *
69
- * @param item - The item to append
70
- */
71
- push(item: T): void;
72
- /**
73
- * Removes and returns the last item from the array.
74
- * Emits a "pop" action to $lastAction when an item is removed.
75
- * If the array is already empty, returns undefined without notifying dependents or updating $lastAction.
76
- *
77
- * @returns The removed item, or undefined if the array was empty
78
- */
79
- pop(): T | undefined;
80
- /**
81
- * Inserts an item at the beginning of the array.
82
- * Emits an "unshift" action to $lastAction.
83
- *
84
- * @param item - The item to insert
85
- */
86
- unshift(item: T): void;
87
- /**
88
- * Removes and returns the first item from the array.
89
- * Emits a "shift" action to $lastAction when an item is removed.
90
- * If the array is already empty, returns undefined without notifying dependents or updating $lastAction.
91
- *
92
- * @returns The removed item, or undefined if the array was empty
93
- */
94
- shift(): T | undefined;
95
- /**
96
- * Changes the content of the array by removing, replacing, or adding items.
97
- * Emits a "splice" action to $lastAction.
98
- *
99
- * @param start - The starting index
100
- * @param deleteCount - Number of items to remove
101
- * @param newItems - New items to add at the start position
102
- * @returns Array of removed items
103
- */
104
- splice(start: number, deleteCount: number, ...newItems: T[]): T[];
105
- /**
106
- * Removes all items from the array.
107
- * Emits a "clear" action to $lastAction.
108
- *
109
- * @returns Array of all removed items
110
- */
111
- clear(): T[];
112
- /**
113
- * The current length of the array.
114
- */
115
- length: number;
116
- /**
117
- * Reactive state containing the last mutation operation performed on the array.
118
- * `.subscribe()` invokes its callback once per mutation (including several in the same tick).
119
- * `get()` / `pick()` expose only the latest action snapshot.
120
- */
121
- $lastAction: FlowState<FlowArrayAction<T>>;
122
- }
123
- /**
124
- * Creates a reactive array with mutation methods and fine-grained action tracking.
125
- *
126
- * The array starts with the provided initial items (or empty if none provided). All mutation methods
127
- * (push, pop, splice, etc.) notify dependents and emit detailed action information to `$lastAction`.
128
- * Use the array itself for coarse-grained reactivity, or subscribe to `$lastAction` for fine-grained
129
- * reactivity to specific mutation types. Useful for reactive lists, collections, or any data that
130
- * needs array-like operations with automatic change propagation.
131
- *
132
- * @param initial - Optional initial array of items
133
- * @param options - Optional settings; `name` identifies this primitive in error messages
134
- * @returns A FlowArray with reactive mutation methods
135
- *
136
- * @public
137
- */
138
- export declare function array<T>(initial?: T[], options?: FlowPrimitiveOptions): FlowArray<T>;
@@ -1,100 +0,0 @@
1
- import { FlowPrimitiveOptions } from '../../base/flowPrimitiveOptions.js';
2
- import { FlowState } from '../sync/flowState.js';
3
- /**
4
- * Discriminated union representing all possible map mutation operations.
5
- *
6
- * Each mutation on a FlowMap emits an action describing what changed. This enables fine-grained
7
- * reactive tracking - you can observe the map itself or subscribe to `$lastAction` to react only
8
- * to specific mutations. Use this for optimized updates, undo/redo systems, or any scenario where
9
- * you need to know exactly what changed rather than just that something changed.
10
- *
11
- * @public
12
- */
13
- export type FlowMapAction<K, V> = {
14
- type: "set";
15
- setMap: Map<K, V>;
16
- clearedMap: Map<K, V>;
17
- } | {
18
- type: "add";
19
- key: K;
20
- addedValue: V;
21
- } | {
22
- type: "update";
23
- key: K;
24
- setValue: V;
25
- clearedValue: V;
26
- } | {
27
- type: "delete";
28
- key: K;
29
- removedValue: V;
30
- } | {
31
- type: "clear";
32
- clearedMap: Map<K, V>;
33
- };
34
- /**
35
- * Reactive map with standard mutation methods and fine-grained change tracking.
36
- *
37
- * FlowMap behaves like a regular Map but notifies dependents on mutations. It provides standard
38
- * map operations (add, update, delete) and tracks each operation via the `$lastAction` signal.
39
- * This enables both coarse-grained reactivity (reacting to any change) and fine-grained reactivity
40
- * (reacting only to specific mutations). Use for key-value collections that need reactive updates,
41
- * such as entity stores, lookup tables, or any map-based data that changes over time.
42
- *
43
- * @public
44
- */
45
- export interface FlowMap<K, V> extends FlowState<Map<K, V>> {
46
- /**
47
- * Removes a key-value pair from the map.
48
- * Emits a "delete" action to $lastAction.
49
- *
50
- * @param key - The key to delete
51
- * @returns The deleted value
52
- */
53
- delete(key: K): V;
54
- /**
55
- * Updates an existing key-value pair in the map.
56
- * Emits an "update" action to $lastAction.
57
- *
58
- * @param key - The key to update (must exist)
59
- * @param value - The new value
60
- * @returns The previous value
61
- */
62
- update(key: K, value: V): V | undefined;
63
- /**
64
- * Adds a new key-value pair to the map.
65
- * Emits an "add" action to $lastAction.
66
- *
67
- * @param key - The key to add (must not exist)
68
- * @param value - The value to associate with the key
69
- */
70
- add(key: K, value: V): void;
71
- /**
72
- * Removes all entries from the map.
73
- * Emits a "clear" action to $lastAction.
74
- *
75
- * @returns Map of all removed entries
76
- */
77
- clear(): Map<K, V>;
78
- /**
79
- * Reactive state containing the last mutation operation performed on the map.
80
- * `.subscribe()` invokes its callback once per mutation (including several in the same tick).
81
- * `get()` / `pick()` expose only the latest action snapshot.
82
- */
83
- $lastAction: FlowState<FlowMapAction<K, V>>;
84
- }
85
- /**
86
- * Creates a reactive map with mutation methods and fine-grained action tracking.
87
- *
88
- * The map starts with the provided initial entries (or empty if none provided). All mutation methods
89
- * (add, update, delete) notify dependents and emit detailed action information to `$lastAction`.
90
- * Use the map itself for coarse-grained reactivity, or subscribe to `$lastAction` for fine-grained
91
- * reactivity to specific mutation types. Useful for entity stores, lookup tables, or any key-value
92
- * data that needs reactive updates.
93
- *
94
- * @param initial - Optional initial entries as a Record or Map
95
- * @param options - Optional settings; `name` identifies this primitive in error messages
96
- * @returns A FlowMap with reactive mutation methods
97
- *
98
- * @public
99
- */
100
- export declare function map<K extends string | number | symbol, V>(initial?: Record<K, V> | Map<K, V>, options?: FlowPrimitiveOptions): FlowMap<K, V>;
@@ -1,2 +0,0 @@
1
- export * from './flowArray.js';
2
- export * from './flowMap.js';
@@ -1,28 +0,0 @@
1
- import { FlowDisposable } from '../base/flowDisposable.js';
2
- import { FlowDataTracker, FlowOnDataListener, FlowOnErrorListener, FlowOnPendingListener } from '../base/flowSubscribable.js';
3
- /**
4
- * Handle to a reactive effect that automatically tracks dependencies and re-executes when they change.
5
- *
6
- * Effects run immediately upon creation and then reactively respond to changes in any reactive values
7
- * accessed during execution. Call `dispose()` to stop the effect and clean up its subscriptions.
8
- *
9
- * @public
10
- */
11
- export interface FlowEffect extends FlowDisposable {
12
- }
13
- /**
14
- * Creates a reactive effect that runs immediately and automatically re-runs when dependencies change.
15
- *
16
- * The effect function tracks any reactive values accessed and subscribes to their changes.
17
- * When any tracked value changes, the effect re-executes with the new values.
18
- * Optional callbacks handle errors and pending async states.
19
- *
20
- * @param data - Function that accesses reactive dependencies and returns data
21
- * @param onData - Callback invoked with the computed data on each execution
22
- * @param onError - Optional callback for handling errors during execution
23
- * @param onPending - Optional callback invoked when async dependencies are pending
24
- * @returns A FlowEffect handle with a `dispose()` method to stop the effect
25
- *
26
- * @public
27
- */
28
- export declare function subscribe<T>(data: FlowDataTracker<T>, onData: FlowOnDataListener<T>, onError?: FlowOnErrorListener, onPending?: FlowOnPendingListener): FlowEffect;
@@ -1,26 +0,0 @@
1
- import { FlowObservable } from '../base/flowObservable.js';
2
- import { FlowPrimitiveOptions } from '../base/flowPrimitiveOptions.js';
3
- /**
4
- * Manual trigger that notifies subscribers without carrying data.
5
- *
6
- * Unlike reactive state or derivations, signals don't hold values. They serve as event emitters
7
- * that notify dependents when explicitly triggered. Use signals for side effects that should run
8
- * in response to manual actions rather than data changes.
9
- *
10
- * @public
11
- */
12
- export interface FlowSignal extends FlowObservable<void> {
13
- }
14
- /**
15
- * Creates a signal that can be manually triggered to notify dependents.
16
- *
17
- * Signals act as event emitters in the reactive graph. Call `trigger()` to notify all subscribers
18
- * and reactive computations that depend on the signal. Unlike state or derivations, signals don't
19
- * carry data values - they simply represent that an event occurred.
20
- *
21
- * @param options - Optional settings; `name` identifies this primitive in error messages
22
- * @returns A FlowSignal that can be triggered manually and subscribed to
23
- *
24
- * @public
25
- */
26
- export declare function signal(options?: FlowPrimitiveOptions): FlowSignal;