@tinyfx/runtime 0.1.8 → 0.1.9

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 (46) hide show
  1. package/dist/__tests__/mount-state.test.d.ts +1 -0
  2. package/dist/__tests__/mount-state.test.js +30 -0
  3. package/dist/__tests__/page-registry.test.d.ts +1 -0
  4. package/dist/__tests__/page-registry.test.js +38 -0
  5. package/dist/__tests__/path-matcher.test.d.ts +1 -0
  6. package/dist/__tests__/path-matcher.test.js +43 -0
  7. package/dist/__tests__/registry.test.d.ts +1 -0
  8. package/dist/__tests__/registry.test.js +67 -0
  9. package/dist/context.d.ts +15 -0
  10. package/dist/context.js +0 -2
  11. package/dist/dom.d.ts +35 -0
  12. package/dist/dom.js +35 -0
  13. package/dist/each.d.ts +10 -0
  14. package/dist/each.js +24 -0
  15. package/dist/http/data.d.ts +76 -0
  16. package/dist/http/data.js +36 -0
  17. package/dist/http/helper.d.ts +20 -0
  18. package/dist/http/helper.js +20 -0
  19. package/dist/http/http.d.ts +13 -0
  20. package/dist/http/http.js +13 -0
  21. package/dist/index.d.ts +8 -0
  22. package/dist/index.js +8 -0
  23. package/dist/init.d.ts +12 -0
  24. package/dist/init.js +40 -0
  25. package/dist/mount-state.d.ts +17 -0
  26. package/dist/mount-state.js +27 -0
  27. package/dist/page-registry.d.ts +31 -0
  28. package/dist/page-registry.js +38 -0
  29. package/dist/registry.d.ts +31 -0
  30. package/dist/registry.js +49 -0
  31. package/dist/router/active-links.d.ts +3 -0
  32. package/dist/router/active-links.js +3 -0
  33. package/dist/router/index.d.ts +1 -0
  34. package/dist/router/index.js +1 -0
  35. package/dist/router/lifecycle.d.ts +26 -0
  36. package/dist/router/lifecycle.js +26 -0
  37. package/dist/router/navigate.d.ts +8 -0
  38. package/dist/router/navigate.js +8 -0
  39. package/dist/router/params.d.ts +19 -0
  40. package/dist/router/params.js +19 -0
  41. package/dist/router/path-matcher.d.ts +30 -0
  42. package/dist/router/path-matcher.js +45 -0
  43. package/dist/router/types.d.ts +15 -2
  44. package/dist/signals.d.ts +41 -0
  45. package/dist/signals.js +41 -0
  46. package/package.json +6 -2
package/dist/signals.js CHANGED
@@ -1,6 +1,19 @@
1
1
  // @tinyfx/runtime — signals
2
2
  // Minimal, explicit reactivity — no proxies, no magic.
3
3
  const effectStack = [];
4
+ /**
5
+ * Reactive value container used by TinyFX signals.
6
+ *
7
+ * Reading the value through {@link Signal.get} during an active effect records
8
+ * that effect as a subscriber. Writing through {@link Signal.set} re-runs the
9
+ * affected subscribers.
10
+ *
11
+ * @example
12
+ * const count = new Signal(0);
13
+ * console.log(count.get());
14
+ * count.set(1);
15
+ * console.log(count.get());
16
+ */
4
17
  export class Signal {
5
18
  constructor(v) {
6
19
  this.subs = new Set();
@@ -20,12 +33,40 @@ export class Signal {
20
33
  this.subs.forEach((fn) => fn());
21
34
  }
22
35
  }
36
+ /**
37
+ * Creates a reactive signal function.
38
+ *
39
+ * @param v - The initial value stored by the signal
40
+ * @returns A callable signal that reads the current value and exposes `.set()`
41
+ * to update it
42
+ *
43
+ * @example
44
+ * const count = signal(0);
45
+ * console.log(count());
46
+ * count.set(1);
47
+ */
23
48
  export function signal(v) {
24
49
  const s = new Signal(v);
25
50
  const fn = () => s.get();
26
51
  fn.set = (v) => s.set(v);
27
52
  return fn;
28
53
  }
54
+ /**
55
+ * Registers and runs a reactive effect.
56
+ *
57
+ * Every signal read while `fn` runs is tracked, and the effect is re-run when
58
+ * any of those signal values change.
59
+ *
60
+ * @param fn - The reactive callback to execute and subscribe
61
+ * @returns Nothing
62
+ *
63
+ * @example
64
+ * const count = signal(0);
65
+ * effect(() => {
66
+ * console.log(`count = ${count()}`);
67
+ * });
68
+ * count.set(1);
69
+ */
29
70
  export function effect(fn) {
30
71
  const run = () => {
31
72
  effectStack.push(run);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinyfx/runtime",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Minimal frontend runtime — signals, DOM helpers, typed HTTP, DTO mapping",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -17,10 +17,14 @@
17
17
  ],
18
18
  "scripts": {
19
19
  "build": "tsc",
20
+ "test": "vitest run",
20
21
  "prepublishOnly": "npm run build"
21
22
  },
22
23
  "devDependencies": {
23
- "typescript": "^5.9.3"
24
+ "@vitest/coverage-v8": "^4.1.2",
25
+ "jsdom": "^29.0.1",
26
+ "typescript": "^5.9.3",
27
+ "vitest": "^4.1.2"
24
28
  },
25
29
  "license": "MIT"
26
30
  }