@mhmo91/schmancy 0.2.140 → 0.2.142
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/card.cjs +1 -1
- package/dist/card.js +1 -1
- package/dist/content-drawer.cjs +1 -1
- package/dist/content-drawer.js +1 -1
- package/dist/context-array-BrljBA5R.cjs +2 -0
- package/dist/context-array-BrljBA5R.cjs.map +1 -0
- package/dist/context-array-CSGdoQ1W.js +923 -0
- package/dist/context-array-CSGdoQ1W.js.map +1 -0
- package/dist/extra.cjs +1 -1
- package/dist/extra.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +102 -92
- package/dist/mixins/tailwind.css +5 -0
- package/dist/nav-drawer.cjs +1 -1
- package/dist/nav-drawer.js +1 -1
- package/dist/selector-hook-0691Losv.js +323 -0
- package/dist/selector-hook-0691Losv.js.map +1 -0
- package/dist/selector-hook-SzNTYQII.cjs +2 -0
- package/dist/selector-hook-SzNTYQII.cjs.map +1 -0
- package/dist/store.cjs +1 -1
- package/dist/store.js +33 -23
- package/dist/teleport.cjs +1 -1
- package/dist/{teleport.component-CqG_93Gb.js → teleport.component-Du14Yyxz.js} +3 -3
- package/dist/{teleport.component-CqG_93Gb.js.map → teleport.component-Du14Yyxz.js.map} +1 -1
- package/dist/{teleport.component-C6QSf6Kd.cjs → teleport.component-Vicu2fPa.cjs} +2 -2
- package/dist/{teleport.component-C6QSf6Kd.cjs.map → teleport.component-Vicu2fPa.cjs.map} +1 -1
- package/dist/teleport.js +1 -1
- package/dist/{timezone-Bh92BXoh.cjs → timezone-2Eb26kSx.cjs} +1 -3
- package/dist/timezone-2Eb26kSx.cjs.map +1 -0
- package/dist/{timezone-95O0-5pe.js → timezone-C8cbkh7P.js} +1 -3
- package/dist/timezone-C8cbkh7P.js.map +1 -0
- package/package.json +2 -1
- package/types/src/store/context-array.d.ts +83 -0
- package/types/src/store/context-collection.d.ts +20 -41
- package/types/src/store/context-create.d.ts +31 -9
- package/types/src/store/context-object.d.ts +14 -43
- package/types/src/store/filter-directive.d.ts +62 -5
- package/types/src/store/immer-integration.d.ts +60 -0
- package/types/src/store/selector-hook.d.ts +4 -0
- package/types/src/store/selectors.d.ts +29 -20
- package/types/src/store/store.class.d.ts +67 -0
- package/types/src/store/types.d.ts +102 -0
- package/dist/context-object-BDXZ5EKJ.js +0 -306
- package/dist/context-object-BDXZ5EKJ.js.map +0 -1
- package/dist/context-object-BIywslrO.cjs +0 -2
- package/dist/context-object-BIywslrO.cjs.map +0 -1
- package/dist/selector-hook-C6VCezv7.js +0 -273
- package/dist/selector-hook-C6VCezv7.js.map +0 -1
- package/dist/selector-hook-DDaYMsHs.cjs +0 -2
- package/dist/selector-hook-DDaYMsHs.cjs.map +0 -1
- package/dist/timezone-95O0-5pe.js.map +0 -1
- package/dist/timezone-Bh92BXoh.cjs.map +0 -1
|
@@ -1,41 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IStore, StorageType
|
|
1
|
+
import { BaseStore } from './store.class';
|
|
2
|
+
import { IStore, StorageType } from './types';
|
|
3
3
|
/**
|
|
4
|
-
* Enhanced store object with better TypeScript support
|
|
4
|
+
* Enhanced store object with better TypeScript support and immutability
|
|
5
|
+
* Now extends BaseStore for common functionality and uses Immer
|
|
5
6
|
*/
|
|
6
|
-
export declare class SchmancyStoreObject<T extends Record<string, any>> implements IStore<T> {
|
|
7
|
-
private storageType;
|
|
8
|
-
private key;
|
|
7
|
+
export declare class SchmancyStoreObject<T extends Record<string, any>> extends BaseStore<T> implements IStore<T> {
|
|
9
8
|
static type: string;
|
|
10
9
|
private static instances;
|
|
11
|
-
private _ready;
|
|
12
|
-
private _destroy$;
|
|
13
|
-
$: BehaviorSubject<T>;
|
|
14
|
-
error$: BehaviorSubject<StoreError<unknown>>;
|
|
15
|
-
readonly defaultValue: T;
|
|
16
|
-
private storage;
|
|
17
|
-
/**
|
|
18
|
-
* Get store ready state
|
|
19
|
-
*/
|
|
20
|
-
get ready(): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Set store ready state
|
|
23
|
-
*/
|
|
24
|
-
set ready(value: boolean);
|
|
25
|
-
/**
|
|
26
|
-
* Private constructor to enforce singleton pattern
|
|
27
|
-
*/
|
|
28
|
-
private constructor();
|
|
29
10
|
/**
|
|
30
11
|
* Static method to get or create an instance with strong typing
|
|
31
12
|
*/
|
|
32
13
|
static getInstance<T extends Record<string, any>>(storage: StorageType, key: string, defaultValue: T): SchmancyStoreObject<T>;
|
|
33
14
|
/**
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
|
-
get value(): T;
|
|
37
|
-
/**
|
|
38
|
-
* Set state with proper typing
|
|
15
|
+
* Set state with proper typing and immutability using Immer
|
|
39
16
|
*/
|
|
40
17
|
set(value: Partial<T>, merge?: boolean): void;
|
|
41
18
|
/**
|
|
@@ -43,27 +20,21 @@ export declare class SchmancyStoreObject<T extends Record<string, any>> implemen
|
|
|
43
20
|
*/
|
|
44
21
|
clear(): void;
|
|
45
22
|
/**
|
|
46
|
-
*
|
|
47
|
-
*/
|
|
48
|
-
replace(newValue: T): void;
|
|
49
|
-
/**
|
|
50
|
-
* Delete a specific key from the store with type checking
|
|
23
|
+
* Delete a specific key from the store with type checking and immutability
|
|
51
24
|
*/
|
|
52
25
|
delete<K extends keyof T>(key: K): void;
|
|
53
26
|
/**
|
|
54
|
-
* Update
|
|
27
|
+
* Update a nested property at a specific path
|
|
28
|
+
* @param path Dot-separated path to the property (e.g., 'user.profile.name')
|
|
29
|
+
* @param value New value to set
|
|
55
30
|
*/
|
|
56
|
-
|
|
31
|
+
setPath(path: string, value: any): void;
|
|
57
32
|
/**
|
|
58
|
-
*
|
|
33
|
+
* Process stored value by merging with default value
|
|
59
34
|
*/
|
|
60
|
-
|
|
35
|
+
protected processStoredValue(storedValue: T): T;
|
|
61
36
|
/**
|
|
62
37
|
* Setup development tools for debugging
|
|
63
38
|
*/
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Clean up resources
|
|
67
|
-
*/
|
|
68
|
-
destroy(): void;
|
|
39
|
+
protected setupDevTools(): void;
|
|
69
40
|
}
|
|
@@ -29,11 +29,6 @@ export interface ScoredItem<T> {
|
|
|
29
29
|
* Checks explicitly for null/undefined so falsy values like 0 or false are preserved.
|
|
30
30
|
*/
|
|
31
31
|
export declare const getFieldValue: <T = any>(item: Record<string, any>, path: string) => T;
|
|
32
|
-
/**
|
|
33
|
-
* Compare two values based on a comparison operator.
|
|
34
|
-
* For non-fuzzy operators, this returns a boolean.
|
|
35
|
-
*/
|
|
36
|
-
export declare function compareValues(op: ComparisonOperator, actual: unknown, expected: unknown): boolean;
|
|
37
32
|
/**
|
|
38
33
|
* Filter a Map of items given an array of query conditions.
|
|
39
34
|
* For each query condition:
|
|
@@ -55,5 +50,67 @@ export declare function filterMapItems<T extends Record<string, any>>(items: Map
|
|
|
55
50
|
* Filter an array of items using query conditions
|
|
56
51
|
*/
|
|
57
52
|
export declare function filterArrayItems<T extends Record<string, any>>(items: T[], queries?: QueryCondition[], fuzzyThreshold?: number): T[];
|
|
53
|
+
/**
|
|
54
|
+
* Type guard for checking if a value is an array with better type inference
|
|
55
|
+
* @param value Value to check
|
|
56
|
+
* @returns True if the value is an array
|
|
57
|
+
*/
|
|
58
|
+
export declare function isArray<T = unknown>(value: unknown): value is Array<T>;
|
|
59
|
+
/**
|
|
60
|
+
* Type guard for checking if a value is a string
|
|
61
|
+
* @param value Value to check
|
|
62
|
+
* @returns True if the value is a string
|
|
63
|
+
*/
|
|
64
|
+
export declare function isString(value: unknown): value is string;
|
|
65
|
+
/**
|
|
66
|
+
* Type guard for checking if a value is a number
|
|
67
|
+
* @param value Value to check
|
|
68
|
+
* @returns True if the value is a number and not NaN
|
|
69
|
+
*/
|
|
70
|
+
export declare function isNumber(value: unknown): value is number;
|
|
71
|
+
/**
|
|
72
|
+
* Type guard for checking if a value is a date
|
|
73
|
+
* @param value Value to check
|
|
74
|
+
* @returns True if the value is a valid Date object
|
|
75
|
+
*/
|
|
76
|
+
export declare function isDate(value: unknown): value is Date;
|
|
77
|
+
/**
|
|
78
|
+
* Type guard for checking if a value is an iterable collection
|
|
79
|
+
* @param value Value to check
|
|
80
|
+
* @returns True if the value implements the iterable protocol
|
|
81
|
+
*/
|
|
82
|
+
export declare function isIterable<T = unknown>(value: unknown): value is Iterable<T>;
|
|
83
|
+
/**
|
|
84
|
+
* Type guard for checking if a value is a Map
|
|
85
|
+
* @param value Value to check
|
|
86
|
+
* @returns True if the value is a Map
|
|
87
|
+
*/
|
|
88
|
+
export declare function isMap<K = unknown, V = unknown>(value: unknown): value is Map<K, V>;
|
|
89
|
+
/**
|
|
90
|
+
* Type guard for checking if a value is a Set
|
|
91
|
+
* @param value Value to check
|
|
92
|
+
* @returns True if the value is a Set
|
|
93
|
+
*/
|
|
94
|
+
export declare function isSet<T = unknown>(value: unknown): value is Set<T>;
|
|
95
|
+
/**
|
|
96
|
+
* Type guard for checking if a value is a plain object (not an array, Map, etc.)
|
|
97
|
+
* @param value Value to check
|
|
98
|
+
* @returns True if the value is a plain object
|
|
99
|
+
*/
|
|
100
|
+
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
101
|
+
/**
|
|
102
|
+
* Type guard for checking if a value is undefined or null
|
|
103
|
+
* @param value Value to check
|
|
104
|
+
* @returns True if the value is undefined or null
|
|
105
|
+
*/
|
|
106
|
+
export declare function isNil(value: unknown): value is undefined | null;
|
|
107
|
+
/**
|
|
108
|
+
* Improved type-safe comparison function that uses appropriate type guards
|
|
109
|
+
* @param op Comparison operator
|
|
110
|
+
* @param actual Actual value
|
|
111
|
+
* @param expected Expected value
|
|
112
|
+
* @returns Result of the comparison
|
|
113
|
+
*/
|
|
114
|
+
export declare function compareValues(op: ComparisonOperator, actual: unknown, expected: unknown): boolean;
|
|
58
115
|
export declare const filterMap: typeof filterMapItems;
|
|
59
116
|
export declare const filterArray: typeof filterArrayItems;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Draft, castDraft, castImmutable, Immutable } from 'immer';
|
|
2
|
+
/**
|
|
3
|
+
* Type-safe wrapper functions for immutable operations with Immer
|
|
4
|
+
*
|
|
5
|
+
* Re-export useful Immer types and utilities
|
|
6
|
+
*/
|
|
7
|
+
export { Draft, castDraft, castImmutable, Immutable };
|
|
8
|
+
/**
|
|
9
|
+
* Create an immutable update for Maps
|
|
10
|
+
* @param map Original Map to update
|
|
11
|
+
* @param updater Function that can make "mutable" changes to the draft
|
|
12
|
+
* @returns A new Map with the changes applied
|
|
13
|
+
*/
|
|
14
|
+
export declare function updateMap<K, V>(map: Immutable<Map<K, V>>, updater: (draft: Draft<Map<K, V>>) => void): Map<K, V>;
|
|
15
|
+
/**
|
|
16
|
+
* Create an immutable update for a specific item in a Map
|
|
17
|
+
* @param map Original Map to update
|
|
18
|
+
* @param key Key of the item to update
|
|
19
|
+
* @param updater Function that can make "mutable" changes to the item
|
|
20
|
+
* @returns A new Map with the item updated
|
|
21
|
+
*/
|
|
22
|
+
export declare function updateItem<K, V>(map: Immutable<Map<K, V>>, key: K, updater: (item: Draft<V>) => void): Map<K, V>;
|
|
23
|
+
/**
|
|
24
|
+
* Immutably filter a Map
|
|
25
|
+
* @param map Original Map to filter
|
|
26
|
+
* @param predicate Function that returns true for items to keep
|
|
27
|
+
* @returns A new Map with only the matching items
|
|
28
|
+
*/
|
|
29
|
+
export declare function filterMap<K, V>(map: Immutable<Map<K, V>>, predicate: (value: Immutable<V>, key: Immutable<K>) => boolean): Map<K, V>;
|
|
30
|
+
/**
|
|
31
|
+
* Create an immutable update for an object
|
|
32
|
+
* @param obj Original object to update
|
|
33
|
+
* @param updater Function that can make "mutable" changes to the draft
|
|
34
|
+
* @returns A new object with the changes applied
|
|
35
|
+
*/
|
|
36
|
+
export declare function updateObject<T extends Record<string, any>>(obj: Immutable<T>, updater: (draft: Draft<T>) => void): T;
|
|
37
|
+
/**
|
|
38
|
+
* Merge objects immutably
|
|
39
|
+
* @param target Original object
|
|
40
|
+
* @param source Source object to merge in
|
|
41
|
+
* @returns A new object with properties merged
|
|
42
|
+
*/
|
|
43
|
+
export declare function mergeObjects<T extends Record<string, any>>(target: Immutable<T>, source: Partial<T>): T;
|
|
44
|
+
/**
|
|
45
|
+
* Type guard to check if an object is a Map
|
|
46
|
+
*/
|
|
47
|
+
export declare function isMap<K = unknown, V = unknown>(value: unknown): value is Map<K, V>;
|
|
48
|
+
/**
|
|
49
|
+
* Creates a readonly version of a type
|
|
50
|
+
* This is a utility that uses Immer's Immutable type to make a type readonly
|
|
51
|
+
* @param value The value to cast as immutable
|
|
52
|
+
* @returns The same value but typed as immutable
|
|
53
|
+
*/
|
|
54
|
+
export declare function asReadonly<T>(value: T): Immutable<T>;
|
|
55
|
+
/**
|
|
56
|
+
* Makes an object or Map deeply immutable at runtime by freezing
|
|
57
|
+
* @param value The value to freeze
|
|
58
|
+
* @returns The frozen value
|
|
59
|
+
*/
|
|
60
|
+
export declare function freeze<T>(value: T): Immutable<T>;
|
|
@@ -22,9 +22,12 @@ interface SelectOptions {
|
|
|
22
22
|
deepClone?: boolean;
|
|
23
23
|
/** Custom equality function to determine when to update */
|
|
24
24
|
equals?: (a: any, b: any) => boolean;
|
|
25
|
+
/** Debug mode - logs selector activity */
|
|
26
|
+
debug?: boolean;
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
29
|
* Selector decorator that connects a component property to a store selector
|
|
30
|
+
* with improved memory management
|
|
28
31
|
*
|
|
29
32
|
* @param store The store to select from
|
|
30
33
|
* @param selectorFn Optional function to transform the store state
|
|
@@ -33,6 +36,7 @@ interface SelectOptions {
|
|
|
33
36
|
export declare function select<T, R>(store: IStore<T> | ICollectionStore<T>, selectorFn?: (state: any) => R, options?: SelectOptions): (proto: Record<string, any>, propName: string, _descriptor?: PropertyDescriptor<R>) => void;
|
|
34
37
|
/**
|
|
35
38
|
* Creates a selector decorator that selects a specific item from a collection store
|
|
39
|
+
* with improved memory management
|
|
36
40
|
*
|
|
37
41
|
* @param store The collection store
|
|
38
42
|
* @param keyGetter Function that returns the key to select
|
|
@@ -23,14 +23,6 @@ export declare function createCollectionSelector<T, R>(store: ICollectionStore<T
|
|
|
23
23
|
* @returns An observable of all items as an array
|
|
24
24
|
*/
|
|
25
25
|
export declare function createItemsSelector<T>(store: ICollectionStore<T>): Observable<T[]>;
|
|
26
|
-
/**
|
|
27
|
-
* Creates a selector that filters items from a collection
|
|
28
|
-
*
|
|
29
|
-
* @param store The collection store
|
|
30
|
-
* @param filterFn Function that returns true for items to include
|
|
31
|
-
* @returns An observable of filtered items as an array
|
|
32
|
-
*/
|
|
33
|
-
export declare function createFilterSelector<T>(store: ICollectionStore<T>, filterFn: (item: T, key: string) => boolean): Observable<T[]>;
|
|
34
26
|
/**
|
|
35
27
|
* Creates a selector that retrieves a single item from a collection
|
|
36
28
|
*
|
|
@@ -39,14 +31,6 @@ export declare function createFilterSelector<T>(store: ICollectionStore<T>, filt
|
|
|
39
31
|
* @returns An observable of the selected item that emits when the item changes
|
|
40
32
|
*/
|
|
41
33
|
export declare function createItemSelector<T>(store: ICollectionStore<T>, itemKey: string): Observable<T | undefined>;
|
|
42
|
-
/**
|
|
43
|
-
* Creates a selector that counts items in a collection, optionally filtered
|
|
44
|
-
*
|
|
45
|
-
* @param store The collection store
|
|
46
|
-
* @param filterFn Optional function to filter which items to count
|
|
47
|
-
* @returns An observable of the count
|
|
48
|
-
*/
|
|
49
|
-
export declare function createCountSelector<T>(store: ICollectionStore<T>, filterFn?: (item: T, key: string) => boolean): Observable<number>;
|
|
50
34
|
/**
|
|
51
35
|
* Creates a compound selector that depends on multiple other selectors
|
|
52
36
|
*
|
|
@@ -65,10 +49,6 @@ export declare function createKeysSelector<T>(store: ICollectionStore<T>): Obser
|
|
|
65
49
|
* Creates a selector that returns entries (key-value pairs) from a collection
|
|
66
50
|
*/
|
|
67
51
|
export declare function createEntriesSelector<T>(store: ICollectionStore<T>): Observable<[string, T][]>;
|
|
68
|
-
/**
|
|
69
|
-
* Creates a selector that maps collection values through a transform function
|
|
70
|
-
*/
|
|
71
|
-
export declare function createMapSelector<T, R>(store: ICollectionStore<T>, mapFn: (item: T, key: string) => R): Observable<R[]>;
|
|
72
52
|
/**
|
|
73
53
|
* Creates a selector that sorts collection items
|
|
74
54
|
*/
|
|
@@ -77,3 +57,32 @@ export declare function createSortSelector<T>(store: ICollectionStore<T>, compar
|
|
|
77
57
|
* Creates a selector that finds the first item matching a predicate
|
|
78
58
|
*/
|
|
79
59
|
export declare function createFindSelector<T>(store: ICollectionStore<T>, predicate: (item: T, key: string) => boolean): Observable<T | undefined>;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a selector that filters items from a collection - OPTIMIZED
|
|
62
|
+
*
|
|
63
|
+
* @param store The collection store
|
|
64
|
+
* @param filterFn Function that returns true for items to include
|
|
65
|
+
* @returns An observable of filtered items as an array
|
|
66
|
+
*/
|
|
67
|
+
export declare function createFilterSelector<T>(store: ICollectionStore<T>, filterFn: (item: T, key: string) => boolean): Observable<T[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Creates a selector that maps collection values through a transform function - OPTIMIZED
|
|
70
|
+
*/
|
|
71
|
+
export declare function createMapSelector<T, R>(store: ICollectionStore<T>, mapFn: (item: T, key: string) => R): Observable<R[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Creates a selector that counts items in a collection, optionally filtered - OPTIMIZED
|
|
74
|
+
*
|
|
75
|
+
* @param store The collection store
|
|
76
|
+
* @param filterFn Optional function to filter which items to count
|
|
77
|
+
* @returns An observable of the count
|
|
78
|
+
*/
|
|
79
|
+
export declare function createCountSelector<T>(store: ICollectionStore<T>, filterFn?: (item: T, key: string) => boolean): Observable<number>;
|
|
80
|
+
/**
|
|
81
|
+
* Optimized RxJS Pipeline - use share with reset on refCount zero for better memory management
|
|
82
|
+
* in scenarios where selector subscriptions come and go
|
|
83
|
+
*
|
|
84
|
+
* @param store The store to observe
|
|
85
|
+
* @param selectorFn Function that transforms the state
|
|
86
|
+
* @returns An observable of the selected state with improved memory management
|
|
87
|
+
*/
|
|
88
|
+
export declare function createOptimizedSelector<T, R>(store: IStore<T>, selectorFn: (state: T) => R): Observable<R>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { BehaviorSubject, Subject } from 'rxjs';
|
|
2
|
+
import { IStorageManager, StorageType, StoreError } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Base store class to handle common functionality between store types
|
|
5
|
+
* Now with Immer integration for immutability
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class BaseStore<T> {
|
|
8
|
+
protected storageType: StorageType;
|
|
9
|
+
protected key: string;
|
|
10
|
+
protected _ready: boolean;
|
|
11
|
+
protected _destroy$: Subject<void>;
|
|
12
|
+
$: BehaviorSubject<T>;
|
|
13
|
+
error$: BehaviorSubject<StoreError<unknown>>;
|
|
14
|
+
readonly defaultValue: T;
|
|
15
|
+
protected storage: IStorageManager<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Get store ready state
|
|
18
|
+
*/
|
|
19
|
+
get ready(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Set store ready state
|
|
22
|
+
*/
|
|
23
|
+
set ready(value: boolean);
|
|
24
|
+
/**
|
|
25
|
+
* Get the current value
|
|
26
|
+
*/
|
|
27
|
+
get value(): T;
|
|
28
|
+
/**
|
|
29
|
+
* Initialize the base store
|
|
30
|
+
* @param storageType Storage type to use
|
|
31
|
+
* @param key Unique key for the store
|
|
32
|
+
* @param defaultValue Default/initial value
|
|
33
|
+
*/
|
|
34
|
+
constructor(storageType: StorageType, key: string, defaultValue: T);
|
|
35
|
+
/**
|
|
36
|
+
* Cleanup method for all store types
|
|
37
|
+
*/
|
|
38
|
+
destroy(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Replace the entire store state immutably
|
|
41
|
+
*/
|
|
42
|
+
replace(newValue: T): void;
|
|
43
|
+
/**
|
|
44
|
+
* Reset to default value - to be implemented by subclasses
|
|
45
|
+
*/
|
|
46
|
+
abstract clear(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Update the state with proper error handling and immutability
|
|
49
|
+
*/
|
|
50
|
+
protected updateState(newValue: T): void;
|
|
51
|
+
/**
|
|
52
|
+
* Initialize the store from persistent storage
|
|
53
|
+
*/
|
|
54
|
+
protected initializeFromStorage(): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Process stored value (can be overridden by subclasses)
|
|
57
|
+
*/
|
|
58
|
+
protected processStoredValue(storedValue: T): T;
|
|
59
|
+
/**
|
|
60
|
+
* Persist state to storage
|
|
61
|
+
*/
|
|
62
|
+
protected persistToStorage(state: T): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Setup development tools
|
|
65
|
+
*/
|
|
66
|
+
protected abstract setupDevTools(): void;
|
|
67
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Draft } from 'immer';
|
|
1
2
|
import { BehaviorSubject, Observable } from 'rxjs';
|
|
2
3
|
/**
|
|
3
4
|
* Storage types supported by the store
|
|
@@ -137,3 +138,104 @@ export type StoreFactory = <T extends Record<string, any>>(initialData: T, stora
|
|
|
137
138
|
* Factory function type for creating collection stores
|
|
138
139
|
*/
|
|
139
140
|
export type CollectionStoreFactory = <T>(initialData: Map<string, T>, storage: StorageType, key: string) => ICollectionStore<T>;
|
|
141
|
+
/**
|
|
142
|
+
* Interface for array stores with improved typing
|
|
143
|
+
*/
|
|
144
|
+
export interface IArrayStore<T> {
|
|
145
|
+
/** Get the current array value */
|
|
146
|
+
readonly value: T[];
|
|
147
|
+
/** Observable stream of array values */
|
|
148
|
+
readonly $: BehaviorSubject<T[]>;
|
|
149
|
+
/** The default/initial value of the array */
|
|
150
|
+
readonly defaultValue: T[];
|
|
151
|
+
/** Whether the store is ready (loaded from storage) */
|
|
152
|
+
ready: boolean;
|
|
153
|
+
/** Observable stream of store errors */
|
|
154
|
+
readonly error$: Observable<StoreError | null>;
|
|
155
|
+
/**
|
|
156
|
+
* Add item(s) to the end of the array
|
|
157
|
+
* @param items Items to add
|
|
158
|
+
*/
|
|
159
|
+
push(...items: T[]): void;
|
|
160
|
+
/**
|
|
161
|
+
* Remove and return the last item from the array
|
|
162
|
+
* @returns The removed item or undefined if the array was empty
|
|
163
|
+
*/
|
|
164
|
+
pop(): T | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* Add item(s) to the beginning of the array
|
|
167
|
+
* @param items Items to add
|
|
168
|
+
*/
|
|
169
|
+
unshift(...items: T[]): void;
|
|
170
|
+
/**
|
|
171
|
+
* Remove and return the first item from the array
|
|
172
|
+
* @returns The removed item or undefined if the array was empty
|
|
173
|
+
*/
|
|
174
|
+
shift(): T | undefined;
|
|
175
|
+
/**
|
|
176
|
+
* Update an item at a specific index
|
|
177
|
+
* @param index The index to update
|
|
178
|
+
* @param value The new value
|
|
179
|
+
*/
|
|
180
|
+
set(index: number, value: T): void;
|
|
181
|
+
/**
|
|
182
|
+
* Get the item at a specific index
|
|
183
|
+
* @param index The index to get
|
|
184
|
+
* @returns The item or undefined if index is out of bounds
|
|
185
|
+
*/
|
|
186
|
+
get(index: number): T | undefined;
|
|
187
|
+
/**
|
|
188
|
+
* Remove items from the array and optionally insert new ones
|
|
189
|
+
* @param start The start index
|
|
190
|
+
* @param deleteCount The number of items to delete
|
|
191
|
+
* @param items Items to insert
|
|
192
|
+
* @returns The removed items
|
|
193
|
+
*/
|
|
194
|
+
splice(start: number, deleteCount?: number, ...items: T[]): T[];
|
|
195
|
+
/**
|
|
196
|
+
* Remove an item by value (first occurrence)
|
|
197
|
+
* @param item The item to remove
|
|
198
|
+
* @param compareFn Optional function to compare items
|
|
199
|
+
* @returns True if the item was found and removed
|
|
200
|
+
*/
|
|
201
|
+
remove(item: T, compareFn?: (a: T, b: T) => boolean): boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Replace the entire array
|
|
204
|
+
* @param newArray The new array
|
|
205
|
+
*/
|
|
206
|
+
replace(newArray: T[]): void;
|
|
207
|
+
/**
|
|
208
|
+
* Filter items in the array
|
|
209
|
+
* @param predicate Function to test each item
|
|
210
|
+
*/
|
|
211
|
+
filter(predicate: (value: T, index: number, array: T[]) => boolean): void;
|
|
212
|
+
/**
|
|
213
|
+
* Map over the array and transform items
|
|
214
|
+
* @param mapper Function to transform each item
|
|
215
|
+
* @returns Array of transformed items
|
|
216
|
+
*/
|
|
217
|
+
map<U>(mapper: (value: T, index: number, array: T[]) => U): U[];
|
|
218
|
+
/**
|
|
219
|
+
* Sort the array in place
|
|
220
|
+
* @param compareFn Optional function to determine sort order
|
|
221
|
+
*/
|
|
222
|
+
sort(compareFn?: (a: T, b: T) => number): void;
|
|
223
|
+
/**
|
|
224
|
+
* Update a specific item using a callback function
|
|
225
|
+
* @param index The index to update
|
|
226
|
+
* @param updater Function that can modify the item
|
|
227
|
+
*/
|
|
228
|
+
update(index: number, updater: (item: Draft<T>) => void): void;
|
|
229
|
+
/**
|
|
230
|
+
* Clear all items from the array
|
|
231
|
+
*/
|
|
232
|
+
clear(): void;
|
|
233
|
+
/**
|
|
234
|
+
* Clean up resources
|
|
235
|
+
*/
|
|
236
|
+
destroy(): void;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Factory function type for creating array stores
|
|
240
|
+
*/
|
|
241
|
+
export type ArrayStoreFactory = <T>(initialData: T[], storage: StorageType, key: string) => IArrayStore<T>;
|