Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo-mod-jslibs-dist.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'alpinejs/packages/persist/dist/dist/module.esm.js')
-rw-r--r--alpinejs/packages/persist/dist/dist/module.esm.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/alpinejs/packages/persist/dist/dist/module.esm.js b/alpinejs/packages/persist/dist/dist/module.esm.js
new file mode 100644
index 0000000..dbdd3b8
--- /dev/null
+++ b/alpinejs/packages/persist/dist/dist/module.esm.js
@@ -0,0 +1,41 @@
+// packages/persist/src/index.js
+function src_default(Alpine) {
+ Alpine.magic("persist", (el, {interceptor}) => {
+ let alias;
+ let storage = localStorage;
+ return interceptor((initialValue, getter, setter, path, key) => {
+ let lookup = alias || `_x_${path}`;
+ let initial = storageHas(lookup, storage) ? storageGet(lookup, storage) : initialValue;
+ setter(initial);
+ Alpine.effect(() => {
+ let value = getter();
+ storageSet(lookup, value, storage);
+ setter(value);
+ });
+ return initial;
+ }, (func) => {
+ func.as = (key) => {
+ alias = key;
+ return func;
+ }, func.using = (target) => {
+ storage = target;
+ return func;
+ };
+ });
+ });
+}
+function storageHas(key, storage) {
+ return storage.getItem(key) !== null;
+}
+function storageGet(key, storage) {
+ return JSON.parse(storage.getItem(key, storage));
+}
+function storageSet(key, value, storage) {
+ storage.setItem(key, JSON.stringify(value));
+}
+
+// packages/persist/builds/module.js
+var module_default = src_default;
+export {
+ module_default as default
+};