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.
Files changed (2) hide show
  1. package/README.md +35 -12
  2. 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
- If you use AI coding agents, this repo also includes agent-oriented guidance:
15
+ ## Smallest Useful Example
16
16
 
17
- - [llms.txt](./llms.txt) provides a compact overview of the API and recommended patterns.
18
- - Companion skills are available via `npx skills add alloc/preact-sigma`.
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
- ## Best Practices
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
- - Let `new SigmaType<TState, TEvents>()` and the builder inputs drive inference. Avoid forcing extra type arguments onto builder methods.
167
- - Keep top-level state properties meaningful. Each top-level property gets its own signal, so shape state around the reads you want to track.
168
- - Use `computed(...)` for argument-free derived state, and use queries for reactive reads that need parameters.
169
- - Put writes in actions. A draft boundary is any point where sigma cannot keep reusing the current draft. `emit()`, `await`, and any action call other than a same-instance sync nested action call are draft boundaries, so call `this.commit()` before those boundaries when pending writes should become public. Setup can use `this.act(function () { ... })` to run one synchronous anonymous action for initialization work or setup-owned callbacks without adding a public action method.
170
- - Use `snapshot(instance)` and `replaceState(instance, snapshot)` for committed-state replay. They work on top-level state keys and stay outside action semantics.
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "preact-sigma",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "keywords": [],
5
5
  "license": "MIT",
6
6
  "author": "Alec Larson",