@esportsplus/reactivity 0.29.6 → 0.29.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/package.json +1 -1
  2. package/readme.md +76 -4
package/package.json CHANGED
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "type": "module",
33
33
  "types": "build/index.d.ts",
34
- "version": "0.29.6",
34
+ "version": "0.29.7",
35
35
  "scripts": {
36
36
  "build": "tsc",
37
37
  "build:test": "pnpm build && vite build --config test/vite.config.ts",
package/readme.md CHANGED
@@ -60,6 +60,8 @@ console.log(user.canVote); // false
60
60
  user.dispose();
61
61
  ```
62
62
 
63
+ > **Note:** `dispose` is a reserved key and cannot be used as a property name in reactive objects.
64
+
63
65
  ### Reactive Arrays
64
66
 
65
67
  ```typescript
@@ -79,6 +81,32 @@ console.log(state.total); // 15
79
81
  state.items.on('push', ({ items }) => {
80
82
  console.log('Added:', items);
81
83
  });
84
+
85
+ // Cleanup resources
86
+ state.items.dispose();
87
+ ```
88
+
89
+ ### Async Computeds
90
+
91
+ Computed properties that return Promises are automatically unwrapped:
92
+
93
+ ```typescript
94
+ import { reactive } from '@esportsplus/reactivity';
95
+
96
+ let state = reactive({
97
+ userId: 1,
98
+ user: async () => {
99
+ let response = await fetch(`/api/users/${state.userId}`);
100
+ return response.json();
101
+ }
102
+ });
103
+
104
+ // Initially undefined while loading
105
+ console.log(state.user); // undefined
106
+
107
+ // After promise resolves, value is available
108
+ // Changing userId triggers a new fetch
109
+ state.userId = 2;
82
110
  ```
83
111
 
84
112
  ### Effects
@@ -189,8 +217,8 @@ let user = new ReactiveObject_1();
189
217
 
190
218
  | Function | Description |
191
219
  |----------|-------------|
192
- | `reactive(value)` | Creates a signal from a primitive value |
193
- | `reactive(() => expr)` | Creates a computed value |
220
+ | `reactive(value)` | Creates a signal from a primitive value (compile-time only) |
221
+ | `reactive(() => expr)` | Creates a computed value (compile-time only) |
194
222
  | `reactive({...})` | Creates a reactive object with signals and computeds |
195
223
  | `reactive([...])` | Creates a reactive array |
196
224
  | `effect(fn)` | Runs a function that re-executes when dependencies change |
@@ -215,8 +243,52 @@ These are typically only used by the transformer output:
215
243
  |----------|-------------|
216
244
  | `isSignal(value)` | Checks if value is a Signal |
217
245
  | `isComputed(value)` | Checks if value is a Computed |
246
+ | `isPromise(value)` | Checks if value is a Promise |
247
+
248
+ ### Classes
249
+
250
+ For advanced use cases, the underlying classes are exported:
251
+
252
+ | Class | Description |
253
+ |-------|-------------|
254
+ | `ReactiveArray<T>` | Array subclass with reactivity and event dispatching |
255
+ | `ReactiveObject<T>` | Base class for reactive objects |
256
+
257
+ ### Constants
258
+
259
+ Symbol constants for type identification:
260
+
261
+ | Constant | Description |
262
+ |----------|-------------|
263
+ | `SIGNAL` | Symbol identifying Signal nodes |
264
+ | `COMPUTED` | Symbol identifying Computed nodes |
265
+ | `REACTIVE_ARRAY` | Symbol identifying ReactiveArray instances |
266
+ | `REACTIVE_OBJECT` | Symbol identifying ReactiveObject instances |
267
+
268
+ ### Types
269
+
270
+ | Type | Description |
271
+ |------|-------------|
272
+ | `Signal<T>` | Signal node type |
273
+ | `Computed<T>` | Computed node type |
274
+ | `Reactive<T>` | Utility type for inferring reactive object/array types |
275
+
276
+ ## ReactiveArray
277
+
278
+ ### Methods
279
+
280
+ | Method | Description |
281
+ |--------|-------------|
282
+ | `$length()` | Returns the reactive length (tracks reads) |
283
+ | `$set(index, value)` | Sets an item at index reactively |
284
+ | `clear()` | Removes all items and disposes nested reactive objects |
285
+ | `dispose()` | Disposes all nested reactive objects |
286
+ | `on(event, listener)` | Subscribes to an array event |
287
+ | `once(event, listener)` | Subscribes to an event once |
288
+
289
+ All standard array methods (`push`, `pop`, `shift`, `unshift`, `splice`, `sort`, `reverse`, `concat`) are supported and trigger corresponding events.
218
290
 
219
- ## ReactiveArray Events
291
+ ### Events
220
292
 
221
293
  | Event | Payload | Description |
222
294
  |-------|---------|-------------|
@@ -227,7 +299,7 @@ These are typically only used by the transformer output:
227
299
  | `reverse` | `undefined` | Array was reversed |
228
300
  | `set` | `{ index, item }` | Item was set at index |
229
301
  | `shift` | `{ item: T }` | Item was shifted |
230
- | `sort` | `{ order: number[] }` | Array was sorted |
302
+ | `sort` | `{ order: number[] }` | Array was sorted (order maps new→old indices) |
231
303
  | `splice` | `{ start, deleteCount, items }` | Array was spliced |
232
304
  | `unshift` | `{ items: T[] }` | Items were unshifted |
233
305