Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[FIX]: #1529 Watch Local Storage Changes#1652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletionsclient/packages/lowcoder/src/comps/hooks/localStorageComp.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,21 +13,28 @@ const APP_STORE_NAMESPACE = "lowcoder_app_local_storage";
const LocalStorageCompBase = withViewFn(
simpleMultiComp({ values: stateComp<JSONObject>({}) }),
(comp) => {
const originStore = localStorage.getItem(APP_STORE_NAMESPACE) || "{}";
let parseStore = {};
try {
parseStore = JSON.parse(originStore);
} catch (e) {
log.error("application local storage invalid");
}

// add custom event listener to update values reactively
useEffect(() => {
const value = comp.children.values.value;
if (!isEqual(value, parseStore)) {
log.info(value, parseStore);
comp.children.values.dispatchChangeValueAction(parseStore);
}
}, [parseStore]);
const handler = () => {
try {
const raw = localStorage.getItem(APP_STORE_NAMESPACE) || "{}";
const parsed = JSON.parse(raw);
comp.children.values.dispatchChangeValueAction(parsed);
} catch (e) {
log.error("Failed to parse localStorage:", e);
}
};

// Add listener on mount
window.addEventListener("lowcoder-localstorage-updated", handler);

// Run once on mount to initialize
handler();

return () => {
window.removeEventListener("lowcoder-localstorage-updated", handler);
};
}, []);

return null;
}
Expand DownExpand Up@@ -62,6 +69,8 @@ LocalStorageComp = withMethodExposing(LocalStorageComp, [
parseStore[key] = value;
localStorage.setItem(APP_STORE_NAMESPACE, JSON.stringify(parseStore));
comp.children.values.dispatchChangeValueAction(parseStore);

window.dispatchEvent(new CustomEvent("lowcoder-localstorage-updated"));
} catch (e) {
localStorage.setItem(APP_STORE_NAMESPACE, "{}");
}
Expand All@@ -83,6 +92,9 @@ LocalStorageComp = withMethodExposing(LocalStorageComp, [
delete parseStore[key];
localStorage.setItem(APP_STORE_NAMESPACE, JSON.stringify(parseStore));
comp.children.values.dispatchChangeValueAction(parseStore);

// Trigger update
window.dispatchEvent(new CustomEvent("lowcoder-localstorage-updated"));
} catch (e) {
localStorage.setItem(APP_STORE_NAMESPACE, "{}");
}
Expand All@@ -98,6 +110,9 @@ LocalStorageComp = withMethodExposing(LocalStorageComp, [
execute: (comp) => {
localStorage.removeItem(APP_STORE_NAMESPACE);
comp.children.values.dispatchChangeValueAction({});

// Trigger update
window.dispatchEvent(new CustomEvent("lowcoder-localstorage-updated"));
},
},
]);
Loading

[8]ページ先頭

©2009-2025 Movatter.jp