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

Commit0a2bddd

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

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

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

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,28 @@ 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+
comp.children.values.dispatchChangeValueAction(parsed);
23+
}catch(e){
24+
log.error("Failed to parse localStorage:",e);
25+
}
26+
};
27+
28+
// Add listener on mount
29+
window.addEventListener("lowcoder-localstorage-updated",handler);
30+
31+
// Run once on mount to initialize
32+
handler();
33+
34+
return()=>{
35+
window.removeEventListener("lowcoder-localstorage-updated",handler);
36+
};
37+
},[]);
3138

3239
returnnull;
3340
}
@@ -62,6 +69,8 @@ LocalStorageComp = withMethodExposing(LocalStorageComp, [
6269
parseStore[key]=value;
6370
localStorage.setItem(APP_STORE_NAMESPACE,JSON.stringify(parseStore));
6471
comp.children.values.dispatchChangeValueAction(parseStore);
72+
73+
window.dispatchEvent(newCustomEvent("lowcoder-localstorage-updated"));
6574
}catch(e){
6675
localStorage.setItem(APP_STORE_NAMESPACE,"{}");
6776
}
@@ -83,6 +92,9 @@ LocalStorageComp = withMethodExposing(LocalStorageComp, [
8392
deleteparseStore[key];
8493
localStorage.setItem(APP_STORE_NAMESPACE,JSON.stringify(parseStore));
8594
comp.children.values.dispatchChangeValueAction(parseStore);
95+
96+
// Trigger update
97+
window.dispatchEvent(newCustomEvent("lowcoder-localstorage-updated"));
8698
}catch(e){
8799
localStorage.setItem(APP_STORE_NAMESPACE,"{}");
88100
}
@@ -98,6 +110,9 @@ LocalStorageComp = withMethodExposing(LocalStorageComp, [
98110
execute:(comp)=>{
99111
localStorage.removeItem(APP_STORE_NAMESPACE);
100112
comp.children.values.dispatchChangeValueAction({});
113+
114+
// Trigger update
115+
window.dispatchEvent(newCustomEvent("lowcoder-localstorage-updated"));
101116
},
102117
},
103118
]);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp