@yiin/reactive-proxy-state 1.0.0 → 1.0.2
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/LICENSE +21 -0
- package/README.md +10 -14
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yiin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Reactive Proxy State
|
|
2
2
|
|
|
3
|
-
[](https://badge.fury.io/js/%40yiin%2Freactive-proxy-state) <!-- Replace @yiin/reactive-proxy-state -->
|
|
4
4
|
|
|
5
5
|
A simple, standalone reactivity library inspired by Vue 3's reactivity system, designed for use outside of Vue, particularly in server-side contexts or for data synchronization tasks. It uses JavaScript Proxies to track changes in plain objects, Arrays, Maps, and Sets.
|
|
6
6
|
|
|
@@ -9,9 +9,9 @@ A simple, standalone reactivity library inspired by Vue 3's reactivity system, d
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
bun add yiin/reactive-proxy-state
|
|
13
|
-
# or npm install yiin/reactive-proxy-state
|
|
14
|
-
# or yarn add yiin/reactive-proxy-state
|
|
12
|
+
bun add @yiin/reactive-proxy-state
|
|
13
|
+
# or npm install @yiin/reactive-proxy-state
|
|
14
|
+
# or yarn add @yiin/reactive-proxy-state
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Core Concepts
|
|
@@ -27,7 +27,7 @@ bun add yiin/reactive-proxy-state
|
|
|
27
27
|
Creates a reactive proxy for the given object, Array, Map, or Set. Nested objects/collections are also recursively wrapped.
|
|
28
28
|
|
|
29
29
|
```typescript
|
|
30
|
-
import { wrapState } from 'yiin/reactive-proxy-state';
|
|
30
|
+
import { wrapState } from '@yiin/reactive-proxy-state';
|
|
31
31
|
|
|
32
32
|
const state = wrapState({
|
|
33
33
|
count: 0,
|
|
@@ -52,7 +52,7 @@ Creates a reactive "reference" object for any value type (primitive or object).
|
|
|
52
52
|
**Note:** If a plain object is passed to `ref`, the object *itself* is not made deeply reactive. Only assignment to the `.value` property is tracked. Use `wrapState` for deep object reactivity.
|
|
53
53
|
|
|
54
54
|
```typescript
|
|
55
|
-
import { ref, watchEffect, isRef, unref } from 'yiin/reactive-proxy-state';
|
|
55
|
+
import { ref, watchEffect, isRef, unref } from '@yiin/reactive-proxy-state';
|
|
56
56
|
|
|
57
57
|
// Ref for a primitive
|
|
58
58
|
const count = ref(0);
|
|
@@ -96,7 +96,7 @@ Creates a computed property based on a getter function. The getter tracks reacti
|
|
|
96
96
|
Computed refs are read-only.
|
|
97
97
|
|
|
98
98
|
```typescript
|
|
99
|
-
import { ref, computed, watchEffect, isComputed } from 'yiin/reactive-proxy-state';
|
|
99
|
+
import { ref, computed, watchEffect, isComputed } from '@yiin/reactive-proxy-state';
|
|
100
100
|
|
|
101
101
|
const firstName = ref('John');
|
|
102
102
|
const lastName = ref('Doe');
|
|
@@ -157,7 +157,7 @@ Runs a function immediately, tracks its reactive dependencies, and re-runs it sy
|
|
|
157
157
|
* `onTrigger?(event)`: Debug hook called when the effect is triggered by a mutation.
|
|
158
158
|
|
|
159
159
|
```typescript
|
|
160
|
-
import { wrapState, ref, watchEffect } from 'yiin/reactive-proxy-state';
|
|
160
|
+
import { wrapState, ref, watchEffect } from '@yiin/reactive-proxy-state';
|
|
161
161
|
|
|
162
162
|
// ... existing watchEffect example using wrapState ...
|
|
163
163
|
|
|
@@ -182,7 +182,7 @@ Watches a specific reactive source (either a getter function, a direct reactive
|
|
|
182
182
|
* `deep?: boolean`: If `true`, deeply traverses the source for dependency tracking and uses deep comparison logic. **Defaults to `true`**. Set to `false` for shallow watching (only triggers on direct assignment or identity change).
|
|
183
183
|
|
|
184
184
|
```typescript
|
|
185
|
-
import { wrapState, ref, watch } from 'yiin/reactive-proxy-state';
|
|
185
|
+
import { wrapState, ref, watch } from '@yiin/reactive-proxy-state';
|
|
186
186
|
|
|
187
187
|
// ... existing watch examples using wrapState ...
|
|
188
188
|
|
|
@@ -209,7 +209,7 @@ doubleCount.value = 110; // Output: Double changed from 200 to 220
|
|
|
209
209
|
`wrapState` automatically handles Arrays, Maps, and Sets. Mutations via standard methods (`push`, `pop`, `splice`, `set`, `delete`, `add`, `clear`, etc.) are reactive and will trigger effects that depend on the collection or its contents (if watched deeply).
|
|
210
210
|
|
|
211
211
|
```typescript
|
|
212
|
-
import { wrapState, watchEffect } from 'yiin/reactive-proxy-state';
|
|
212
|
+
import { wrapState, watchEffect } from '@yiin/reactive-proxy-state';
|
|
213
213
|
|
|
214
214
|
const state = wrapState({
|
|
215
215
|
list: [1, 2],
|
|
@@ -227,7 +227,3 @@ state.tags.add('important'); // Output: Tags: important
|
|
|
227
227
|
state.data.delete('foo'); // Output: Data has "foo": false
|
|
228
228
|
state.tags.add('urgent'); // Output: Tags: important, urgent
|
|
229
229
|
```
|
|
230
|
-
|
|
231
|
-
## License
|
|
232
|
-
|
|
233
|
-
<!-- Add your license information here, e.g., MIT -->
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yiin/reactive-proxy-state",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"description": "A simple, standalone reactivity library using Proxies",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -48,4 +48,4 @@
|
|
|
48
48
|
"bun-types": "^1.2.8",
|
|
49
49
|
"typescript": "^5.0.4"
|
|
50
50
|
}
|
|
51
|
-
}
|
|
51
|
+
}
|