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

Commit4dde035

Browse files
committed
[FIX]:#1529 Watch Local Storage Values
1 parent4bcbc11 commit4dde035

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

‎client/packages/lowcoder/src/comps/hooks/localStorageComp.ts

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,29 @@ const APP_STORE_NAMESPACE = "lowcoder_app_local_storage";
1313
constLocalStorageCompBase=withViewFn(
1414
simpleMultiComp({values:stateComp<JSONObject>({})}),
1515
(comp)=>{
16-
constoriginStore=localStorage.getItem(APP_STORE_NAMESPACE)||"{}";
17-
letparseStore={};
18-
try{
19-
parseStore=JSON.parse(originStore);
20-
}catch(e){
21-
log.error("application local storage invalid");
22-
}
23-
16+
// add custom event listener to update values reactively
2417
useEffect(()=>{
25-
constvalue=comp.children.values.value;
26-
if(!isEqual(value,parseStore)){
27-
log.info(value,parseStore);
28-
comp.children.values.dispatchChangeValueAction(parseStore);
29-
}
30-
},[parseStore]);
18+
consthandler=()=>{
19+
try{
20+
constraw=localStorage.getItem(APP_STORE_NAMESPACE)||"{}";
21+
constparsed=JSON.parse(raw);
22+
console.log("[LocalStorageComp] Custom event received:",parsed);
23+
comp.children.values.dispatchChangeValueAction(parsed);
24+
}catch(e){
25+
log.error("Failed to parse localStorage:",e);
26+
}
27+
};
28+
29+
// Add listener on mount
30+
window.addEventListener("lowcoder-localstorage-updated",handler);
31+
32+
// Run once on mount to initialize
33+
handler();
34+
35+
return()=>{
36+
window.removeEventListener("lowcoder-localstorage-updated",handler);
37+
};
38+
},[]);
3139

3240
returnnull;
3341
}
@@ -62,6 +70,8 @@ LocalStorageComp = withMethodExposing(LocalStorageComp, [
6270
parseStore[key]=value;
6371
localStorage.setItem(APP_STORE_NAMESPACE,JSON.stringify(parseStore));
6472
comp.children.values.dispatchChangeValueAction(parseStore);
73+
74+
window.dispatchEvent(newCustomEvent("lowcoder-localstorage-updated"));
6575
}catch(e){
6676
localStorage.setItem(APP_STORE_NAMESPACE,"{}");
6777
}
@@ -83,6 +93,9 @@ LocalStorageComp = withMethodExposing(LocalStorageComp, [
8393
deleteparseStore[key];
8494
localStorage.setItem(APP_STORE_NAMESPACE,JSON.stringify(parseStore));
8595
comp.children.values.dispatchChangeValueAction(parseStore);
96+
97+
// Trigger update
98+
window.dispatchEvent(newCustomEvent("lowcoder-localstorage-updated"));
8699
}catch(e){
87100
localStorage.setItem(APP_STORE_NAMESPACE,"{}");
88101
}
@@ -98,6 +111,9 @@ LocalStorageComp = withMethodExposing(LocalStorageComp, [
98111
execute:(comp)=>{
99112
localStorage.removeItem(APP_STORE_NAMESPACE);
100113
comp.children.values.dispatchChangeValueAction({});
114+
115+
// Trigger update
116+
window.dispatchEvent(newCustomEvent("lowcoder-localstorage-updated"));
101117
},
102118
},
103119
]);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp