pocket-state 0.1.22 → 0.1.23
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 +1 -1
- package/src/globalState/store.ts +15 -0
package/package.json
CHANGED
package/src/globalState/store.ts
CHANGED
|
@@ -125,7 +125,22 @@ export function createStore<T>(
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
function resetToInitialState() {
|
|
129
|
+
const cloned = Array.isArray(initialState)
|
|
130
|
+
? initialState.slice()
|
|
131
|
+
: initialState && typeof initialState === 'object'
|
|
132
|
+
? {...initialState}
|
|
133
|
+
: initialState;
|
|
134
|
+
state = cloned as T;
|
|
135
|
+
emitState();
|
|
136
|
+
}
|
|
137
|
+
|
|
128
138
|
function reset(initialValue?: T | Partial<T>) {
|
|
139
|
+
if (initialState === undefined) {
|
|
140
|
+
resetToInitialState();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
129
144
|
const isObj = (
|
|
130
145
|
v: unknown,
|
|
131
146
|
): v is Record<string | symbol | number, unknown> =>
|