@assistant-ui/tap 0.0.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 (82) hide show
  1. package/README.md +252 -0
  2. package/dist/__tests__/test-utils.d.ts +79 -0
  3. package/dist/__tests__/test-utils.d.ts.map +1 -0
  4. package/dist/__tests__/test-utils.js +216 -0
  5. package/dist/__tests__/test-utils.js.map +1 -0
  6. package/dist/core/ResourceFiber.d.ts +6 -0
  7. package/dist/core/ResourceFiber.d.ts.map +1 -0
  8. package/dist/core/ResourceFiber.js +41 -0
  9. package/dist/core/ResourceFiber.js.map +1 -0
  10. package/dist/core/ResourceHandle.d.ts +8 -0
  11. package/dist/core/ResourceHandle.d.ts.map +1 -0
  12. package/dist/core/ResourceHandle.js +64 -0
  13. package/dist/core/ResourceHandle.js.map +1 -0
  14. package/dist/core/commit.d.ts +4 -0
  15. package/dist/core/commit.d.ts.map +1 -0
  16. package/dist/core/commit.js +60 -0
  17. package/dist/core/commit.js.map +1 -0
  18. package/dist/core/execution-context.d.ts +4 -0
  19. package/dist/core/execution-context.d.ts.map +1 -0
  20. package/dist/core/execution-context.js +33 -0
  21. package/dist/core/execution-context.js.map +1 -0
  22. package/dist/core/resource.d.ts +3 -0
  23. package/dist/core/resource.d.ts.map +1 -0
  24. package/dist/core/resource.js +14 -0
  25. package/dist/core/resource.js.map +1 -0
  26. package/dist/core/scheduler.d.ts +14 -0
  27. package/dist/core/scheduler.d.ts.map +1 -0
  28. package/dist/core/scheduler.js +66 -0
  29. package/dist/core/scheduler.js.map +1 -0
  30. package/dist/core/types.d.ts +44 -0
  31. package/dist/core/types.d.ts.map +1 -0
  32. package/dist/core/types.js +1 -0
  33. package/dist/core/types.js.map +1 -0
  34. package/dist/hooks/depsShallowEqual.d.ts +2 -0
  35. package/dist/hooks/depsShallowEqual.d.ts.map +1 -0
  36. package/dist/hooks/depsShallowEqual.js +12 -0
  37. package/dist/hooks/depsShallowEqual.js.map +1 -0
  38. package/dist/hooks/tap-callback.d.ts +2 -0
  39. package/dist/hooks/tap-callback.d.ts.map +1 -0
  40. package/dist/hooks/tap-callback.js +9 -0
  41. package/dist/hooks/tap-callback.js.map +1 -0
  42. package/dist/hooks/tap-effect.d.ts +4 -0
  43. package/dist/hooks/tap-effect.d.ts.map +1 -0
  44. package/dist/hooks/tap-effect.js +32 -0
  45. package/dist/hooks/tap-effect.js.map +1 -0
  46. package/dist/hooks/tap-memo.d.ts +2 -0
  47. package/dist/hooks/tap-memo.d.ts.map +1 -0
  48. package/dist/hooks/tap-memo.js +18 -0
  49. package/dist/hooks/tap-memo.js.map +1 -0
  50. package/dist/hooks/tap-ref.d.ts +7 -0
  51. package/dist/hooks/tap-ref.d.ts.map +1 -0
  52. package/dist/hooks/tap-ref.js +12 -0
  53. package/dist/hooks/tap-ref.js.map +1 -0
  54. package/dist/hooks/tap-rerender.d.ts +2 -0
  55. package/dist/hooks/tap-rerender.d.ts.map +1 -0
  56. package/dist/hooks/tap-rerender.js +10 -0
  57. package/dist/hooks/tap-rerender.js.map +1 -0
  58. package/dist/hooks/tap-resource.d.ts +4 -0
  59. package/dist/hooks/tap-resource.d.ts.map +1 -0
  60. package/dist/hooks/tap-resource.js +33 -0
  61. package/dist/hooks/tap-resource.js.map +1 -0
  62. package/dist/hooks/tap-resources.d.ts +5 -0
  63. package/dist/hooks/tap-resources.d.ts.map +1 -0
  64. package/dist/hooks/tap-resources.js +84 -0
  65. package/dist/hooks/tap-resources.js.map +1 -0
  66. package/dist/hooks/tap-state.d.ts +7 -0
  67. package/dist/hooks/tap-state.d.ts.map +1 -0
  68. package/dist/hooks/tap-state.js +43 -0
  69. package/dist/hooks/tap-state.js.map +1 -0
  70. package/dist/index.d.ts +10 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +20 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/react/index.d.ts +2 -0
  75. package/dist/react/index.d.ts.map +1 -0
  76. package/dist/react/index.js +6 -0
  77. package/dist/react/index.js.map +1 -0
  78. package/dist/react/use-resource.d.ts +3 -0
  79. package/dist/react/use-resource.d.ts.map +1 -0
  80. package/dist/react/use-resource.js +30 -0
  81. package/dist/react/use-resource.js.map +1 -0
  82. package/package.json +46 -0
@@ -0,0 +1,64 @@
1
+ // src/core/ResourceHandle.ts
2
+ import {
3
+ createResourceFiber,
4
+ unmountResource,
5
+ renderResource,
6
+ commitResource
7
+ } from "./ResourceFiber.js";
8
+ import { UpdateScheduler } from "./scheduler.js";
9
+ import { tapResource } from "../hooks/tap-resource.js";
10
+ import { tapRef } from "../hooks/tap-ref.js";
11
+ import { tapEffect } from "../hooks/tap-effect.js";
12
+ import { tapState } from "../hooks/tap-state.js";
13
+ import { tapMemo } from "../hooks/tap-memo.js";
14
+ var HandleWrapperResource = ({
15
+ element,
16
+ onDispose
17
+ }) => {
18
+ const [props, setProps] = tapState(element.props);
19
+ const value = tapResource({ type: element.type, props });
20
+ const subscribers = tapRef(/* @__PURE__ */ new Set()).current;
21
+ const valueRef = tapRef(value);
22
+ tapEffect(() => {
23
+ if (value !== valueRef.current) {
24
+ valueRef.current = value;
25
+ subscribers.forEach((callback) => callback());
26
+ }
27
+ }, [value]);
28
+ const handle = tapMemo(
29
+ () => ({
30
+ getState: () => valueRef.current,
31
+ subscribe: (callback) => {
32
+ subscribers.add(callback);
33
+ return () => subscribers.delete(callback);
34
+ },
35
+ updateInput: (props2) => {
36
+ setProps(() => props2);
37
+ },
38
+ dispose: onDispose
39
+ }),
40
+ []
41
+ );
42
+ return handle;
43
+ };
44
+ var createResource = (element) => {
45
+ const props = {
46
+ element,
47
+ onDispose: () => unmountResource(fiber)
48
+ };
49
+ const scheduler = new UpdateScheduler(() => {
50
+ const result2 = renderResource(fiber, props);
51
+ commitResource(fiber, result2);
52
+ });
53
+ const fiber = createResourceFiber(
54
+ HandleWrapperResource,
55
+ () => scheduler.markDirty()
56
+ );
57
+ const result = renderResource(fiber, props);
58
+ commitResource(fiber, result);
59
+ return result.state;
60
+ };
61
+ export {
62
+ createResource
63
+ };
64
+ //# sourceMappingURL=ResourceHandle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/ResourceHandle.ts"],"sourcesContent":["import { ResourceElement, Unsubscribe } from \"./types\";\nimport {\n createResourceFiber,\n unmountResource,\n renderResource,\n commitResource,\n} from \"./ResourceFiber\";\nimport { UpdateScheduler } from \"./scheduler\";\nimport { tapResource } from \"../hooks/tap-resource\";\nimport { tapRef } from \"../hooks/tap-ref\";\nimport { tapEffect } from \"../hooks/tap-effect\";\nimport { tapState } from \"../hooks/tap-state\";\nimport { tapMemo } from \"../hooks/tap-memo\";\n\nexport interface ResourceHandle<R, P> {\n getState(): R;\n subscribe(callback: () => void): Unsubscribe;\n updateInput(props: P): void;\n}\n\nconst HandleWrapperResource = <R, P>({\n element,\n onDispose,\n}: {\n element: ResourceElement<R, P>;\n onDispose: () => void;\n}): ResourceHandle<R, P> => {\n const [props, setProps] = tapState(element.props);\n const value = tapResource({ type: element.type, props });\n const subscribers = tapRef(new Set<() => void>()).current;\n const valueRef = tapRef(value);\n\n tapEffect(() => {\n if (value !== valueRef.current) {\n valueRef.current = value;\n subscribers.forEach((callback) => callback());\n }\n }, [value]);\n\n const handle = tapMemo(\n () => ({\n getState: () => valueRef.current,\n subscribe: (callback: () => void) => {\n subscribers.add(callback);\n return () => subscribers.delete(callback);\n },\n updateInput: (props: P) => {\n setProps(() => props);\n },\n dispose: onDispose,\n }),\n []\n );\n\n return handle;\n};\n\nexport const createResource = <R, P>(\n element: ResourceElement<R, P>\n): ResourceHandle<R, P> => {\n const props = {\n element,\n onDispose: () => unmountResource(fiber),\n };\n\n const scheduler = new UpdateScheduler(() => {\n const result = renderResource(fiber, props);\n commitResource(fiber, result);\n });\n\n const fiber = createResourceFiber(HandleWrapperResource<R, P>, () =>\n scheduler.markDirty()\n );\n\n const result = renderResource(fiber, props);\n commitResource(fiber, result);\n\n return result.state;\n};\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAC5B,SAAS,cAAc;AACvB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AACzB,SAAS,eAAe;AAQxB,IAAM,wBAAwB,CAAO;AAAA,EACnC;AAAA,EACA;AACF,MAG4B;AAC1B,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,QAAQ,KAAK;AAChD,QAAM,QAAQ,YAAY,EAAE,MAAM,QAAQ,MAAM,MAAM,CAAC;AACvD,QAAM,cAAc,OAAO,oBAAI,IAAgB,CAAC,EAAE;AAClD,QAAM,WAAW,OAAO,KAAK;AAE7B,YAAU,MAAM;AACd,QAAI,UAAU,SAAS,SAAS;AAC9B,eAAS,UAAU;AACnB,kBAAY,QAAQ,CAAC,aAAa,SAAS,CAAC;AAAA,IAC9C;AAAA,EACF,GAAG,CAAC,KAAK,CAAC;AAEV,QAAM,SAAS;AAAA,IACb,OAAO;AAAA,MACL,UAAU,MAAM,SAAS;AAAA,MACzB,WAAW,CAAC,aAAyB;AACnC,oBAAY,IAAI,QAAQ;AACxB,eAAO,MAAM,YAAY,OAAO,QAAQ;AAAA,MAC1C;AAAA,MACA,aAAa,CAACA,WAAa;AACzB,iBAAS,MAAMA,MAAK;AAAA,MACtB;AAAA,MACA,SAAS;AAAA,IACX;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SAAO;AACT;AAEO,IAAM,iBAAiB,CAC5B,YACyB;AACzB,QAAM,QAAQ;AAAA,IACZ;AAAA,IACA,WAAW,MAAM,gBAAgB,KAAK;AAAA,EACxC;AAEA,QAAM,YAAY,IAAI,gBAAgB,MAAM;AAC1C,UAAMC,UAAS,eAAe,OAAO,KAAK;AAC1C,mBAAe,OAAOA,OAAM;AAAA,EAC9B,CAAC;AAED,QAAM,QAAQ;AAAA,IAAoB;AAAA,IAA6B,MAC7D,UAAU,UAAU;AAAA,EACtB;AAEA,QAAM,SAAS,eAAe,OAAO,KAAK;AAC1C,iBAAe,OAAO,MAAM;AAE5B,SAAO,OAAO;AAChB;","names":["props","result"]}
@@ -0,0 +1,4 @@
1
+ import { ResourceFiber, RenderResult } from "./types";
2
+ export declare function commitRender(renderContext: RenderResult, executionContext: ResourceFiber): void;
3
+ export declare function cleanupAllEffects(executionContext: ResourceFiber): void;
4
+ //# sourceMappingURL=commit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit.d.ts","sourceRoot":"","sources":["../../src/core/commit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEtD,wBAAgB,YAAY,CAC1B,aAAa,EAAE,YAAY,EAC3B,gBAAgB,EAAE,aAAa,GAC9B,IAAI,CAuDN;AAED,wBAAgB,iBAAiB,CAAC,gBAAgB,EAAE,aAAa,QAYhE"}
@@ -0,0 +1,60 @@
1
+ // src/core/commit.ts
2
+ function commitRender(renderContext, executionContext) {
3
+ renderContext.commitTasks.forEach((task) => {
4
+ const cellIndex = task.cellIndex;
5
+ const effectCell = executionContext.cells[cellIndex];
6
+ if (effectCell.type !== "effect") {
7
+ throw new Error("Cannot find effect cell");
8
+ }
9
+ let shouldRunEffect = true;
10
+ if (effectCell.deps !== void 0 && task.deps !== void 0) {
11
+ shouldRunEffect = effectCell.deps.length !== task.deps.length || effectCell.deps.some((dep, j) => !Object.is(dep, task.deps[j]));
12
+ }
13
+ if (shouldRunEffect) {
14
+ if (effectCell.mounted) {
15
+ if (typeof effectCell.deps !== typeof task.deps) {
16
+ throw new Error(
17
+ "tapEffect called with and without dependencies across re-renders"
18
+ );
19
+ }
20
+ try {
21
+ if (effectCell.cleanup) {
22
+ effectCell.cleanup();
23
+ }
24
+ } finally {
25
+ effectCell.mounted = false;
26
+ }
27
+ }
28
+ try {
29
+ const cleanup = task.effect();
30
+ if (cleanup !== void 0 && typeof cleanup !== "function") {
31
+ throw new Error(
32
+ `An effect function must either return a cleanup function or nothing. Received: ${typeof cleanup}`
33
+ );
34
+ }
35
+ effectCell.mounted = true;
36
+ effectCell.cleanup = typeof cleanup === "function" ? cleanup : void 0;
37
+ effectCell.deps = task.deps;
38
+ } catch (error) {
39
+ throw error;
40
+ }
41
+ }
42
+ });
43
+ }
44
+ function cleanupAllEffects(executionContext) {
45
+ for (let i = executionContext.cells.length - 1; i >= 0; i--) {
46
+ const cell = executionContext.cells[i];
47
+ if (cell?.type === "effect" && cell.cleanup) {
48
+ try {
49
+ cell.cleanup();
50
+ } finally {
51
+ cell.mounted = false;
52
+ }
53
+ }
54
+ }
55
+ }
56
+ export {
57
+ cleanupAllEffects,
58
+ commitRender
59
+ };
60
+ //# sourceMappingURL=commit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/commit.ts"],"sourcesContent":["import { ResourceFiber, RenderResult } from \"./types\";\n\nexport function commitRender(\n renderContext: RenderResult,\n executionContext: ResourceFiber\n): void {\n // Process all tasks collected during render\n renderContext.commitTasks.forEach((task) => {\n const cellIndex = task.cellIndex;\n const effectCell = executionContext.cells[cellIndex]!;\n if (effectCell.type !== \"effect\") {\n throw new Error(\"Cannot find effect cell\");\n }\n\n // Check if deps changed\n let shouldRunEffect = true;\n\n if (effectCell.deps !== undefined && task.deps !== undefined) {\n shouldRunEffect =\n effectCell.deps.length !== task.deps.length ||\n effectCell.deps.some((dep, j) => !Object.is(dep, task.deps![j]));\n }\n\n // Run cleanup if effect will re-run\n if (shouldRunEffect) {\n if (effectCell.mounted) {\n if (typeof effectCell.deps !== typeof task.deps) {\n throw new Error(\n \"tapEffect called with and without dependencies across re-renders\"\n );\n }\n\n try {\n if (effectCell.cleanup) {\n effectCell.cleanup();\n }\n } finally {\n effectCell.mounted = false;\n }\n }\n\n try {\n const cleanup = task.effect();\n\n if (cleanup !== undefined && typeof cleanup !== \"function\") {\n throw new Error(\n \"An effect function must either return a cleanup function or nothing. \" +\n `Received: ${typeof cleanup}`\n );\n }\n\n effectCell.mounted = true;\n effectCell.cleanup =\n typeof cleanup === \"function\" ? cleanup : undefined;\n effectCell.deps = task.deps;\n } catch (error) {\n throw error;\n }\n }\n });\n}\n\nexport function cleanupAllEffects(executionContext: ResourceFiber) {\n // Run cleanups in reverse order\n for (let i = executionContext.cells.length - 1; i >= 0; i--) {\n const cell = executionContext.cells[i];\n if (cell?.type === \"effect\" && cell.cleanup) {\n try {\n cell.cleanup();\n } finally {\n cell.mounted = false;\n }\n }\n }\n}\n"],"mappings":";AAEO,SAAS,aACd,eACA,kBACM;AAEN,gBAAc,YAAY,QAAQ,CAAC,SAAS;AAC1C,UAAM,YAAY,KAAK;AACvB,UAAM,aAAa,iBAAiB,MAAM,SAAS;AACnD,QAAI,WAAW,SAAS,UAAU;AAChC,YAAM,IAAI,MAAM,yBAAyB;AAAA,IAC3C;AAGA,QAAI,kBAAkB;AAEtB,QAAI,WAAW,SAAS,UAAa,KAAK,SAAS,QAAW;AAC5D,wBACE,WAAW,KAAK,WAAW,KAAK,KAAK,UACrC,WAAW,KAAK,KAAK,CAAC,KAAK,MAAM,CAAC,OAAO,GAAG,KAAK,KAAK,KAAM,CAAC,CAAC,CAAC;AAAA,IACnE;AAGA,QAAI,iBAAiB;AACnB,UAAI,WAAW,SAAS;AACtB,YAAI,OAAO,WAAW,SAAS,OAAO,KAAK,MAAM;AAC/C,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAAA,QACF;AAEA,YAAI;AACF,cAAI,WAAW,SAAS;AACtB,uBAAW,QAAQ;AAAA,UACrB;AAAA,QACF,UAAE;AACA,qBAAW,UAAU;AAAA,QACvB;AAAA,MACF;AAEA,UAAI;AACF,cAAM,UAAU,KAAK,OAAO;AAE5B,YAAI,YAAY,UAAa,OAAO,YAAY,YAAY;AAC1D,gBAAM,IAAI;AAAA,YACR,kFACe,OAAO,OAAO;AAAA,UAC/B;AAAA,QACF;AAEA,mBAAW,UAAU;AACrB,mBAAW,UACT,OAAO,YAAY,aAAa,UAAU;AAC5C,mBAAW,OAAO,KAAK;AAAA,MACzB,SAAS,OAAO;AACd,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEO,SAAS,kBAAkB,kBAAiC;AAEjE,WAAS,IAAI,iBAAiB,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;AAC3D,UAAM,OAAO,iBAAiB,MAAM,CAAC;AACrC,QAAI,MAAM,SAAS,YAAY,KAAK,SAAS;AAC3C,UAAI;AACF,aAAK,QAAQ;AAAA,MACf,UAAE;AACA,aAAK,UAAU;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,4 @@
1
+ import { ResourceFiber } from "./types";
2
+ export declare function withResourceFiber(fiber: ResourceFiber, fn: () => void): void;
3
+ export declare function getCurrentResourceFiber(): ResourceFiber;
4
+ //# sourceMappingURL=execution-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-context.d.ts","sourceRoot":"","sources":["../../src/core/execution-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxC,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAwB5E;AACD,wBAAgB,uBAAuB,IAAI,aAAa,CAKvD"}
@@ -0,0 +1,33 @@
1
+ // src/core/execution-context.ts
2
+ var currentResourceFiber = null;
3
+ function withResourceFiber(fiber, fn) {
4
+ if (fiber.isRendering) throw new Error("Execution context is locked");
5
+ fiber.isRendering = true;
6
+ fiber.commitTasks = [];
7
+ fiber.currentIndex = 0;
8
+ const previousContext = currentResourceFiber;
9
+ currentResourceFiber = fiber;
10
+ try {
11
+ fn();
12
+ fiber.isFirstRender = false;
13
+ if (fiber.cells.length !== fiber.currentIndex) {
14
+ throw new Error(
15
+ `Rendered ${fiber.currentIndex} hooks but expected ${fiber.cells.length}. Hooks must be called in the exact same order in every render.`
16
+ );
17
+ }
18
+ } finally {
19
+ currentResourceFiber = previousContext;
20
+ fiber.isRendering = false;
21
+ }
22
+ }
23
+ function getCurrentResourceFiber() {
24
+ if (!currentResourceFiber) {
25
+ throw new Error("No resource fiber available");
26
+ }
27
+ return currentResourceFiber;
28
+ }
29
+ export {
30
+ getCurrentResourceFiber,
31
+ withResourceFiber
32
+ };
33
+ //# sourceMappingURL=execution-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/execution-context.ts"],"sourcesContent":["import { ResourceFiber } from \"./types\";\n\nlet currentResourceFiber: ResourceFiber | null = null;\n\nexport function withResourceFiber(fiber: ResourceFiber, fn: () => void): void {\n if (fiber.isRendering) throw new Error(\"Execution context is locked\");\n fiber.isRendering = true;\n fiber.commitTasks = [];\n fiber.currentIndex = 0;\n\n const previousContext = currentResourceFiber;\n currentResourceFiber = fiber;\n try {\n fn();\n\n fiber.isFirstRender = false;\n\n // ensure hook count matches\n if (fiber.cells.length !== fiber.currentIndex) {\n throw new Error(\n `Rendered ${fiber.currentIndex} hooks but expected ${fiber.cells.length}. ` +\n \"Hooks must be called in the exact same order in every render.\"\n );\n }\n } finally {\n currentResourceFiber = previousContext;\n fiber.isRendering = false;\n }\n}\nexport function getCurrentResourceFiber(): ResourceFiber {\n if (!currentResourceFiber) {\n throw new Error(\"No resource fiber available\");\n }\n return currentResourceFiber;\n}\n"],"mappings":";AAEA,IAAI,uBAA6C;AAE1C,SAAS,kBAAkB,OAAsB,IAAsB;AAC5E,MAAI,MAAM,YAAa,OAAM,IAAI,MAAM,6BAA6B;AACpE,QAAM,cAAc;AACpB,QAAM,cAAc,CAAC;AACrB,QAAM,eAAe;AAErB,QAAM,kBAAkB;AACxB,yBAAuB;AACvB,MAAI;AACF,OAAG;AAEH,UAAM,gBAAgB;AAGtB,QAAI,MAAM,MAAM,WAAW,MAAM,cAAc;AAC7C,YAAM,IAAI;AAAA,QACR,YAAY,MAAM,YAAY,uBAAuB,MAAM,MAAM,MAAM;AAAA,MAEzE;AAAA,IACF;AAAA,EACF,UAAE;AACA,2BAAuB;AACvB,UAAM,cAAc;AAAA,EACtB;AACF;AACO,SAAS,0BAAyC;AACvD,MAAI,CAAC,sBAAsB;AACzB,UAAM,IAAI,MAAM,6BAA6B;AAAA,EAC/C;AACA,SAAO;AACT;","names":[]}
@@ -0,0 +1,3 @@
1
+ import { ResourceFn, ResourceElementConstructor } from "./types";
2
+ export declare function resource<R, P>(type: ResourceFn<R, P>): ResourceElementConstructor<R, P>;
3
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../src/core/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAEV,0BAA0B,EAC3B,MAAM,SAAS,CAAC;AAEjB,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,IAAI,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GACrB,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAC,CAQlC"}
@@ -0,0 +1,14 @@
1
+ // src/core/resource.ts
2
+ function resource(type) {
3
+ return (props, options) => {
4
+ return {
5
+ type,
6
+ props,
7
+ ...options?.key !== void 0 && { key: options.key }
8
+ };
9
+ };
10
+ }
11
+ export {
12
+ resource
13
+ };
14
+ //# sourceMappingURL=resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/resource.ts"],"sourcesContent":["import {\n ResourceFn,\n ResourceElement,\n ResourceElementConstructor,\n} from \"./types\";\n\nexport function resource<R, P>(\n type: ResourceFn<R, P>\n): ResourceElementConstructor<R, P> {\n return (props: P, options?: { key?: string | number }) => {\n return {\n type,\n props,\n ...(options?.key !== undefined && { key: options.key }),\n } as ResourceElement<R, P>;\n };\n}\n"],"mappings":";AAMO,SAAS,SACd,MACkC;AAClC,SAAO,CAAC,OAAU,YAAwC;AACxD,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,GAAI,SAAS,QAAQ,UAAa,EAAE,KAAK,QAAQ,IAAI;AAAA,IACvD;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,14 @@
1
+ type Task = () => void;
2
+ export declare class UpdateScheduler {
3
+ private readonly _task;
4
+ private _isDirty;
5
+ private _hasScheduledTask;
6
+ private _isFlushing;
7
+ private static readonly MAX_FLUSH_DEPTH;
8
+ constructor(_task: Task);
9
+ get isDirty(): boolean;
10
+ markDirty(): void;
11
+ flushSync(): void;
12
+ }
13
+ export {};
14
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../src/core/scheduler.ts"],"names":[],"mappings":"AAAA,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;AA6BvB,qBAAa,eAAe;IAMd,OAAO,CAAC,QAAQ,CAAC,KAAK;IALlC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,iBAAiB,CAAS;IAClC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAM;gBAEhB,KAAK,EAAE,IAAI;IAExC,IAAI,OAAO,YAEV;IAED,SAAS;IAaT,SAAS;CAyBV"}
@@ -0,0 +1,66 @@
1
+ // src/core/scheduler.ts
2
+ var queue = [];
3
+ var isFlushPending = false;
4
+ function flushQueue() {
5
+ isFlushPending = false;
6
+ const tasksToRun = queue;
7
+ queue = [];
8
+ for (const task of tasksToRun) {
9
+ try {
10
+ task();
11
+ } catch (error) {
12
+ console.error("Error in scheduled task:", error);
13
+ }
14
+ }
15
+ }
16
+ function scheduleUpdate(task) {
17
+ queue.push(task);
18
+ if (!isFlushPending) {
19
+ isFlushPending = true;
20
+ queueMicrotask(flushQueue);
21
+ }
22
+ }
23
+ var UpdateScheduler = class _UpdateScheduler {
24
+ constructor(_task) {
25
+ this._task = _task;
26
+ }
27
+ _isDirty = false;
28
+ _hasScheduledTask = false;
29
+ _isFlushing = false;
30
+ static MAX_FLUSH_DEPTH = 50;
31
+ get isDirty() {
32
+ return this._isDirty;
33
+ }
34
+ markDirty() {
35
+ this._isDirty = true;
36
+ if (this._hasScheduledTask || this._isFlushing) return;
37
+ this._hasScheduledTask = true;
38
+ scheduleUpdate(() => {
39
+ this._hasScheduledTask = false;
40
+ this.flushSync();
41
+ });
42
+ }
43
+ flushSync() {
44
+ if (this._isFlushing) return;
45
+ this._isFlushing = true;
46
+ let flushDepth = 0;
47
+ try {
48
+ while (this._isDirty) {
49
+ flushDepth++;
50
+ if (flushDepth > _UpdateScheduler.MAX_FLUSH_DEPTH) {
51
+ throw new Error(
52
+ `Maximum update depth exceeded. This can happen when a resource repeatedly calls setState inside tapEffect.`
53
+ );
54
+ }
55
+ this._isDirty = false;
56
+ this._task();
57
+ }
58
+ } finally {
59
+ this._isFlushing = false;
60
+ }
61
+ }
62
+ };
63
+ export {
64
+ UpdateScheduler
65
+ };
66
+ //# sourceMappingURL=scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/scheduler.ts"],"sourcesContent":["type Task = () => void;\n\nlet queue: Task[] = [];\nlet isFlushPending = false;\n\nfunction flushQueue() {\n isFlushPending = false;\n\n const tasksToRun = queue;\n queue = [];\n\n for (const task of tasksToRun) {\n try {\n task();\n } catch (error) {\n console.error(\"Error in scheduled task:\", error);\n }\n }\n}\n\nfunction scheduleUpdate(task: Task) {\n queue.push(task);\n\n if (!isFlushPending) {\n isFlushPending = true;\n queueMicrotask(flushQueue);\n }\n}\n\nexport class UpdateScheduler {\n private _isDirty = false;\n private _hasScheduledTask = false;\n private _isFlushing = false;\n private static readonly MAX_FLUSH_DEPTH = 50;\n\n constructor(private readonly _task: Task) {}\n\n get isDirty() {\n return this._isDirty;\n }\n\n markDirty() {\n this._isDirty = true;\n\n if (this._hasScheduledTask || this._isFlushing) return;\n this._hasScheduledTask = true;\n\n scheduleUpdate(() => {\n this._hasScheduledTask = false;\n\n this.flushSync();\n });\n }\n\n flushSync() {\n if (this._isFlushing) return;\n\n this._isFlushing = true;\n let flushDepth = 0;\n\n try {\n while (this._isDirty) {\n flushDepth++;\n\n if (flushDepth > UpdateScheduler.MAX_FLUSH_DEPTH) {\n throw new Error(\n `Maximum update depth exceeded. This can happen when a resource ` +\n `repeatedly calls setState inside tapEffect.`\n );\n }\n\n this._isDirty = false;\n this._task();\n }\n } finally {\n this._isFlushing = false;\n }\n }\n\n}\n"],"mappings":";AAEA,IAAI,QAAgB,CAAC;AACrB,IAAI,iBAAiB;AAErB,SAAS,aAAa;AACpB,mBAAiB;AAEjB,QAAM,aAAa;AACnB,UAAQ,CAAC;AAET,aAAW,QAAQ,YAAY;AAC7B,QAAI;AACF,WAAK;AAAA,IACP,SAAS,OAAO;AACd,cAAQ,MAAM,4BAA4B,KAAK;AAAA,IACjD;AAAA,EACF;AACF;AAEA,SAAS,eAAe,MAAY;AAClC,QAAM,KAAK,IAAI;AAEf,MAAI,CAAC,gBAAgB;AACnB,qBAAiB;AACjB,mBAAe,UAAU;AAAA,EAC3B;AACF;AAEO,IAAM,kBAAN,MAAM,iBAAgB;AAAA,EAM3B,YAA6B,OAAa;AAAb;AAAA,EAAc;AAAA,EALnC,WAAW;AAAA,EACX,oBAAoB;AAAA,EACpB,cAAc;AAAA,EACtB,OAAwB,kBAAkB;AAAA,EAI1C,IAAI,UAAU;AACZ,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,YAAY;AACV,SAAK,WAAW;AAEhB,QAAI,KAAK,qBAAqB,KAAK,YAAa;AAChD,SAAK,oBAAoB;AAEzB,mBAAe,MAAM;AACnB,WAAK,oBAAoB;AAEzB,WAAK,UAAU;AAAA,IACjB,CAAC;AAAA,EACH;AAAA,EAEA,YAAY;AACV,QAAI,KAAK,YAAa;AAEtB,SAAK,cAAc;AACnB,QAAI,aAAa;AAEjB,QAAI;AACF,aAAO,KAAK,UAAU;AACpB;AAEA,YAAI,aAAa,iBAAgB,iBAAiB;AAChD,gBAAM,IAAI;AAAA,YACR;AAAA,UAEF;AAAA,QACF;AAEA,aAAK,WAAW;AAChB,aAAK,MAAM;AAAA,MACb;AAAA,IACF,UAAE;AACA,WAAK,cAAc;AAAA,IACrB;AAAA,EACF;AAEF;","names":[]}
@@ -0,0 +1,44 @@
1
+ export type ResourceFn<R, P> = (props: P) => R;
2
+ export type Unsubscribe = () => void;
3
+ export type ResourceElement<R, P = any> = {
4
+ type: ResourceFn<R, P>;
5
+ props: P;
6
+ key?: string | number;
7
+ };
8
+ export type ResourceElementConstructor<R, P> = (props: P, options?: {
9
+ key?: string | number;
10
+ }) => ResourceElement<R, P>;
11
+ export type StateUpdater<S> = S | ((prev: S) => S);
12
+ export type Destructor = () => void;
13
+ export type EffectCallback = () => void | Destructor;
14
+ export type Cell = {
15
+ type: "state";
16
+ value: any;
17
+ set: (updater: StateUpdater<any>) => void;
18
+ } | {
19
+ type: "effect";
20
+ mounted: boolean;
21
+ cleanup?: Destructor | undefined;
22
+ deps?: readonly unknown[] | undefined;
23
+ };
24
+ export interface EffectTask {
25
+ effect: EffectCallback;
26
+ deps?: readonly unknown[] | undefined;
27
+ cellIndex: number;
28
+ }
29
+ export interface RenderResult {
30
+ state: any;
31
+ props: any;
32
+ commitTasks: EffectTask[];
33
+ }
34
+ export interface ResourceFiber {
35
+ readonly scheduleRerender: () => void;
36
+ readonly resourceFn: ResourceFn<any, any>;
37
+ cells: Cell[];
38
+ currentIndex: number;
39
+ commitTasks: EffectTask[];
40
+ isFirstRender: boolean;
41
+ committedProps: any;
42
+ isRendering: boolean;
43
+ }
44
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;AAE/C,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,IAAI;IACxC,IAAI,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACvB,KAAK,EAAE,CAAC,CAAC;IACT,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,0BAA0B,CAAC,CAAC,EAAE,CAAC,IAAI,CAC7C,KAAK,EAAE,CAAC,EACR,OAAO,CAAC,EAAE;IACR,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,KACE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAE3B,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AAEnD,MAAM,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC;AACpC,MAAM,MAAM,cAAc,GAAG,MAAM,IAAI,GAAG,UAAU,CAAC;AAErD,MAAM,MAAM,IAAI,GACZ;IACE,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,GAAG,CAAC;IACX,GAAG,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC;CAC3C,GACD;IACE,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IACjC,IAAI,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,SAAS,CAAC;CACvC,CAAC;AAEN,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,cAAc,CAAC;IACvB,IAAI,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,SAAS,CAAC;IACtC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,GAAG,CAAC;IACX,KAAK,EAAE,GAAG,CAAC;IACX,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,IAAI,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAE1C,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,aAAa,EAAE,OAAO,CAAC;IAEvB,cAAc,EAAE,GAAG,CAAC;IACpB,WAAW,EAAE,OAAO,CAAC;CACtB"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,2 @@
1
+ export declare const depsShallowEqual: (a: readonly unknown[], b: readonly unknown[]) => boolean;
2
+ //# sourceMappingURL=depsShallowEqual.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"depsShallowEqual.d.ts","sourceRoot":"","sources":["../../src/hooks/depsShallowEqual.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,GAC3B,GAAG,SAAS,OAAO,EAAE,EACrB,GAAG,SAAS,OAAO,EAAE,YAOtB,CAAC"}
@@ -0,0 +1,12 @@
1
+ // src/hooks/depsShallowEqual.ts
2
+ var depsShallowEqual = (a, b) => {
3
+ if (a.length !== b.length) return false;
4
+ for (let i = 0; i < a.length; i++) {
5
+ if (!Object.is(a[i], b[i])) return false;
6
+ }
7
+ return true;
8
+ };
9
+ export {
10
+ depsShallowEqual
11
+ };
12
+ //# sourceMappingURL=depsShallowEqual.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/depsShallowEqual.ts"],"sourcesContent":["export const depsShallowEqual = (\n a: readonly unknown[],\n b: readonly unknown[]\n) => {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (!Object.is(a[i], b[i])) return false;\n }\n return true;\n};\n"],"mappings":";AAAO,IAAM,mBAAmB,CAC9B,GACA,MACG;AACH,MAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAClC,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,QAAI,CAAC,OAAO,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAG,QAAO;AAAA,EACrC;AACA,SAAO;AACT;","names":[]}
@@ -0,0 +1,2 @@
1
+ export declare const tapCallback: <T extends (...args: any[]) => any>(fn: T, deps: readonly unknown[]) => T;
2
+ //# sourceMappingURL=tap-callback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tap-callback.d.ts","sourceRoot":"","sources":["../../src/hooks/tap-callback.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAC3D,IAAI,CAAC,EACL,MAAM,SAAS,OAAO,EAAE,KACvB,CAEF,CAAC"}
@@ -0,0 +1,9 @@
1
+ // src/hooks/tap-callback.ts
2
+ import { tapMemo } from "./tap-memo.js";
3
+ var tapCallback = (fn, deps) => {
4
+ return tapMemo(() => fn, deps);
5
+ };
6
+ export {
7
+ tapCallback
8
+ };
9
+ //# sourceMappingURL=tap-callback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/tap-callback.ts"],"sourcesContent":["import { tapMemo } from \"./tap-memo\";\n\nexport const tapCallback = <T extends (...args: any[]) => any>(\n fn: T,\n deps: readonly unknown[]\n): T => {\n return tapMemo(() => fn, deps);\n};"],"mappings":";AAAA,SAAS,eAAe;AAEjB,IAAM,cAAc,CACzB,IACA,SACM;AACN,SAAO,QAAQ,MAAM,IAAI,IAAI;AAC/B;","names":[]}
@@ -0,0 +1,4 @@
1
+ import { EffectCallback } from "../core/types";
2
+ export declare function tapEffect(effect: EffectCallback): void;
3
+ export declare function tapEffect(effect: EffectCallback, deps: readonly unknown[]): void;
4
+ //# sourceMappingURL=tap-effect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tap-effect.d.ts","sourceRoot":"","sources":["../../src/hooks/tap-effect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAQ,MAAM,eAAe,CAAC;AAmCrD,wBAAgB,SAAS,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;AACxD,wBAAgB,SAAS,CACvB,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,SAAS,OAAO,EAAE,GACvB,IAAI,CAAC"}
@@ -0,0 +1,32 @@
1
+ // src/hooks/tap-effect.ts
2
+ import { getCurrentResourceFiber } from "../core/execution-context.js";
3
+ function getEffectCell() {
4
+ const executionContext = getCurrentResourceFiber();
5
+ const index = executionContext.currentIndex++;
6
+ if (!executionContext.isFirstRender && index >= executionContext.cells.length) {
7
+ throw new Error(
8
+ "Rendered more hooks than during the previous render. Hooks must be called in the exact same order in every render."
9
+ );
10
+ }
11
+ if (!executionContext.cells[index]) {
12
+ const cell2 = {
13
+ type: "effect",
14
+ mounted: false
15
+ };
16
+ executionContext.cells[index] = cell2;
17
+ }
18
+ const cell = executionContext.cells[index];
19
+ if (cell.type !== "effect") {
20
+ throw new Error("Hook order changed between renders");
21
+ }
22
+ return index;
23
+ }
24
+ function tapEffect(effect, deps) {
25
+ const executionContext = getCurrentResourceFiber();
26
+ const cellIndex = getEffectCell();
27
+ executionContext.commitTasks.push({ effect, deps, cellIndex });
28
+ }
29
+ export {
30
+ tapEffect
31
+ };
32
+ //# sourceMappingURL=tap-effect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/tap-effect.ts"],"sourcesContent":["import { getCurrentResourceFiber } from \"../core/execution-context\";\nimport { EffectCallback, Cell } from \"../core/types\";\n\nfunction getEffectCell(): number {\n const executionContext = getCurrentResourceFiber();\n const index = executionContext.currentIndex++;\n\n // Check if we're trying to use more hooks than in previous renders\n if (\n !executionContext.isFirstRender &&\n index >= executionContext.cells.length\n ) {\n throw new Error(\n \"Rendered more hooks than during the previous render. \" +\n \"Hooks must be called in the exact same order in every render.\"\n );\n }\n\n if (!executionContext.cells[index]) {\n // Create the effect cell\n const cell: Cell & { type: \"effect\" } = {\n type: \"effect\",\n mounted: false,\n };\n\n executionContext.cells[index] = cell;\n }\n\n const cell = executionContext.cells[index];\n if (cell.type !== \"effect\") {\n throw new Error(\"Hook order changed between renders\");\n }\n\n return index;\n}\n\nexport function tapEffect(effect: EffectCallback): void;\nexport function tapEffect(\n effect: EffectCallback,\n deps: readonly unknown[]\n): void;\nexport function tapEffect(\n effect: EffectCallback,\n deps?: readonly unknown[]\n): void {\n const executionContext = getCurrentResourceFiber();\n\n // Reserve a spot for the effect cell and get its index\n const cellIndex = getEffectCell();\n\n // Add task to render context for execution in commit phase\n executionContext.commitTasks.push({ effect, deps, cellIndex });\n}\n"],"mappings":";AAAA,SAAS,+BAA+B;AAGxC,SAAS,gBAAwB;AAC/B,QAAM,mBAAmB,wBAAwB;AACjD,QAAM,QAAQ,iBAAiB;AAG/B,MACE,CAAC,iBAAiB,iBAClB,SAAS,iBAAiB,MAAM,QAChC;AACA,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AAEA,MAAI,CAAC,iBAAiB,MAAM,KAAK,GAAG;AAElC,UAAMA,QAAkC;AAAA,MACtC,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAEA,qBAAiB,MAAM,KAAK,IAAIA;AAAA,EAClC;AAEA,QAAM,OAAO,iBAAiB,MAAM,KAAK;AACzC,MAAI,KAAK,SAAS,UAAU;AAC1B,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AAEA,SAAO;AACT;AAOO,SAAS,UACd,QACA,MACM;AACN,QAAM,mBAAmB,wBAAwB;AAGjD,QAAM,YAAY,cAAc;AAGhC,mBAAiB,YAAY,KAAK,EAAE,QAAQ,MAAM,UAAU,CAAC;AAC/D;","names":["cell"]}
@@ -0,0 +1,2 @@
1
+ export declare const tapMemo: <T>(fn: () => T, deps: readonly unknown[]) => T;
2
+ //# sourceMappingURL=tap-memo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tap-memo.d.ts","sourceRoot":"","sources":["../../src/hooks/tap-memo.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,IAAI,MAAM,CAAC,EAAE,MAAM,SAAS,OAAO,EAAE,MAY/D,CAAC"}
@@ -0,0 +1,18 @@
1
+ // src/hooks/tap-memo.ts
2
+ import { tapRef } from "./tap-ref.js";
3
+ import { depsShallowEqual } from "./depsShallowEqual.js";
4
+ var tapMemo = (fn, deps) => {
5
+ const dataRef = tapRef(() => ({
6
+ value: fn(),
7
+ deps
8
+ }));
9
+ if (!depsShallowEqual(dataRef.current.deps, deps)) {
10
+ dataRef.current.value = fn();
11
+ dataRef.current.deps = deps;
12
+ }
13
+ return dataRef.current.value;
14
+ };
15
+ export {
16
+ tapMemo
17
+ };
18
+ //# sourceMappingURL=tap-memo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/tap-memo.ts"],"sourcesContent":["import { tapRef } from \"./tap-ref\";\nimport { depsShallowEqual } from \"./depsShallowEqual\";\n\nexport const tapMemo = <T>(fn: () => T, deps: readonly unknown[]) => {\n const dataRef = tapRef(() => ({\n value: fn(),\n deps,\n }));\n\n if (!depsShallowEqual(dataRef.current.deps, deps)) {\n dataRef.current.value = fn();\n dataRef.current.deps = deps;\n }\n\n return dataRef.current.value;\n};\n"],"mappings":";AAAA,SAAS,cAAc;AACvB,SAAS,wBAAwB;AAE1B,IAAM,UAAU,CAAI,IAAa,SAA6B;AACnE,QAAM,UAAU,OAAO,OAAO;AAAA,IAC5B,OAAO,GAAG;AAAA,IACV;AAAA,EACF,EAAE;AAEF,MAAI,CAAC,iBAAiB,QAAQ,QAAQ,MAAM,IAAI,GAAG;AACjD,YAAQ,QAAQ,QAAQ,GAAG;AAC3B,YAAQ,QAAQ,OAAO;AAAA,EACzB;AAEA,SAAO,QAAQ,QAAQ;AACzB;","names":[]}
@@ -0,0 +1,7 @@
1
+ interface MutableRefObject<T> {
2
+ current: T;
3
+ }
4
+ export declare function tapRef<T>(initialValue: T | (() => T)): MutableRefObject<T>;
5
+ export declare function tapRef<T = undefined>(): MutableRefObject<T | undefined>;
6
+ export {};
7
+ //# sourceMappingURL=tap-ref.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tap-ref.d.ts","sourceRoot":"","sources":["../../src/hooks/tap-ref.ts"],"names":[],"mappings":"AAEA,UAAU,gBAAgB,CAAC,CAAC;IAC1B,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;AAC5E,wBAAgB,MAAM,CAAC,CAAC,GAAG,SAAS,KAAK,gBAAgB,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ // src/hooks/tap-ref.ts
2
+ import { tapState } from "./tap-state.js";
3
+ function tapRef(initialValue) {
4
+ const [state] = tapState(() => ({
5
+ current: initialValue !== void 0 && typeof initialValue === "function" ? initialValue() : initialValue
6
+ }));
7
+ return state;
8
+ }
9
+ export {
10
+ tapRef
11
+ };
12
+ //# sourceMappingURL=tap-ref.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/tap-ref.ts"],"sourcesContent":["import { tapState } from \"./tap-state\";\n\ninterface MutableRefObject<T> {\n current: T;\n}\n\nexport function tapRef<T>(initialValue: T | (() => T)): MutableRefObject<T>;\nexport function tapRef<T = undefined>(): MutableRefObject<T | undefined>;\nexport function tapRef<T>(\n initialValue?: T | (() => T)\n): MutableRefObject<T | undefined> {\n const [state] = tapState(() => ({\n current:\n initialValue !== undefined && typeof initialValue === \"function\"\n ? (initialValue as () => T)()\n : initialValue,\n }));\n return state;\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AAQlB,SAAS,OACd,cACiC;AACjC,QAAM,CAAC,KAAK,IAAI,SAAS,OAAO;AAAA,IAC9B,SACE,iBAAiB,UAAa,OAAO,iBAAiB,aACjD,aAAyB,IAC1B;AAAA,EACR,EAAE;AACF,SAAO;AACT;","names":[]}
@@ -0,0 +1,2 @@
1
+ export declare const tapRerender: () => () => void;
2
+ //# sourceMappingURL=tap-rerender.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tap-rerender.d.ts","sourceRoot":"","sources":["../../src/hooks/tap-rerender.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,kBAGvB,CAAC"}
@@ -0,0 +1,10 @@
1
+ // src/hooks/tap-rerender.ts
2
+ import { getCurrentResourceFiber } from "../core/execution-context.js";
3
+ var tapRerender = () => {
4
+ const executionContext = getCurrentResourceFiber();
5
+ return executionContext.scheduleRerender;
6
+ };
7
+ export {
8
+ tapRerender
9
+ };
10
+ //# sourceMappingURL=tap-rerender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/tap-rerender.ts"],"sourcesContent":["import { getCurrentResourceFiber } from \"../core/execution-context\";\n\nexport const tapRerender = () => {\n const executionContext = getCurrentResourceFiber();\n return executionContext.scheduleRerender;\n};\n"],"mappings":";AAAA,SAAS,+BAA+B;AAEjC,IAAM,cAAc,MAAM;AAC/B,QAAM,mBAAmB,wBAAwB;AACjD,SAAO,iBAAiB;AAC1B;","names":[]}
@@ -0,0 +1,4 @@
1
+ import { ResourceElement } from "../core/types";
2
+ export declare function tapResource<R, P>(element: ResourceElement<R, P>): R;
3
+ export declare function tapResource<R, P>(element: ResourceElement<R, P>, deps: readonly unknown[]): R;
4
+ //# sourceMappingURL=tap-resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tap-resource.d.ts","sourceRoot":"","sources":["../../src/hooks/tap-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAWhD,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;AACrE,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAC9B,OAAO,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EAC9B,IAAI,EAAE,SAAS,OAAO,EAAE,GACvB,CAAC,CAAC"}
@@ -0,0 +1,33 @@
1
+ // src/hooks/tap-resource.ts
2
+ import { tapEffect } from "./tap-effect.js";
3
+ import {
4
+ createResourceFiber,
5
+ unmountResource,
6
+ renderResource,
7
+ commitResource
8
+ } from "../core/ResourceFiber.js";
9
+ import { tapMemo } from "./tap-memo.js";
10
+ import { tapState } from "./tap-state.js";
11
+ function tapResource(element, deps) {
12
+ const [stateVersion, rerender] = tapState({});
13
+ const fiber = tapMemo(
14
+ () => createResourceFiber(element.type, () => rerender({})),
15
+ [element.type]
16
+ );
17
+ const props = deps ? tapMemo(() => element.props, deps) : element.props;
18
+ const result = tapMemo(
19
+ () => renderResource(fiber, props),
20
+ [fiber, props, stateVersion]
21
+ );
22
+ tapEffect(() => {
23
+ return () => unmountResource(fiber);
24
+ }, [fiber]);
25
+ tapEffect(() => {
26
+ commitResource(fiber, result);
27
+ }, [fiber, result]);
28
+ return result.state;
29
+ }
30
+ export {
31
+ tapResource
32
+ };
33
+ //# sourceMappingURL=tap-resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/tap-resource.ts"],"sourcesContent":["import { ResourceElement } from \"../core/types\";\nimport { tapEffect } from \"./tap-effect\";\nimport {\n createResourceFiber,\n unmountResource,\n renderResource,\n commitResource,\n} from \"../core/ResourceFiber\";\nimport { tapMemo } from \"./tap-memo\";\nimport { tapState } from \"./tap-state\";\n\nexport function tapResource<R, P>(element: ResourceElement<R, P>): R;\nexport function tapResource<R, P>(\n element: ResourceElement<R, P>,\n deps: readonly unknown[]\n): R;\nexport function tapResource<R, P>(\n element: ResourceElement<R, P>,\n deps?: readonly unknown[]\n): R {\n const [stateVersion, rerender] = tapState({});\n const fiber = tapMemo(\n () => createResourceFiber(element.type, () => rerender({})),\n [element.type]\n );\n\n const props = deps ? tapMemo(() => element.props, deps) : element.props;\n const result = tapMemo(\n () => renderResource(fiber, props),\n [fiber, props, stateVersion]\n );\n\n tapEffect(() => {\n return () => unmountResource(fiber);\n }, [fiber]);\n\n tapEffect(() => {\n commitResource(fiber, result);\n }, [fiber, result]);\n\n return result.state;\n}\n"],"mappings":";AACA,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,eAAe;AACxB,SAAS,gBAAgB;AAOlB,SAAS,YACd,SACA,MACG;AACH,QAAM,CAAC,cAAc,QAAQ,IAAI,SAAS,CAAC,CAAC;AAC5C,QAAM,QAAQ;AAAA,IACZ,MAAM,oBAAoB,QAAQ,MAAM,MAAM,SAAS,CAAC,CAAC,CAAC;AAAA,IAC1D,CAAC,QAAQ,IAAI;AAAA,EACf;AAEA,QAAM,QAAQ,OAAO,QAAQ,MAAM,QAAQ,OAAO,IAAI,IAAI,QAAQ;AAClE,QAAM,SAAS;AAAA,IACb,MAAM,eAAe,OAAO,KAAK;AAAA,IACjC,CAAC,OAAO,OAAO,YAAY;AAAA,EAC7B;AAEA,YAAU,MAAM;AACd,WAAO,MAAM,gBAAgB,KAAK;AAAA,EACpC,GAAG,CAAC,KAAK,CAAC;AAEV,YAAU,MAAM;AACd,mBAAe,OAAO,MAAM;AAAA,EAC9B,GAAG,CAAC,OAAO,MAAM,CAAC;AAElB,SAAO,OAAO;AAChB;","names":[]}
@@ -0,0 +1,5 @@
1
+ import { ResourceElement } from "../core/types";
2
+ export declare function tapResources<T extends ReadonlyArray<ResourceElement<any, any>>>(elements: T): {
3
+ [K in keyof T]: T[K] extends ResourceElement<any, infer R> ? R : never;
4
+ };
5
+ //# sourceMappingURL=tap-resources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tap-resources.d.ts","sourceRoot":"","sources":["../../src/hooks/tap-resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,eAAe,EAAiB,MAAM,eAAe,CAAC;AAmB7E,wBAAgB,YAAY,CAC1B,CAAC,SAAS,aAAa,CAAC,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,EAElD,QAAQ,EAAE,CAAC,GACV;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CAAE,CAwG5E"}