🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@semantq/state

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@semantq/state - npm Package Compare versions

Comparing version
1.0.0
to
1.0.1
+1
-0
core/bind.js

@@ -0,1 +1,2 @@

//bind.js
import { $effect } from './effect.js';

@@ -2,0 +3,0 @@

@@ -0,1 +1,2 @@

//effect.js
import { getCurrentEffect, setCurrentEffect } from './PulseCore.js';

@@ -2,0 +3,0 @@

// 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",