preact-sigma 2.2.0 → 2.2.1
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 +35 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,10 +12,33 @@ To add `preact-sigma` to your project:
|
|
|
12
12
|
npm install preact-sigma
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
## Smallest Useful Example
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
```ts
|
|
18
|
+
import { SigmaType } from "preact-sigma";
|
|
19
|
+
|
|
20
|
+
const Counter = new SigmaType<{ count: number }>("Counter")
|
|
21
|
+
.defaultState({
|
|
22
|
+
count: 0,
|
|
23
|
+
})
|
|
24
|
+
.computed({
|
|
25
|
+
doubled() {
|
|
26
|
+
return this.count * 2;
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
.actions({
|
|
30
|
+
increment() {
|
|
31
|
+
this.count += 1;
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const counter = new Counter();
|
|
36
|
+
|
|
37
|
+
counter.increment();
|
|
38
|
+
|
|
39
|
+
console.log(counter.count); // 1
|
|
40
|
+
console.log(counter.doubled); // 2
|
|
41
|
+
```
|
|
19
42
|
|
|
20
43
|
## What It Is
|
|
21
44
|
|
|
@@ -161,13 +184,13 @@ Cleanup resources can be returned as functions, `AbortController`, objects with
|
|
|
161
184
|
|
|
162
185
|
Inside setup, `this` exposes the public instance plus `emit(...)` and `act(fn)`. Use `this.act(function () { ... })` when setup needs one synchronous anonymous action with normal draft, `commit()`, and `emit(...)` semantics, whether that work happens immediately in the setup body or later from a setup-owned callback, but should not become a public action method.
|
|
163
186
|
|
|
164
|
-
##
|
|
187
|
+
## Constructor and Defaults
|
|
188
|
+
|
|
189
|
+
- `defaultState` values may be plain values or zero-argument initializer functions. Use initializer functions when each instance needs a fresh object, array, or class instance.
|
|
190
|
+
- Constructor input shallowly overrides `defaultState`, so `new TodoList({ draft: "ready" })` replaces only the top-level keys you pass.
|
|
165
191
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
-
|
|
169
|
-
-
|
|
170
|
-
-
|
|
171
|
-
- Use `SigmaRef<T>` when a value should stay by reference in sigma's `Draft` and `Immutable` types. A normal assignment to a `SigmaRef<T>`-typed value only changes typing and does not change Immer's runtime drafting or freezing behavior.
|
|
172
|
-
- Use `immerable` on custom classes only when they should participate in Immer drafting. `setAutoFreeze(false)` disables sigma's runtime deep-freezing when you need published state to stay unfrozen.
|
|
173
|
-
- Use `setup(...)` for owned side effects, and always return cleanup resources for anything the instance starts.
|
|
192
|
+
## More Docs
|
|
193
|
+
|
|
194
|
+
- [llms.txt](./llms.txt) provides the exhaustive machine-oriented API guide and terminology.
|
|
195
|
+
- Companion skills are available via `npx skills add alloc/preact-sigma`.
|
|
196
|
+
- The `preact-sigma` skill packages the procedural guidance and agent-oriented workflow for this library.
|