ustor 0.0.6 → 0.0.8
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.
- package/README.md +30 -26
- package/dist/index.es.js +2 -6
- package/dist/index.js +2 -6
- package/dist/index.min.js +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# UStor
|
|
2
2
|
|
|
3
|
-
[](https://github.com/ustor/actions/workflows/node.js.yml) [](https://www.npmjs.com/package/ustor) [](https://unpkg.com/ustor) [](https://unpkg.com/ustor)
|
|
3
|
+
[](https://github.com/ustor/actions/workflows/node.js.yml) [](https://www.npmjs.com/package/ustor) [](https://unpkg.com/ustor) [](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
|
|
26
|
+
- [Integration with Solid.js, Preact Signals or any](#integration-with-solidjs-preact-signals-or-any)
|
|
27
27
|
|
|
28
28
|
## Installation
|
|
29
29
|
|
|
@@ -34,7 +34,7 @@ npm install ustor
|
|
|
34
34
|
yarn add ustor
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
This library can be integrated `solid-js`, `@preact/signals-core`, `ulive`, `usignal`, `oby`, `sinuous
|
|
37
|
+
This library can be integrated with `solid-js`, `@preact/signals-core`, `ulive`, `usignal`, `oby`, `sinuous` any other libarary you can think of for managing reactive signals.
|
|
38
38
|
|
|
39
39
|
## Setup
|
|
40
40
|
|
|
@@ -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';
|
|
46
45
|
import { createSignal } from "solid-js";
|
|
46
|
+
// import { signal } from '@preact/signals-core'; // 'usignal' 'ulive'
|
|
47
47
|
|
|
48
48
|
// Solid.js setup
|
|
49
49
|
api.signal = createSignal;
|
|
50
|
-
api.get = (v) => v
|
|
51
|
-
api.set = (signal, v) => signal
|
|
52
|
-
api.is = (v) =>
|
|
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 =
|
|
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(
|
|
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
|
|
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
|
-
|
|
182
|
+
effect(() => {
|
|
173
183
|
effectValue = s.a * 2;
|
|
174
184
|
});
|
|
175
185
|
|
|
@@ -178,7 +188,7 @@ s.a = 4;
|
|
|
178
188
|
console.log(effectValue); // 8
|
|
179
189
|
```
|
|
180
190
|
|
|
181
|
-
## Integration with Solid.js, Preact Signals
|
|
191
|
+
## Integration with Solid.js, Preact Signals or any
|
|
182
192
|
|
|
183
193
|
This library can be used with Solid.js, Preact Signals, React, or any other UI framework to provide reactive signals.
|
|
184
194
|
|
|
@@ -208,33 +218,27 @@ api.set = (signal, v) => (signal.value = v);
|
|
|
208
218
|
api.is = (v) => v?.peek;
|
|
209
219
|
```
|
|
210
220
|
|
|
211
|
-
To use
|
|
221
|
+
To use any signal library
|
|
212
222
|
|
|
213
223
|
```javascript
|
|
214
|
-
import
|
|
224
|
+
import ... from "...";
|
|
215
225
|
|
|
216
|
-
api.signal =
|
|
217
|
-
api.get =
|
|
218
|
-
api.set = (signal, value) =>
|
|
219
|
-
api.is = (v) =>
|
|
226
|
+
api.signal = ...;
|
|
227
|
+
api.get = ...;
|
|
228
|
+
api.set = (signal, value) => ...;
|
|
229
|
+
api.is = (v) => ...;
|
|
220
230
|
|
|
221
231
|
const state = store({
|
|
222
|
-
count: 0
|
|
223
|
-
get double() { //useMemo
|
|
224
|
-
return useMemo(() => {
|
|
225
|
-
return this.count * this.count;
|
|
226
|
-
}, [this.count]);
|
|
227
|
-
},
|
|
232
|
+
count: 0
|
|
228
233
|
});
|
|
229
234
|
```
|
|
230
235
|
|
|
231
236
|
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.
|
|
232
237
|
|
|
233
|
-
|
|
234
238
|
### License
|
|
235
239
|
|
|
236
240
|
This library is provided "as-is" under the MIT license. Feel free to use, modify, and distribute it in your projects.
|
|
237
241
|
|
|
238
242
|
### Thanks and Inspiration
|
|
239
243
|
|
|
240
|
-
- **[dy](https://github.com/dy)**
|
|
244
|
+
- **[dy](https://github.com/dy)**
|
package/dist/index.es.js
CHANGED
|
@@ -2,11 +2,7 @@ let api = {},
|
|
|
2
2
|
_s = Symbol("s"),
|
|
3
3
|
is = (v) => v[_s],
|
|
4
4
|
isObject = (v) => v && v.constructor === Object,
|
|
5
|
-
resolve = (v) => Array.isArray(v)
|
|
6
|
-
? store(v)
|
|
7
|
-
: isObject(v)
|
|
8
|
-
? Object.seal(store(v))
|
|
9
|
-
: v,
|
|
5
|
+
resolve = (v) => Array.isArray(v) ? store(v) : isObject(v) ? Object.seal(store(v)) : v,
|
|
10
6
|
store = (values, proto) => {
|
|
11
7
|
if ((is(values) && !proto) || !(api.signal && api.get && api.set && api.is)) return values;
|
|
12
8
|
if (Array.isArray(values)) values.forEach((item, i) => values[i] = is(item) ? item : store(item));
|
|
@@ -15,7 +11,7 @@ let api = {},
|
|
|
15
11
|
Object.entries(Object.getOwnPropertyDescriptors(values)).forEach(
|
|
16
12
|
([key, desc]) => {
|
|
17
13
|
let signal = api.is(desc.value) ? desc.value : api.signal(resolve(desc.value)),
|
|
18
|
-
memo = desc.get ? api.memo ? api.memo(desc.get.bind(state)) : desc.get.bind(state)
|
|
14
|
+
memo = desc.get ? (api.memo ? api.memo(desc.get.bind(state)) : desc.get.bind(state)()) : signal;
|
|
19
15
|
Object.defineProperty(state, key, {
|
|
20
16
|
get: () => desc.get ? memo : api.get(memo),
|
|
21
17
|
set: desc.get ? desc.set?.bind(state) : v => api.set(signal, resolve(v)),
|
package/dist/index.js
CHANGED
|
@@ -4,11 +4,7 @@ let api = {},
|
|
|
4
4
|
_s = Symbol("s"),
|
|
5
5
|
is = (v) => v[_s],
|
|
6
6
|
isObject = (v) => v && v.constructor === Object,
|
|
7
|
-
resolve = (v) => Array.isArray(v)
|
|
8
|
-
? store(v)
|
|
9
|
-
: isObject(v)
|
|
10
|
-
? Object.seal(store(v))
|
|
11
|
-
: v,
|
|
7
|
+
resolve = (v) => Array.isArray(v) ? store(v) : isObject(v) ? Object.seal(store(v)) : v,
|
|
12
8
|
store = (values, proto) => {
|
|
13
9
|
if ((is(values) && !proto) || !(api.signal && api.get && api.set && api.is)) return values;
|
|
14
10
|
if (Array.isArray(values)) values.forEach((item, i) => values[i] = is(item) ? item : store(item));
|
|
@@ -17,7 +13,7 @@ let api = {},
|
|
|
17
13
|
Object.entries(Object.getOwnPropertyDescriptors(values)).forEach(
|
|
18
14
|
([key, desc]) => {
|
|
19
15
|
let signal = api.is(desc.value) ? desc.value : api.signal(resolve(desc.value)),
|
|
20
|
-
memo = desc.get ? api.memo ? api.memo(desc.get.bind(state)) : desc.get.bind(state)
|
|
16
|
+
memo = desc.get ? (api.memo ? api.memo(desc.get.bind(state)) : desc.get.bind(state)()) : signal;
|
|
21
17
|
Object.defineProperty(state, key, {
|
|
22
18
|
get: () => desc.get ? memo : api.get(memo),
|
|
23
19
|
set: desc.get ? desc.set?.bind(state) : v => api.set(signal, resolve(v)),
|
package/dist/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var ustor=function(e){let t={},r=Symbol("s"),s=e=>e[r],i=e=>e&&e.constructor===Object,a=e=>Array.isArray(e)?n(e):i(e)?Object.seal(n(e)):e,n=(e,o)=>{if(s(e)&&!o||!(t.signal&&t.get&&t.set&&t.is))return e;if(Array.isArray(e)&&e.forEach(((t,r)=>e[r]=s(t)?t:n(t))),i(e)){let s=Object.create(o||Object.getPrototypeOf(e));return Object.entries(Object.getOwnPropertyDescriptors(e)).forEach((([e,r])=>{let i=t.is(r.value)?r.value:t.signal(a(r.value)),n=r.get?t.memo?t.memo(r.get.bind(s)):r.get.bind(s)():i;Object.defineProperty(s,e,{get:()=>r.get?n:t.get(n),set:r.get?r.set?.bind(s):e=>t.set(i,a(e)),enumerable:!0})})),Object.defineProperty(s,r,{value:!0}),s}return e};return e.api=t,e.is=s,e.store=n,e}({});
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ustor={})}(this,(function(e){let t={},r=Symbol("s"),o=e=>e[r],i=e=>e&&e.constructor===Object,n=e=>Array.isArray(e)?s(e):i(e)?Object.seal(s(e)):e,s=(e,f)=>{if(o(e)&&!f||!(t.signal&&t.get&&t.set&&t.is))return e;if(Array.isArray(e)&&e.forEach(((t,r)=>e[r]=o(t)?t:s(t))),i(e)){let o=Object.create(f||Object.getPrototypeOf(e));return Object.entries(Object.getOwnPropertyDescriptors(e)).forEach((([e,r])=>{let i=t.is(r.value)?r.value:t.signal(n(r.value)),s=r.get?t.memo?t.memo(r.get.bind(o)):r.get.bind(o)():i;Object.defineProperty(o,e,{get:()=>r.get?s:t.get(s),set:r.get?r.set?.bind(o):e=>t.set(i,n(e)),enumerable:!0})})),Object.defineProperty(o,r,{value:!0}),o}return e};e.api=t,e.is=o,e.store=s}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ustor",
|
|
3
|
-
"description": "A lightweight reactive store library that provides a powerful reactivity system for managing state, compatible with any UI framework, including
|
|
4
|
-
"version": "0.0.
|
|
3
|
+
"description": "A lightweight reactive store library that provides a powerful reactivity system for managing state, compatible with any UI framework, including Solid.js, and Preact Signals.",
|
|
4
|
+
"version": "0.0.8",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.js",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -29,8 +29,12 @@
|
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@preact/signals-core": "^1.8.0",
|
|
31
31
|
"@rollup/plugin-terser": "^0.4.4",
|
|
32
|
+
"oby": "^15.1.2",
|
|
33
|
+
"reactively": "^0.0.1",
|
|
32
34
|
"rollup": "^4.24.0",
|
|
33
35
|
"rollup-plugin-bundle-size": "^1.0.3",
|
|
36
|
+
"s-js": "^0.4.9",
|
|
37
|
+
"sinuous": "^0.32.1",
|
|
34
38
|
"solid-js": "^1.9.2",
|
|
35
39
|
"ulive": "^1.0.7",
|
|
36
40
|
"vitest": "^2.1.3"
|
|
@@ -43,8 +47,6 @@
|
|
|
43
47
|
"createmutable",
|
|
44
48
|
"mutable",
|
|
45
49
|
"createstore",
|
|
46
|
-
"react",
|
|
47
|
-
"preact",
|
|
48
50
|
"solid.js",
|
|
49
51
|
"state",
|
|
50
52
|
"observable",
|