feat(GlobalStateStore): prevent saving during initial load
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
# @warkypublic/zustandsyncstore
|
# @warkypublic/zustandsyncstore
|
||||||
|
|
||||||
|
## 0.0.37
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- feat(GlobalStateStore): prevent saving during initial load
|
||||||
|
|
||||||
## 0.0.36
|
## 0.0.36
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@warkypublic/oranguru",
|
"name": "@warkypublic/oranguru",
|
||||||
"author": "Warky Devs",
|
"author": "Warky Devs",
|
||||||
"version": "0.0.36",
|
"version": "0.0.37",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"types": "./dist/lib.d.ts",
|
"types": "./dist/lib.d.ts",
|
||||||
"main": "./dist/lib.cjs.js",
|
"main": "./dist/lib.cjs.js",
|
||||||
|
|||||||
@@ -301,6 +301,9 @@ const GlobalStateStore = createStore<GlobalStateStoreType>((set, get) => ({
|
|||||||
...createComplexActions(set, get),
|
...createComplexActions(set, get),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Flag to prevent saving during initial load
|
||||||
|
let isInitialLoad = true;
|
||||||
|
|
||||||
loadStorage()
|
loadStorage()
|
||||||
.then((state) => {
|
.then((state) => {
|
||||||
GlobalStateStore.setState((current) => ({
|
GlobalStateStore.setState((current) => ({
|
||||||
@@ -316,9 +319,18 @@ loadStorage()
|
|||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error('Error loading storage:', e);
|
console.error('Error loading storage:', e);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
// Enable saving after initial load completes
|
||||||
|
isInitialLoad = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
GlobalStateStore.subscribe((state) => {
|
GlobalStateStore.subscribe((state) => {
|
||||||
|
// Skip saving during initial load
|
||||||
|
if (isInitialLoad) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
saveStorage(state).catch((e) => {
|
saveStorage(state).catch((e) => {
|
||||||
console.error('Error saving storage:', e);
|
console.error('Error saving storage:', e);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import {
|
|||||||
import type { GlobalState, GlobalStateStoreType, ProgramState } from './GlobalStateStore.types';
|
import type { GlobalState, GlobalStateStoreType, ProgramState } from './GlobalStateStore.types';
|
||||||
|
|
||||||
import { GetGlobalState, GlobalStateStore } from './GlobalStateStore';
|
import { GetGlobalState, GlobalStateStore } from './GlobalStateStore';
|
||||||
import { loadStorage } from './GlobalStateStore.utils';
|
|
||||||
|
|
||||||
interface GlobalStateStoreContextValue {
|
interface GlobalStateStoreContextValue {
|
||||||
fetchData: (url?: string) => Promise<void>;
|
fetchData: (url?: string) => Promise<void>;
|
||||||
@@ -76,23 +75,6 @@ export function GlobalStateStoreProvider({
|
|||||||
await throttledFetch();
|
await throttledFetch();
|
||||||
}, [throttledFetch]);
|
}, [throttledFetch]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
loadStorage()
|
|
||||||
.then((state) => {
|
|
||||||
GlobalStateStore.setState((current) => ({
|
|
||||||
...current,
|
|
||||||
...state,
|
|
||||||
session: {
|
|
||||||
...current.session,
|
|
||||||
...state.session,
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
console.error('Error loading storage on mount:', e);
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (apiURL) {
|
if (apiURL) {
|
||||||
GlobalStateStore.getState().setApiURL(apiURL);
|
GlobalStateStore.getState().setApiURL(apiURL);
|
||||||
|
|||||||
Reference in New Issue
Block a user