@zeix/cause-effect 0.17.3 → 0.18.1
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/.ai-context.md +169 -227
- package/.cursorrules +41 -35
- package/.github/copilot-instructions.md +176 -116
- package/ARCHITECTURE.md +276 -0
- package/CHANGELOG.md +29 -0
- package/CLAUDE.md +201 -143
- package/GUIDE.md +298 -0
- package/README.md +246 -193
- package/REQUIREMENTS.md +100 -0
- package/bench/reactivity.bench.ts +577 -0
- package/context7.json +4 -0
- package/examples/events-sensor.ts +187 -0
- package/examples/selector-sensor.ts +173 -0
- package/index.dev.js +1390 -1008
- package/index.js +1 -1
- package/index.ts +60 -74
- package/package.json +5 -2
- package/skills/changelog-keeper/SKILL.md +59 -0
- package/skills/changelog-keeper/agents/openai.yaml +4 -0
- package/src/errors.ts +118 -74
- package/src/graph.ts +612 -0
- package/src/nodes/collection.ts +512 -0
- package/src/nodes/effect.ts +149 -0
- package/src/nodes/list.ts +589 -0
- package/src/nodes/memo.ts +148 -0
- package/src/nodes/sensor.ts +149 -0
- package/src/nodes/state.ts +135 -0
- package/src/nodes/store.ts +378 -0
- package/src/nodes/task.ts +174 -0
- package/src/signal.ts +112 -66
- package/src/util.ts +26 -57
- package/test/batch.test.ts +96 -62
- package/test/benchmark.test.ts +473 -487
- package/test/collection.test.ts +456 -707
- package/test/effect.test.ts +293 -696
- package/test/list.test.ts +335 -592
- package/test/memo.test.ts +574 -0
- package/test/regression.test.ts +156 -0
- package/test/scope.test.ts +191 -0
- package/test/sensor.test.ts +454 -0
- package/test/signal.test.ts +220 -213
- package/test/state.test.ts +217 -265
- package/test/store.test.ts +346 -446
- package/test/task.test.ts +529 -0
- package/test/untrack.test.ts +167 -0
- package/types/index.d.ts +13 -15
- package/types/src/errors.d.ts +73 -17
- package/types/src/graph.d.ts +218 -0
- package/types/src/nodes/collection.d.ts +69 -0
- package/types/src/nodes/effect.d.ts +48 -0
- package/types/src/nodes/list.d.ts +66 -0
- package/types/src/nodes/memo.d.ts +63 -0
- package/types/src/nodes/sensor.d.ts +81 -0
- package/types/src/nodes/state.d.ts +78 -0
- package/types/src/nodes/store.d.ts +51 -0
- package/types/src/nodes/task.d.ts +79 -0
- package/types/src/signal.d.ts +43 -29
- package/types/src/util.d.ts +9 -16
- package/archive/benchmark.ts +0 -683
- package/archive/collection.ts +0 -253
- package/archive/composite.ts +0 -85
- package/archive/computed.ts +0 -195
- package/archive/list.ts +0 -483
- package/archive/memo.ts +0 -139
- package/archive/state.ts +0 -90
- package/archive/store.ts +0 -298
- package/archive/task.ts +0 -189
- package/src/classes/collection.ts +0 -245
- package/src/classes/computed.ts +0 -349
- package/src/classes/list.ts +0 -343
- package/src/classes/ref.ts +0 -70
- package/src/classes/state.ts +0 -102
- package/src/classes/store.ts +0 -262
- package/src/diff.ts +0 -138
- package/src/effect.ts +0 -93
- package/src/match.ts +0 -45
- package/src/resolve.ts +0 -49
- package/src/system.ts +0 -257
- package/test/computed.test.ts +0 -1108
- package/test/diff.test.ts +0 -955
- package/test/match.test.ts +0 -388
- package/test/ref.test.ts +0 -353
- package/test/resolve.test.ts +0 -154
- package/types/src/classes/collection.d.ts +0 -45
- package/types/src/classes/computed.d.ts +0 -94
- package/types/src/classes/list.d.ts +0 -43
- package/types/src/classes/ref.d.ts +0 -35
- package/types/src/classes/state.d.ts +0 -49
- package/types/src/classes/store.d.ts +0 -52
- package/types/src/diff.d.ts +0 -28
- package/types/src/effect.d.ts +0 -15
- package/types/src/match.d.ts +0 -21
- package/types/src/resolve.d.ts +0 -29
- package/types/src/system.d.ts +0 -78
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type Cleanup, type SignalOptions } from '../graph';
|
|
2
|
+
/**
|
|
3
|
+
* A read-only signal that tracks external input and updates a state value as long as it is active.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of value produced by the sensor
|
|
6
|
+
*/
|
|
7
|
+
type Sensor<T extends {}> = {
|
|
8
|
+
readonly [Symbol.toStringTag]: 'Sensor';
|
|
9
|
+
/**
|
|
10
|
+
* Gets the current value of the sensor.
|
|
11
|
+
* When called inside another reactive context, creates a dependency.
|
|
12
|
+
* @returns The sensor value
|
|
13
|
+
* @throws UnsetSignalValueError If the sensor value is still unset when read.
|
|
14
|
+
*/
|
|
15
|
+
get(): T;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A callback function for sensors when the sensor starts being watched.
|
|
19
|
+
*
|
|
20
|
+
* @template T - The type of value observed
|
|
21
|
+
* @param set - A function to set the observed value
|
|
22
|
+
* @returns A cleanup function when the sensor stops being watched
|
|
23
|
+
*/
|
|
24
|
+
type SensorOptions<T extends {}> = SignalOptions<T> & {
|
|
25
|
+
/**
|
|
26
|
+
* Optional initial value. Avoids `UnsetSignalValueError` on first read
|
|
27
|
+
* before the watched callback fires.
|
|
28
|
+
*/
|
|
29
|
+
value?: T;
|
|
30
|
+
};
|
|
31
|
+
type SensorCallback<T extends {}> = (set: (next: T) => void) => Cleanup;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a sensor that tracks external input and updates a state value as long as it is active.
|
|
34
|
+
* Sensors get activated when they are first accessed by an effect and deactivated when they are
|
|
35
|
+
* no longer watched. This lazy activation pattern ensures resources are only consumed when needed.
|
|
36
|
+
*
|
|
37
|
+
* @since 0.18.0
|
|
38
|
+
* @template T - The type of value produced by the sensor
|
|
39
|
+
* @param watched - The callback invoked when the sensor starts being watched, receives a `set` function and returns a cleanup function.
|
|
40
|
+
* @param options - Optional configuration for the sensor.
|
|
41
|
+
* @param options.value - Optional initial value. Avoids `UnsetSignalValueError` on first read
|
|
42
|
+
* before the watched callback fires. Essential for the mutable-object observation pattern.
|
|
43
|
+
* @param options.equals - Optional equality function. Defaults to strict equality (`===`). Use `SKIP_EQUALITY`
|
|
44
|
+
* for mutable objects where the reference stays the same but internal state changes.
|
|
45
|
+
* @param options.guard - Optional type guard to validate values.
|
|
46
|
+
* @returns A read-only sensor signal.
|
|
47
|
+
*
|
|
48
|
+
* @example Tracking external values
|
|
49
|
+
* ```ts
|
|
50
|
+
* const mousePos = createSensor<{ x: number; y: number }>((set) => {
|
|
51
|
+
* const handler = (e: MouseEvent) => {
|
|
52
|
+
* set({ x: e.clientX, y: e.clientY });
|
|
53
|
+
* };
|
|
54
|
+
* window.addEventListener('mousemove', handler);
|
|
55
|
+
* return () => window.removeEventListener('mousemove', handler);
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @example Observing a mutable object
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { createSensor, SKIP_EQUALITY } from 'cause-effect';
|
|
62
|
+
*
|
|
63
|
+
* const el = createSensor<HTMLElement>((set) => {
|
|
64
|
+
* const node = document.getElementById('box')!;
|
|
65
|
+
* set(node);
|
|
66
|
+
* const obs = new MutationObserver(() => set(node));
|
|
67
|
+
* obs.observe(node, { attributes: true });
|
|
68
|
+
* return () => obs.disconnect();
|
|
69
|
+
* }, { value: node, equals: SKIP_EQUALITY });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare function createSensor<T extends {}>(watched: SensorCallback<T>, options?: SensorOptions<T>): Sensor<T>;
|
|
73
|
+
/**
|
|
74
|
+
* Checks if a value is a Sensor signal.
|
|
75
|
+
*
|
|
76
|
+
* @since 0.18.0
|
|
77
|
+
* @param value - The value to check
|
|
78
|
+
* @returns True if the value is a Sensor
|
|
79
|
+
*/
|
|
80
|
+
declare function isSensor<T extends {} = unknown & {}>(value: unknown): value is Sensor<T>;
|
|
81
|
+
export { createSensor, isSensor, type Sensor, type SensorCallback, type SensorOptions, };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type SignalOptions } from '../graph';
|
|
2
|
+
/**
|
|
3
|
+
* A callback function for states that updates a value based on the previous value.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of value
|
|
6
|
+
* @param prev - The previous state value
|
|
7
|
+
* @returns The new state value
|
|
8
|
+
*/
|
|
9
|
+
type UpdateCallback<T extends {}> = (prev: T) => T;
|
|
10
|
+
/**
|
|
11
|
+
* A mutable reactive state container.
|
|
12
|
+
* Changes to the state will automatically propagate to dependent computations and effects.
|
|
13
|
+
*
|
|
14
|
+
* @template T - The type of value stored in the state
|
|
15
|
+
*/
|
|
16
|
+
type State<T extends {}> = {
|
|
17
|
+
readonly [Symbol.toStringTag]: 'State';
|
|
18
|
+
/**
|
|
19
|
+
* Gets the current value of the state.
|
|
20
|
+
* When called inside a memo, task, or effect, creates a dependency.
|
|
21
|
+
* @returns The current value
|
|
22
|
+
*/
|
|
23
|
+
get(): T;
|
|
24
|
+
/**
|
|
25
|
+
* Sets a new value for the state.
|
|
26
|
+
* If the new value is different (according to the equality function), all dependents will be notified.
|
|
27
|
+
* @param next - The new value to set
|
|
28
|
+
*/
|
|
29
|
+
set(next: T): void;
|
|
30
|
+
/**
|
|
31
|
+
* Updates the state with a new value computed by a callback function.
|
|
32
|
+
* The callback receives the current value as an argument.
|
|
33
|
+
* @param fn - The callback function to compute the new value
|
|
34
|
+
*/
|
|
35
|
+
update(fn: UpdateCallback<T>): void;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Creates a mutable reactive state container.
|
|
39
|
+
*
|
|
40
|
+
* @since 0.9.0
|
|
41
|
+
* @template T - The type of value stored in the state
|
|
42
|
+
* @param value - The initial value
|
|
43
|
+
* @param options - Optional configuration for the state
|
|
44
|
+
* @returns A State object with get() and set() methods
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const count = createState(0);
|
|
49
|
+
* count.set(1);
|
|
50
|
+
* console.log(count.get()); // 1
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* // With type guard
|
|
56
|
+
* const count = createState(0, {
|
|
57
|
+
* guard: (v): v is number => typeof v === 'number'
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
declare function createState<T extends {}>(value: T, options?: SignalOptions<T>): State<T>;
|
|
62
|
+
/**
|
|
63
|
+
* Checks if a value is a State signal.
|
|
64
|
+
*
|
|
65
|
+
* @since 0.9.0
|
|
66
|
+
* @param value - The value to check
|
|
67
|
+
* @returns True if the value is a State
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* const state = createState(0);
|
|
72
|
+
* if (isState(state)) {
|
|
73
|
+
* state.set(1); // TypeScript knows state has set()
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
declare function isState<T extends {} = unknown & {}>(value: unknown): value is State<T>;
|
|
78
|
+
export { createState, isState, type State, type UpdateCallback };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type Cleanup, TYPE_STORE } from '../graph';
|
|
2
|
+
import { type List, type UnknownRecord } from './list';
|
|
3
|
+
import { type State } from './state';
|
|
4
|
+
type StoreOptions = {
|
|
5
|
+
watched?: () => Cleanup;
|
|
6
|
+
};
|
|
7
|
+
type BaseStore<T extends UnknownRecord> = {
|
|
8
|
+
readonly [Symbol.toStringTag]: 'Store';
|
|
9
|
+
readonly [Symbol.isConcatSpreadable]: false;
|
|
10
|
+
[Symbol.iterator](): IterableIterator<[
|
|
11
|
+
string,
|
|
12
|
+
State<T[keyof T] & {}> | Store<UnknownRecord> | List<unknown & {}>
|
|
13
|
+
]>;
|
|
14
|
+
keys(): IterableIterator<string>;
|
|
15
|
+
byKey<K extends keyof T & string>(key: K): T[K] extends readonly (infer U extends {})[] ? List<U> : T[K] extends UnknownRecord ? Store<T[K]> : T[K] extends unknown & {} ? State<T[K] & {}> : State<T[K] & {}> | undefined;
|
|
16
|
+
get(): T;
|
|
17
|
+
set(next: T): void;
|
|
18
|
+
update(fn: (prev: T) => T): void;
|
|
19
|
+
add<K extends keyof T & string>(key: K, value: T[K]): K;
|
|
20
|
+
remove(key: string): void;
|
|
21
|
+
};
|
|
22
|
+
type Store<T extends UnknownRecord> = BaseStore<T> & {
|
|
23
|
+
[K in keyof T]: T[K] extends readonly (infer U extends {})[] ? List<U> : T[K] extends UnknownRecord ? Store<T[K]> : T[K] extends unknown & {} ? State<T[K] & {}> : State<T[K] & {}> | undefined;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Creates a reactive store with deeply nested reactive properties.
|
|
27
|
+
* Each property becomes its own signal (State for primitives, nested Store for objects, List for arrays).
|
|
28
|
+
* Properties are accessible directly via proxy.
|
|
29
|
+
*
|
|
30
|
+
* @since 0.15.0
|
|
31
|
+
* @param value - Initial object value of the store
|
|
32
|
+
* @param options - Optional configuration for watch lifecycle
|
|
33
|
+
* @returns A Store with reactive properties
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const user = createStore({ name: 'Alice', age: 30 });
|
|
38
|
+
* user.name.set('Bob'); // Only name subscribers react
|
|
39
|
+
* console.log(user.get()); // { name: 'Bob', age: 30 }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare function createStore<T extends UnknownRecord>(value: T, options?: StoreOptions): Store<T>;
|
|
43
|
+
/**
|
|
44
|
+
* Checks if a value is a Store signal.
|
|
45
|
+
*
|
|
46
|
+
* @since 0.15.0
|
|
47
|
+
* @param value - The value to check
|
|
48
|
+
* @returns True if the value is a Store
|
|
49
|
+
*/
|
|
50
|
+
declare function isStore<T extends UnknownRecord>(value: unknown): value is Store<T>;
|
|
51
|
+
export { createStore, isStore, type Store, type StoreOptions, TYPE_STORE };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type ComputedOptions, type TaskCallback } from '../graph';
|
|
2
|
+
/**
|
|
3
|
+
* An asynchronous reactive computation (colorless async).
|
|
4
|
+
* Automatically tracks dependencies and re-executes when they change.
|
|
5
|
+
* Provides abort semantics and pending state tracking.
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of value resolved by the task
|
|
8
|
+
*/
|
|
9
|
+
type Task<T extends {}> = {
|
|
10
|
+
readonly [Symbol.toStringTag]: 'Task';
|
|
11
|
+
/**
|
|
12
|
+
* Gets the current value of the task.
|
|
13
|
+
* Returns the last resolved value, even while a new computation is pending.
|
|
14
|
+
* When called inside another reactive context, creates a dependency.
|
|
15
|
+
* @returns The current value
|
|
16
|
+
* @throws UnsetSignalValueError If the task value is still unset when read.
|
|
17
|
+
*/
|
|
18
|
+
get(): T;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if the task is currently executing.
|
|
21
|
+
* @returns True if a computation is in progress
|
|
22
|
+
*/
|
|
23
|
+
isPending(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Aborts the current computation if one is running.
|
|
26
|
+
* The task's AbortSignal will be triggered.
|
|
27
|
+
*/
|
|
28
|
+
abort(): void;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Creates an asynchronous reactive computation (colorless async).
|
|
32
|
+
* The computation automatically tracks dependencies and re-executes when they change.
|
|
33
|
+
* Provides abort semantics - in-flight computations are aborted when dependencies change.
|
|
34
|
+
*
|
|
35
|
+
* @since 0.18.0
|
|
36
|
+
* @template T - The type of value resolved by the task
|
|
37
|
+
* @param fn - The async computation function that receives the previous value and an AbortSignal
|
|
38
|
+
* @param options - Optional configuration for the task
|
|
39
|
+
* @param options.value - Optional initial value for reducer patterns
|
|
40
|
+
* @param options.equals - Optional equality function. Defaults to strict equality (`===`)
|
|
41
|
+
* @param options.guard - Optional type guard to validate values
|
|
42
|
+
* @param options.watched - Optional callback invoked when the task is first watched by an effect.
|
|
43
|
+
* Receives an `invalidate` function to mark the task dirty and trigger re-execution.
|
|
44
|
+
* Must return a cleanup function called when no effects are watching.
|
|
45
|
+
* @returns A Task object with get(), isPending(), and abort() methods
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const userId = createState(1);
|
|
50
|
+
* const user = createTask(async (prev, signal) => {
|
|
51
|
+
* const response = await fetch(`/api/users/${userId.get()}`, { signal });
|
|
52
|
+
* return response.json();
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* // When userId changes, the previous fetch is aborted
|
|
56
|
+
* userId.set(2);
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* // Check pending state
|
|
62
|
+
* if (user.isPending()) {
|
|
63
|
+
* console.log('Loading...');
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare function createTask<T extends {}>(fn: (prev: T, signal: AbortSignal) => Promise<T>, options: ComputedOptions<T> & {
|
|
68
|
+
value: T;
|
|
69
|
+
}): Task<T>;
|
|
70
|
+
declare function createTask<T extends {}>(fn: TaskCallback<T>, options?: ComputedOptions<T>): Task<T>;
|
|
71
|
+
/**
|
|
72
|
+
* Checks if a value is a Task signal.
|
|
73
|
+
*
|
|
74
|
+
* @since 0.18.0
|
|
75
|
+
* @param value - The value to check
|
|
76
|
+
* @returns True if the value is a Task
|
|
77
|
+
*/
|
|
78
|
+
declare function isTask<T extends {} = unknown & {}>(value: unknown): value is Task<T>;
|
|
79
|
+
export { createTask, isTask, type Task };
|
package/types/src/signal.d.ts
CHANGED
|
@@ -1,51 +1,65 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { List } from './
|
|
3
|
-
import {
|
|
4
|
-
import { type
|
|
5
|
-
import type
|
|
6
|
-
type
|
|
1
|
+
import { type ComputedOptions, type MemoCallback, type Signal, type TaskCallback } from './graph';
|
|
2
|
+
import { type List, type UnknownRecord } from './nodes/list';
|
|
3
|
+
import { type Memo } from './nodes/memo';
|
|
4
|
+
import { type State } from './nodes/state';
|
|
5
|
+
import { type Store } from './nodes/store';
|
|
6
|
+
import { type Task } from './nodes/task';
|
|
7
|
+
type MutableSignal<T extends {}> = {
|
|
7
8
|
get(): T;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type MutableSignal<T extends {}> = T extends readonly (infer U extends {})[] ? List<U> : T extends UnknownRecord ? Store<T> : State<T>;
|
|
11
|
-
type ReadonlySignal<T extends {}> = Computed<T>;
|
|
12
|
-
type UnknownSignalRecord = Record<string, UnknownSignal>;
|
|
13
|
-
type SignalValues<S extends UnknownSignalRecord> = {
|
|
14
|
-
[K in keyof S]: S[K] extends Signal<infer T> ? T : never;
|
|
9
|
+
set(value: T): void;
|
|
10
|
+
update(callback: (value: T) => T): void;
|
|
15
11
|
};
|
|
16
12
|
/**
|
|
17
|
-
*
|
|
13
|
+
* Create a derived signal from existing signals
|
|
18
14
|
*
|
|
19
15
|
* @since 0.9.0
|
|
20
|
-
* @param
|
|
21
|
-
* @
|
|
16
|
+
* @param callback - Computation callback function
|
|
17
|
+
* @param options - Optional configuration
|
|
22
18
|
*/
|
|
23
|
-
declare
|
|
24
|
-
|
|
25
|
-
* Check whether a value is a State, Store, or List
|
|
26
|
-
*
|
|
27
|
-
* @since 0.15.2
|
|
28
|
-
* @param {unknown} value - Value to check
|
|
29
|
-
* @returns {boolean} - True if value is a State, Store, or List, false otherwise
|
|
30
|
-
*/
|
|
31
|
-
declare const isMutableSignal: (value: unknown) => value is MutableSignal<unknown & {}>;
|
|
19
|
+
declare function createComputed<T extends {}>(callback: TaskCallback<T>, options?: ComputedOptions<T>): Task<T>;
|
|
20
|
+
declare function createComputed<T extends {}>(callback: MemoCallback<T>, options?: ComputedOptions<T>): Memo<T>;
|
|
32
21
|
/**
|
|
33
22
|
* Convert a value to a Signal.
|
|
34
23
|
*
|
|
35
24
|
* @since 0.9.6
|
|
36
25
|
*/
|
|
26
|
+
declare function createSignal<T extends {}>(value: Signal<T>): Signal<T>;
|
|
37
27
|
declare function createSignal<T extends {}>(value: readonly T[]): List<T>;
|
|
38
|
-
declare function createSignal<T extends {}>(value: T[]): List<T>;
|
|
39
28
|
declare function createSignal<T extends UnknownRecord>(value: T): Store<T>;
|
|
40
|
-
declare function createSignal<T extends {}>(value:
|
|
29
|
+
declare function createSignal<T extends {}>(value: TaskCallback<T>): Task<T>;
|
|
30
|
+
declare function createSignal<T extends {}>(value: MemoCallback<T>): Memo<T>;
|
|
41
31
|
declare function createSignal<T extends {}>(value: T): State<T>;
|
|
42
32
|
/**
|
|
43
33
|
* Convert a value to a MutableSignal.
|
|
44
34
|
*
|
|
45
35
|
* @since 0.17.0
|
|
46
36
|
*/
|
|
37
|
+
declare function createMutableSignal<T extends {}>(value: MutableSignal<T>): MutableSignal<T>;
|
|
47
38
|
declare function createMutableSignal<T extends {}>(value: readonly T[]): List<T>;
|
|
48
|
-
declare function createMutableSignal<T extends {}>(value: T[]): List<T>;
|
|
49
39
|
declare function createMutableSignal<T extends UnknownRecord>(value: T): Store<T>;
|
|
50
40
|
declare function createMutableSignal<T extends {}>(value: T): State<T>;
|
|
51
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Check if a value is a computed signal
|
|
43
|
+
*
|
|
44
|
+
* @since 0.9.0
|
|
45
|
+
* @param value - Value to check
|
|
46
|
+
* @returns True if value is a computed signal, false otherwise
|
|
47
|
+
*/
|
|
48
|
+
declare function isComputed<T extends {}>(value: unknown): value is Memo<T>;
|
|
49
|
+
/**
|
|
50
|
+
* Check whether a value is a Signal
|
|
51
|
+
*
|
|
52
|
+
* @since 0.9.0
|
|
53
|
+
* @param value - Value to check
|
|
54
|
+
* @returns True if value is a Signal, false otherwise
|
|
55
|
+
*/
|
|
56
|
+
declare function isSignal<T extends {}>(value: unknown): value is Signal<T>;
|
|
57
|
+
/**
|
|
58
|
+
* Check whether a value is a State, Store, or List
|
|
59
|
+
*
|
|
60
|
+
* @since 0.15.2
|
|
61
|
+
* @param value - Value to check
|
|
62
|
+
* @returns True if value is a State, Store, or List, false otherwise
|
|
63
|
+
*/
|
|
64
|
+
declare function isMutableSignal(value: unknown): value is MutableSignal<unknown & {}>;
|
|
65
|
+
export { type MutableSignal, createComputed, createSignal, createMutableSignal, isComputed, isSignal, isMutableSignal, };
|
package/types/src/util.d.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
declare
|
|
2
|
-
declare
|
|
3
|
-
declare
|
|
4
|
-
declare const isFunction: <T>(fn: unknown) => fn is (...args: unknown[]) => T;
|
|
5
|
-
declare const isAsyncFunction: <T>(fn: unknown) => fn is (...args: unknown[]) => Promise<T>;
|
|
6
|
-
declare const isSyncFunction: <T extends unknown & {
|
|
1
|
+
declare function isFunction<T>(fn: unknown): fn is (...args: unknown[]) => T;
|
|
2
|
+
declare function isAsyncFunction<T>(fn: unknown): fn is (...args: unknown[]) => Promise<T>;
|
|
3
|
+
declare function isSyncFunction<T extends unknown & {
|
|
7
4
|
then?: undefined;
|
|
8
|
-
}>(fn: unknown)
|
|
9
|
-
declare
|
|
10
|
-
declare
|
|
11
|
-
declare
|
|
12
|
-
declare
|
|
13
|
-
|
|
14
|
-
declare const hasMethod: <T extends object & Record<string, (...args: unknown[]) => unknown>>(obj: T, methodName: string) => obj is T & Record<string, (...args: unknown[]) => unknown>;
|
|
15
|
-
declare const isAbortError: (error: unknown) => boolean;
|
|
16
|
-
declare const valueString: (value: unknown) => string;
|
|
17
|
-
export { isString, isNumber, isSymbol, isFunction, isAsyncFunction, isSyncFunction, isNonNullObject, isObjectOfType, isRecord, isRecordOrArray, isUniformArray, hasMethod, isAbortError, valueString, };
|
|
5
|
+
}>(fn: unknown): fn is (...args: unknown[]) => T;
|
|
6
|
+
declare function isObjectOfType<T>(value: unknown, type: string): value is T;
|
|
7
|
+
declare function isRecord<T extends Record<string, unknown>>(value: unknown): value is T;
|
|
8
|
+
declare function isUniformArray<T>(value: unknown, guard?: (item: T) => item is T & {}): value is T[];
|
|
9
|
+
declare function valueString(value: unknown): string;
|
|
10
|
+
export { isFunction, isAsyncFunction, isSyncFunction, isObjectOfType, isRecord, isUniformArray, valueString, };
|