@zeix/cause-effect 0.16.0 → 0.16.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 +1 -1
- package/index.dev.js +167 -162
- package/index.js +1 -1
- package/index.ts +3 -2
- package/package.json +1 -1
- package/src/computed.ts +15 -16
- package/src/diff.ts +24 -21
- package/src/state.ts +34 -45
- package/src/store.ts +170 -221
- package/src/util.ts +2 -6
- package/test/batch.test.ts +1 -1
- package/test/benchmark.test.ts +1 -1
- package/test/computed.test.ts +1 -1
- package/test/effect.test.ts +1 -1
- package/test/match.test.ts +1 -1
- package/test/resolve.test.ts +1 -1
- package/test/signal.test.ts +2 -2
- package/test/state.test.ts +1 -1
- package/test/store.test.ts +859 -1502
- package/types/index.d.ts +3 -3
- package/types/src/diff.d.ts +7 -7
- package/types/src/store.d.ts +6 -7
package/types/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name Cause & Effect
|
|
3
|
-
* @version 0.16.
|
|
3
|
+
* @version 0.16.1
|
|
4
4
|
* @author Esther Brunner
|
|
5
5
|
*/
|
|
6
6
|
export { type Computed, type ComputedCallback, createComputed, isComputed, isComputedCallback, TYPE_COMPUTED, } from './src/computed';
|
|
7
|
-
export { type DiffResult, diff, isEqual, type
|
|
7
|
+
export { type DiffResult, diff, isEqual, type PartialRecord, type UnknownArray, type UnknownRecord, } from './src/diff';
|
|
8
8
|
export { createEffect, type EffectCallback, type MaybeCleanup, } from './src/effect';
|
|
9
9
|
export { CircularDependencyError, InvalidCallbackError, InvalidSignalValueError, NullishSignalValueError, StoreKeyExistsError, StoreKeyRangeError, StoreKeyReadonlyError, } from './src/errors';
|
|
10
10
|
export { type MatchHandlers, match } from './src/match';
|
|
@@ -13,4 +13,4 @@ export { isMutableSignal, isSignal, type Signal, type SignalValues, toSignal, ty
|
|
|
13
13
|
export { createState, isState, type State, TYPE_STATE } from './src/state';
|
|
14
14
|
export { createStore, isStore, type Store, type StoreChanges, TYPE_STORE, } from './src/store';
|
|
15
15
|
export { batch, type Cleanup, createWatcher, flush, notify, observe, subscribe, type Watcher, } from './src/system';
|
|
16
|
-
export { isAbortError, isAsyncFunction, isFunction, isNumber, isRecord, isRecordOrArray, isString, isSymbol, toError, UNSET, valueString, } from './src/util';
|
|
16
|
+
export { isAbortError, isAsyncFunction, isFunction, isNumber, isObjectOfType, isRecord, isRecordOrArray, isString, isSymbol, toError, UNSET, valueString, } from './src/util';
|
package/types/src/diff.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ type UnknownArray = ReadonlyArray<unknown & {}>;
|
|
|
3
3
|
type ArrayToRecord<T extends UnknownArray> = {
|
|
4
4
|
[key: string]: T extends Array<infer U extends {}> ? U : never;
|
|
5
5
|
};
|
|
6
|
-
type
|
|
7
|
-
type DiffResult<T extends
|
|
6
|
+
type PartialRecord<T> = T extends UnknownArray ? Partial<ArrayToRecord<T>> : Partial<T>;
|
|
7
|
+
type DiffResult<T extends UnknownRecord | UnknownArray = UnknownRecord> = {
|
|
8
8
|
changed: boolean;
|
|
9
|
-
add:
|
|
10
|
-
change:
|
|
11
|
-
remove:
|
|
9
|
+
add: PartialRecord<T>;
|
|
10
|
+
change: PartialRecord<T>;
|
|
11
|
+
remove: PartialRecord<T>;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
14
|
* Checks if two values are equal with cycle detection
|
|
@@ -28,5 +28,5 @@ declare const isEqual: <T>(a: T, b: T, visited?: WeakSet<object>) => boolean;
|
|
|
28
28
|
* @param {T} newObj - The new record to compare
|
|
29
29
|
* @returns {DiffResult<T>} The result of the comparison
|
|
30
30
|
*/
|
|
31
|
-
declare const diff: <T extends
|
|
32
|
-
export { type ArrayToRecord, type DiffResult, diff, isEqual, type UnknownRecord, type UnknownArray, type
|
|
31
|
+
declare const diff: <T extends UnknownRecord | UnknownArray>(oldObj: T extends UnknownArray ? ArrayToRecord<T> : T, newObj: T extends UnknownArray ? ArrayToRecord<T> : T) => DiffResult<T>;
|
|
32
|
+
export { type ArrayToRecord, type DiffResult, diff, isEqual, type UnknownRecord, type UnknownArray, type PartialRecord, };
|
package/types/src/store.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type PartialRecord, type UnknownArray, type UnknownRecord } from './diff';
|
|
2
2
|
import { type State } from './state';
|
|
3
3
|
import { type Cleanup } from './system';
|
|
4
4
|
type ArrayItem<T> = T extends readonly (infer U extends {})[] ? U : never;
|
|
5
5
|
type StoreChanges<T> = {
|
|
6
|
-
add:
|
|
7
|
-
change:
|
|
8
|
-
remove:
|
|
6
|
+
add: PartialRecord<T>;
|
|
7
|
+
change: PartialRecord<T>;
|
|
8
|
+
remove: PartialRecord<T>;
|
|
9
9
|
sort: string[];
|
|
10
10
|
};
|
|
11
11
|
interface BaseStore {
|
|
12
12
|
readonly [Symbol.toStringTag]: 'Store';
|
|
13
|
-
readonly
|
|
13
|
+
readonly length: number;
|
|
14
14
|
}
|
|
15
15
|
type RecordStore<T extends UnknownRecord> = BaseStore & {
|
|
16
16
|
[K in keyof T]: T[K] extends readonly unknown[] | Record<string, unknown> ? Store<T[K]> : State<T[K]>;
|
|
@@ -38,7 +38,6 @@ type ArrayStore<T extends UnknownArray> = BaseStore & {
|
|
|
38
38
|
sort<U = ArrayItem<T>>(compareFn?: (a: U, b: U) => number): void;
|
|
39
39
|
on<K extends keyof StoreChanges<T>>(type: K, listener: (change: StoreChanges<T>[K]) => void): Cleanup;
|
|
40
40
|
remove(index: number): void;
|
|
41
|
-
readonly length: number;
|
|
42
41
|
};
|
|
43
42
|
type Store<T extends UnknownRecord | UnknownArray> = T extends UnknownRecord ? RecordStore<T> : T extends UnknownArray ? ArrayStore<T> : never;
|
|
44
43
|
declare const TYPE_STORE = "Store";
|
|
@@ -62,5 +61,5 @@ declare const createStore: <T extends UnknownRecord | UnknownArray>(initialValue
|
|
|
62
61
|
* @param {unknown} value - value to check
|
|
63
62
|
* @returns {boolean} - true if the value is a Store instance, false otherwise
|
|
64
63
|
*/
|
|
65
|
-
declare const isStore: <T extends
|
|
64
|
+
declare const isStore: <T extends UnknownRecord | UnknownArray>(value: unknown) => value is Store<T>;
|
|
66
65
|
export { TYPE_STORE, isStore, createStore, type Store, type StoreChanges };
|