@quark-fw/atom 0.0.1 → 0.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.
Files changed (2) hide show
  1. package/README.md +35 -0
  2. package/package.json +7 -3
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # @quark-fw/atom
2
+
3
+ Tiny reactive primitive used across the Quark framework: a keyed value with subscriptions.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm i @quark-fw/atom
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import atom from "@quark-fw/atom";
15
+
16
+ const count = atom("count", 0);
17
+
18
+ const unsubscribe = count.subscribe((v) => console.log("count is now", v));
19
+ count.value = 1; // -> "count is now 1"
20
+ unsubscribe();
21
+ ```
22
+
23
+ An atom can declare dependencies (other atoms it derives from) via the third argument — subscribers are re-notified when a dependency changes:
24
+
25
+ ```ts
26
+ const doubled = atom("doubled", 0, [count]);
27
+ ```
28
+
29
+ ## API
30
+
31
+ - `atom<T>(key, initial, deps?)` → `Atom<T>`
32
+ - `Atom<T>`: `key`, `deps`, `value` (get/set), `subscribe(fn)` → unsubscribe
33
+ - `AtomDependency`: `{ key, subscribe }` — the minimal shape a dependency needs
34
+
35
+ Part of the [Quark framework](https://www.npmjs.com/package/@quark-fw/core). Zero dependencies.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quark-fw/atom",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Reactive atom primitive for the Quark framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -14,12 +14,16 @@
14
14
  "./src/*": "./dist/*",
15
15
  "./*": "./dist/*"
16
16
  },
17
- "files": ["dist"],
17
+ "files": [
18
+ "dist"
19
+ ],
18
20
  "scripts": {
19
21
  "dev": "tsx watch src/index.ts",
20
22
  "build": "tsc -p tsconfig.build.json && node ../../scripts/postbuild.mjs"
21
23
  },
22
- "keywords": ["quark"],
24
+ "keywords": [
25
+ "quark"
26
+ ],
23
27
  "author": "",
24
28
  "license": "ISC",
25
29
  "publishConfig": {