@zeix/cause-effect 0.15.0 → 0.15.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/README.md +2 -10
- package/index.dev.js +50 -49
- package/index.js +1 -1
- package/index.ts +12 -2
- package/package.json +1 -1
- package/src/diff.ts +15 -3
- package/src/effect.ts +1 -2
- package/src/match.ts +13 -18
- package/src/resolve.ts +7 -17
- package/src/signal.ts +44 -30
- package/src/store.ts +62 -63
- package/src/util.ts +15 -17
- package/test/signal.test.ts +451 -0
- package/test/store.test.ts +27 -0
- package/types/index.d.ts +4 -4
- package/types/src/diff.d.ts +6 -3
- package/types/src/match.d.ts +3 -3
- package/types/src/resolve.d.ts +3 -3
- package/types/src/signal.d.ts +17 -13
- package/types/src/store.d.ts +20 -15
- package/types/src/util.d.ts +3 -4
package/types/src/store.d.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { type UnknownRecord } from './diff';
|
|
1
|
+
import { type UnknownRecord, type UnknownRecordOrArray } from './diff';
|
|
2
2
|
import { type Signal } from './signal';
|
|
3
3
|
import { type State } from './state';
|
|
4
4
|
declare const TYPE_STORE = "Store";
|
|
5
|
-
interface StoreAddEvent<T extends
|
|
5
|
+
interface StoreAddEvent<T extends UnknownRecordOrArray> extends CustomEvent {
|
|
6
6
|
type: 'store-add';
|
|
7
7
|
detail: Partial<T>;
|
|
8
8
|
}
|
|
9
|
-
interface StoreChangeEvent<T extends
|
|
9
|
+
interface StoreChangeEvent<T extends UnknownRecordOrArray> extends CustomEvent {
|
|
10
10
|
type: 'store-change';
|
|
11
11
|
detail: Partial<T>;
|
|
12
12
|
}
|
|
13
|
-
interface StoreRemoveEvent<T extends
|
|
13
|
+
interface StoreRemoveEvent<T extends UnknownRecordOrArray> extends CustomEvent {
|
|
14
14
|
type: 'store-remove';
|
|
15
15
|
detail: Partial<T>;
|
|
16
16
|
}
|
|
17
|
-
type StoreEventMap<T extends
|
|
17
|
+
type StoreEventMap<T extends UnknownRecordOrArray> = {
|
|
18
18
|
'store-add': StoreAddEvent<T>;
|
|
19
19
|
'store-change': StoreChangeEvent<T>;
|
|
20
20
|
'store-remove': StoreRemoveEvent<T>;
|
|
21
21
|
};
|
|
22
|
-
interface StoreEventTarget<T extends
|
|
22
|
+
interface StoreEventTarget<T extends UnknownRecordOrArray> extends EventTarget {
|
|
23
23
|
addEventListener<K extends keyof StoreEventMap<T>>(type: K, listener: (event: StoreEventMap<T>[K]) => void, options?: boolean | AddEventListenerOptions): void;
|
|
24
24
|
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
25
25
|
removeEventListener<K extends keyof StoreEventMap<T>>(type: K, listener: (event: StoreEventMap<T>[K]) => void, options?: boolean | EventListenerOptions): void;
|
|
26
26
|
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
|
27
27
|
dispatchEvent(event: Event): boolean;
|
|
28
28
|
}
|
|
29
|
-
type Store<T extends
|
|
30
|
-
[K in keyof T
|
|
29
|
+
type Store<T extends UnknownRecordOrArray = UnknownRecord> = {
|
|
30
|
+
[K in keyof T]: T[K] extends UnknownRecord ? Store<T[K]> : State<T[K]>;
|
|
31
31
|
} & StoreEventTarget<T> & {
|
|
32
32
|
[Symbol.toStringTag]: 'Store';
|
|
33
|
-
[Symbol.iterator](): IterableIterator<[
|
|
34
|
-
add<K extends keyof T
|
|
33
|
+
[Symbol.iterator](): IterableIterator<[keyof T, Signal<T[keyof T]>]>;
|
|
34
|
+
add<K extends keyof T>(key: K, value: T[K]): void;
|
|
35
35
|
get(): T;
|
|
36
|
-
remove<K extends keyof T
|
|
36
|
+
remove<K extends keyof T>(key: K): void;
|
|
37
37
|
set(value: T): void;
|
|
38
38
|
update(updater: (value: T) => T): void;
|
|
39
39
|
size: State<number>;
|
|
@@ -41,11 +41,16 @@ type Store<T extends UnknownRecord = UnknownRecord> = {
|
|
|
41
41
|
/**
|
|
42
42
|
* Create a new store with deeply nested reactive properties
|
|
43
43
|
*
|
|
44
|
+
* Supports both objects and arrays as initial values. Arrays are converted
|
|
45
|
+
* to records internally for storage but maintain their array type through
|
|
46
|
+
* the .get() method, which automatically converts objects with consecutive
|
|
47
|
+
* numeric keys back to arrays.
|
|
48
|
+
*
|
|
44
49
|
* @since 0.15.0
|
|
45
|
-
* @param {T} initialValue - initial object value of the store
|
|
46
|
-
* @returns {Store<T>} - new store with reactive properties
|
|
50
|
+
* @param {T} initialValue - initial object or array value of the store
|
|
51
|
+
* @returns {Store<T>} - new store with reactive properties that preserves the original type T
|
|
47
52
|
*/
|
|
48
|
-
declare const store: <T extends
|
|
53
|
+
declare const store: <T extends UnknownRecordOrArray>(initialValue: T) => Store<T>;
|
|
49
54
|
/**
|
|
50
55
|
* Check if the provided value is a Store instance
|
|
51
56
|
*
|
|
@@ -53,5 +58,5 @@ declare const store: <T extends UnknownRecord>(initialValue: T) => Store<T>;
|
|
|
53
58
|
* @param {unknown} value - value to check
|
|
54
59
|
* @returns {boolean} - true if the value is a Store instance, false otherwise
|
|
55
60
|
*/
|
|
56
|
-
declare const isStore: <T extends
|
|
61
|
+
declare const isStore: <T extends UnknownRecordOrArray>(value: unknown) => value is Store<T>;
|
|
57
62
|
export { TYPE_STORE, isStore, store, type Store, type StoreAddEvent, type StoreChangeEvent, type StoreRemoveEvent, type StoreEventMap, };
|
package/types/src/util.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
declare const isNumber: (value: unknown) => value is number;
|
|
2
1
|
declare const isString: (value: unknown) => value is string;
|
|
2
|
+
declare const isNumber: (value: unknown) => value is number;
|
|
3
3
|
declare const isFunction: <T>(fn: unknown) => fn is (...args: unknown[]) => T;
|
|
4
4
|
declare const isAsyncFunction: <T>(fn: unknown) => fn is (...args: unknown[]) => Promise<T>;
|
|
5
5
|
declare const isObjectOfType: <T>(value: unknown, type: string) => value is T;
|
|
6
6
|
declare const isRecord: <T extends Record<string, unknown>>(value: unknown) => value is T;
|
|
7
|
-
declare const
|
|
8
|
-
declare const arrayToRecord: <T extends unknown & {}>(array: T[]) => Record<string, T>;
|
|
7
|
+
declare const validArrayIndexes: (keys: Array<PropertyKey>) => number[] | null;
|
|
9
8
|
declare const hasMethod: <T extends object & Record<string, (...args: unknown[]) => unknown>>(obj: T, methodName: string) => obj is T & Record<string, (...args: unknown[]) => unknown>;
|
|
10
9
|
declare const isAbortError: (error: unknown) => boolean;
|
|
11
10
|
declare const toError: (reason: unknown) => Error;
|
|
12
11
|
declare class CircularDependencyError extends Error {
|
|
13
12
|
constructor(where: string);
|
|
14
13
|
}
|
|
15
|
-
export {
|
|
14
|
+
export { isString, isNumber, isFunction, isAsyncFunction, isObjectOfType, isRecord, validArrayIndexes, hasMethod, isAbortError, toError, CircularDependencyError, };
|