ustor 0.0.5 → 0.0.7

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.
Files changed (2) hide show
  1. package/README.md +37 -12
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # UStor
2
2
 
3
- [![tests](https://github.com/ustor/actions/workflows/node.js.yml/badge.svg)](https://github.com/ustor/actions/workflows/node.js.yml) [![Version](https://img.shields.io/npm/v/ustor.svg?color=success&style=flat-square)](https://www.npmjs.com/package/ustor) [![Badge size](https://deno.bundlejs.com/badge?q=ustor&treeshake=[*]&config={"compression":"brotli"})](https://unpkg.com/ustor) [![Badge size](https://deno.bundlejs.com/badge?q=ustor&treeshake=[*]&config={"compression":"gzip"})](https://unpkg.com/ustor)
3
+ [![tests](https://github.com/kethan/ustor/actions/workflows/node.js.yml/badge.svg)](https://github.com/ustor/actions/workflows/node.js.yml) [![Version](https://img.shields.io/npm/v/ustor.svg?color=success&style=flat-square)](https://www.npmjs.com/package/ustor) [![Badge size](https://deno.bundlejs.com/badge?q=ustor&treeshake=[*]&config={"compression":"brotli"})](https://unpkg.com/ustor) [![Badge size](https://deno.bundlejs.com/badge?q=ustor&treeshake=[*]&config={"compression":"gzip"})](https://unpkg.com/ustor)
4
4
 
5
5
  # Reactive Store Library
6
6
 
@@ -23,7 +23,7 @@ This library provides a powerful reactivity system for creating stateful objects
23
23
  - [Deeply Nested Structures](#deeply-nested-structures)
24
24
  - [Arrays and Objects](#arrays-and-objects)
25
25
  - [Reactivity and Effects](#reactivity-and-effects)
26
- - [Integration with Solid.js, Preact Signals, and React](#integration-with-solidjs-preact-signals-and-react)
26
+ - [Integration with Solid.js, Preact Signals, and React or anything](#integration-with-solidjs-preact-signals-and-react)
27
27
 
28
28
  ## Installation
29
29
 
@@ -42,14 +42,24 @@ First, import the `store` function and the `api` object. You need to initialize
42
42
 
43
43
  ```javascript
44
44
  import { store, api } from "./src";
45
- // import { signal } from '@preact/signals-core';
45
+ // import { signal } from '@preact/signals-core'; // 'usignal' 'ulive'
46
46
  import { createSignal } from "solid-js";
47
47
 
48
48
  // Solid.js setup
49
49
  api.signal = createSignal;
50
- api.get = (v) => v?.[0]();
51
- api.set = (signal, v) => signal?.[1](v);
52
- api.is = (v) => v?.[0]?.name?.includes("readSignal");
50
+ api.get = (v) => v[0]();
51
+ api.set = (signal, v) => signal[1](v);
52
+ api.is = (v) =>
53
+ (Array.isArray(v) &&
54
+ typeof v[0] === "function" &&
55
+ typeof v[1] === "function") ||
56
+ v[0]?.name?.includes("readSignal");
57
+
58
+ // @preact/signals-core, usignal or ulive setup
59
+ api.signal = signal;
60
+ api.get = (v) => v.value;
61
+ api.set = (signal, v) => (signal.value = v);
62
+ api.is = (v) => v?.peek;
53
63
  ```
54
64
 
55
65
  ## API
@@ -141,11 +151,11 @@ The `store` function can also handle deeply nested objects, converting nested pr
141
151
 
142
152
  ```javascript
143
153
  const s = store({ nested: { deep: { value: 10 } } });
144
- const deepValue = api.get(s.nested.deep.value) * 2;
154
+ const deepValue = s.nested.deep.value * 2;
145
155
 
146
156
  console.log(deepValue); // 20
147
157
  s.nested.deep.value = 15;
148
- console.log(api.get(s.nested.deep.value) * 2); // 30
158
+ console.log(s.nested.deep.value) * 2; // 30
149
159
  ```
150
160
 
151
161
  ### Arrays and Objects
@@ -163,13 +173,13 @@ console.log(s.list.reduce((acc, item) => acc + item, 0)); // 9
163
173
 
164
174
  ### Reactivity and Effects
165
175
 
166
- The library integrates with effects to track dependencies and automatically re-run whenever dependencies change:
176
+ The signal value trigger with effects to track dependencies and automatically re-run whenever dependencies change:
167
177
 
168
178
  ```javascript
169
179
  const s = store({ a: 1 });
170
180
  let effectValue = 0;
171
181
 
172
- api.effect(() => {
182
+ effect(() => {
173
183
  effectValue = s.a * 2;
174
184
  });
175
185
 
@@ -220,7 +230,8 @@ api.is = (v) => Array.isArray(v) && typeof v[1] === "function";
220
230
 
221
231
  const state = store({
222
232
  count: 0,
223
- get double() { //useMemo
233
+ get double() {
234
+ //useMemo
224
235
  return useMemo(() => {
225
236
  return this.count * this.count;
226
237
  }, [this.count]);
@@ -228,8 +239,22 @@ const state = store({
228
239
  });
229
240
  ```
230
241
 
231
- The library provides a unified API to work with different reactive systems, allowing you to switch between Solid.js, Preact Signals, React, or any other UI framework easily.
242
+ To use any signal library
243
+
244
+ ```javascript
245
+ import ... from "...";
232
246
 
247
+ api.signal = ...;
248
+ api.get = ...;
249
+ api.set = (signal, value) => ...;
250
+ api.is = (v) => ...;
251
+
252
+ const state = store({
253
+ count: 0
254
+ });
255
+ ```
256
+
257
+ The library provides a unified API to work with different reactive systems, allowing you to switch between Solid.js, Preact Signals, React, or any other UI framework easily.
233
258
 
234
259
  ### License
235
260
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ustor",
3
3
  "description": "A lightweight reactive store library that provides a powerful reactivity system for managing state, compatible with any UI framework, including React, Solid.js, and Preact Signals.",
4
- "version": "0.0.5",
4
+ "version": "0.0.7",
5
5
  "type": "module",
6
6
  "source": "./src/index.js",
7
7
  "main": "./dist/index.js",