@umituz/react-native-storage 2.6.9 → 2.6.11
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-storage",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.11",
|
|
4
4
|
"description": "Unified storage solution with AsyncStorage persistence, Zustand state management, and in-memory caching for React Native",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { create } from 'zustand';
|
|
7
7
|
import { persist, createJSONStorage } from 'zustand/middleware';
|
|
8
|
+
import type { StoreApi } from 'zustand';
|
|
8
9
|
import type { StoreConfig } from '../types/Store';
|
|
9
10
|
import { storageService } from '../../infrastructure/adapters/StorageService';
|
|
10
11
|
|
|
@@ -16,9 +17,10 @@ export function createStore<
|
|
|
16
17
|
TActions extends object = object
|
|
17
18
|
>(config: StoreConfig<TState, TActions>) {
|
|
18
19
|
type Store = TState & TActions;
|
|
20
|
+
type SetState = StoreApi<Store>['setState'];
|
|
21
|
+
type GetState = StoreApi<Store>['getState'];
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
const stateCreator = (set: any, get: any): Store => {
|
|
23
|
+
const stateCreator = (set: SetState, get: GetState): Store => {
|
|
22
24
|
const state = config.initialState as TState;
|
|
23
25
|
const actions = config.actions
|
|
24
26
|
? config.actions(set, get)
|
|
@@ -37,8 +39,8 @@ export function createStore<
|
|
|
37
39
|
version: config.version || 1,
|
|
38
40
|
partialize: config.partialize
|
|
39
41
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
-
? (state) => config.partialize!(state as any) as any
|
|
41
|
-
: (state) => {
|
|
42
|
+
? (state: Store) => config.partialize!(state as any) as any
|
|
43
|
+
: (state: Store) => {
|
|
42
44
|
const persisted: Record<string, unknown> = {};
|
|
43
45
|
for (const key of Object.keys(state)) {
|
|
44
46
|
if (typeof state[key as keyof Store] !== 'function') {
|
|
@@ -48,7 +50,7 @@ export function createStore<
|
|
|
48
50
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
51
|
return persisted as any;
|
|
50
52
|
},
|
|
51
|
-
onRehydrateStorage: () => (state) => {
|
|
53
|
+
onRehydrateStorage: () => (state: Store | undefined) => {
|
|
52
54
|
if (state && config.onRehydrate) {
|
|
53
55
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
56
|
config.onRehydrate(state as any);
|