This commit is contained in:
2026-03-22 00:44:55 +01:00
parent 443315aae4
commit 7c400ad227
113 changed files with 31773 additions and 998 deletions

31
plugins/storage.js Normal file
View File

@@ -0,0 +1,31 @@
/**
* SigPro Storage Plugin
* Automatically synchronizes signals with localStorage.
*/
export const Storage = ($) => {
/**
* Persists a signal's value in localStorage.
* @param {Function} $sig - The signal to persist.
* @param {string} key - The localStorage key name.
* @returns {Function} The same signal for chaining.
*/
_storage = ($sig, key) => {
// 1. Initial Load: If there's data in storage, update the signal immediately
const saved = localStorage.getItem(key);
if (saved !== null) {
try {
$sig(JSON.parse(saved));
} catch (e) {
console.error(`[SigPro Storage] Error parsing key "${key}":`, e);
}
}
// 2. Auto-Save: Every time the signal changes, update localStorage
$(() => {
const val = $sig();
localStorage.setItem(key, JSON.stringify(val));
});
return $sig;
};
};