@semantq/state
Advanced tools
+1
-0
@@ -0,1 +1,2 @@ | ||
| //bind.js | ||
| import { $effect } from './effect.js'; | ||
@@ -2,0 +3,0 @@ |
+1
-0
@@ -0,1 +1,2 @@ | ||
| //effect.js | ||
| import { getCurrentEffect, setCurrentEffect } from './PulseCore.js'; | ||
@@ -2,0 +3,0 @@ |
+27
-6
| // pulse.js | ||
| import { PulseCore } from './PulseCore.js'; | ||
| import { $effect } from './effect.js'; | ||
| export function pulse(initialValue) { | ||
| const signal = new PulseCore(initialValue); | ||
| export function pulse(initialValue, options = {}) { | ||
| const { key, persist = false } = options; | ||
| let startValue = initialValue; | ||
| if (persist && key && typeof localStorage !== 'undefined') { | ||
| const saved = localStorage.getItem(key); | ||
| if (saved !== null) { | ||
| try { | ||
| startValue = JSON.parse(saved); | ||
| } catch (e) { | ||
| console.warn(`Failed to parse stored value for ${key}:`, e); | ||
| } | ||
| } | ||
| } | ||
| const signal = new PulseCore(startValue); | ||
| if (persist && key) { | ||
| // Watch for changes and persist them | ||
| $effect(() => { | ||
| localStorage.setItem(key, JSON.stringify(signal.value)); | ||
| }); | ||
| } | ||
| return new Proxy(signal, { | ||
| get(target, prop) { | ||
| if (prop === 'value') return target.value; | ||
| if (prop === 'set') return (newValue) => { target.value = newValue; }; | ||
| if (prop === 'set') return newValue => { target.value = newValue; }; | ||
| return Reflect.get(target, prop); | ||
@@ -22,3 +45,1 @@ }, | ||
| } | ||
| export const $state = pulse; |
@@ -0,1 +1,3 @@ | ||
| //PulseCore.js | ||
| let currentEffect = null; | ||
@@ -2,0 +4,0 @@ |
+1
-1
| { | ||
| "name": "@semantq/state", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "A reactive state management system for Semantq", | ||
@@ -5,0 +5,0 @@ "main": "./core/index.js", |
13847
5.04%359
6.53%