@chromahq/store 1.0.54 → 1.0.55
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/dist/index.cjs.js +9 -1
- package/dist/index.es.js +9 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -61,6 +61,8 @@ function chromeStoragePersist(options = {}) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
|
+
let persistDebounceTimer = null;
|
|
65
|
+
const PERSIST_DEBOUNCE_MS = 500;
|
|
64
66
|
const persistState = async (state) => {
|
|
65
67
|
if (!chrome?.storage?.local) {
|
|
66
68
|
return;
|
|
@@ -78,7 +80,13 @@ function chromeStoragePersist(options = {}) {
|
|
|
78
80
|
if (persistenceSetup) return;
|
|
79
81
|
persistenceSetup = true;
|
|
80
82
|
store.subscribe((state) => {
|
|
81
|
-
|
|
83
|
+
if (persistDebounceTimer) {
|
|
84
|
+
clearTimeout(persistDebounceTimer);
|
|
85
|
+
}
|
|
86
|
+
persistDebounceTimer = setTimeout(() => {
|
|
87
|
+
persistDebounceTimer = null;
|
|
88
|
+
persistState(state);
|
|
89
|
+
}, PERSIST_DEBOUNCE_MS);
|
|
82
90
|
});
|
|
83
91
|
};
|
|
84
92
|
loadPersistedState();
|
package/dist/index.es.js
CHANGED
|
@@ -41,6 +41,8 @@ function chromeStoragePersist(options = {}) {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
|
+
let persistDebounceTimer = null;
|
|
45
|
+
const PERSIST_DEBOUNCE_MS = 500;
|
|
44
46
|
const persistState = async (state) => {
|
|
45
47
|
if (!chrome?.storage?.local) {
|
|
46
48
|
return;
|
|
@@ -58,7 +60,13 @@ function chromeStoragePersist(options = {}) {
|
|
|
58
60
|
if (persistenceSetup) return;
|
|
59
61
|
persistenceSetup = true;
|
|
60
62
|
store.subscribe((state) => {
|
|
61
|
-
|
|
63
|
+
if (persistDebounceTimer) {
|
|
64
|
+
clearTimeout(persistDebounceTimer);
|
|
65
|
+
}
|
|
66
|
+
persistDebounceTimer = setTimeout(() => {
|
|
67
|
+
persistDebounceTimer = null;
|
|
68
|
+
persistState(state);
|
|
69
|
+
}, PERSIST_DEBOUNCE_MS);
|
|
62
70
|
});
|
|
63
71
|
};
|
|
64
72
|
loadPersistedState();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chromahq/store",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.55",
|
|
4
4
|
"description": "Centralized, persistent store for Chrome extensions using zustand, accessible from service workers and React, with chrome.storage.local persistence.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs.js",
|