@assistant-ui/tap 0.0.1 → 0.1.0

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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -2
  3. package/dist/__tests__/test-utils.d.ts +10 -10
  4. package/dist/__tests__/test-utils.d.ts.map +1 -1
  5. package/dist/__tests__/test-utils.js +3 -82
  6. package/dist/__tests__/test-utils.js.map +1 -1
  7. package/dist/core/ResourceFiber.d.ts +4 -4
  8. package/dist/core/ResourceFiber.d.ts.map +1 -1
  9. package/dist/core/ResourceFiber.js +19 -11
  10. package/dist/core/ResourceFiber.js.map +1 -1
  11. package/dist/core/ResourceHandle.d.ts +3 -1
  12. package/dist/core/ResourceHandle.d.ts.map +1 -1
  13. package/dist/core/ResourceHandle.js +23 -10
  14. package/dist/core/ResourceHandle.js.map +1 -1
  15. package/dist/core/commit.d.ts +2 -2
  16. package/dist/core/commit.d.ts.map +1 -1
  17. package/dist/core/commit.js +9 -5
  18. package/dist/core/commit.js.map +1 -1
  19. package/dist/core/execution-context.d.ts +2 -2
  20. package/dist/core/execution-context.d.ts.map +1 -1
  21. package/dist/core/execution-context.js +0 -4
  22. package/dist/core/execution-context.js.map +1 -1
  23. package/dist/core/resource.d.ts +1 -1
  24. package/dist/core/resource.d.ts.map +1 -1
  25. package/dist/core/resource.js.map +1 -1
  26. package/dist/core/scheduler.d.ts.map +1 -1
  27. package/dist/core/scheduler.js.map +1 -1
  28. package/dist/core/types.d.ts +10 -7
  29. package/dist/core/types.d.ts.map +1 -1
  30. package/dist/hooks/depsShallowEqual.js.map +1 -1
  31. package/dist/hooks/tap-callback.js.map +1 -1
  32. package/dist/hooks/tap-effect.d.ts.map +1 -1
  33. package/dist/hooks/tap-effect.js +12 -8
  34. package/dist/hooks/tap-effect.js.map +1 -1
  35. package/dist/hooks/tap-inline-resource.d.ts +3 -0
  36. package/dist/hooks/tap-inline-resource.d.ts.map +1 -0
  37. package/dist/hooks/tap-inline-resource.js +8 -0
  38. package/dist/hooks/tap-inline-resource.js.map +1 -0
  39. package/dist/hooks/tap-ref.d.ts +3 -4
  40. package/dist/hooks/tap-ref.d.ts.map +1 -1
  41. package/dist/hooks/tap-ref.js.map +1 -1
  42. package/dist/hooks/tap-resource.js.map +1 -1
  43. package/dist/hooks/tap-resources.d.ts +1 -1
  44. package/dist/hooks/tap-resources.d.ts.map +1 -1
  45. package/dist/hooks/tap-resources.js +44 -48
  46. package/dist/hooks/tap-resources.js.map +1 -1
  47. package/dist/hooks/tap-state.d.ts +2 -1
  48. package/dist/hooks/tap-state.d.ts.map +1 -1
  49. package/dist/hooks/tap-state.js +19 -10
  50. package/dist/hooks/tap-state.js.map +1 -1
  51. package/dist/index.d.ts +3 -1
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +4 -0
  54. package/dist/index.js.map +1 -1
  55. package/dist/react/index.js.map +1 -1
  56. package/dist/react/use-resource.d.ts.map +1 -1
  57. package/dist/react/use-resource.js +2 -3
  58. package/dist/react/use-resource.js.map +1 -1
  59. package/package.json +2 -1
  60. package/dist/hooks/tap-rerender.d.ts +0 -2
  61. package/dist/hooks/tap-rerender.d.ts.map +0 -1
  62. package/dist/hooks/tap-rerender.js +0 -10
  63. package/dist/hooks/tap-rerender.js.map +0 -1
@@ -1 +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"}
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;CAwBV"}
@@ -1 +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":[]}
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"],"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;AACF;","names":[]}
@@ -5,9 +5,11 @@ export type ResourceElement<R, P = any> = {
5
5
  props: P;
6
6
  key?: string | number;
7
7
  };
8
- export type ResourceElementConstructor<R, P> = (props: P, options?: {
8
+ export type ResourceElementConstructor<R, P> = (...args: undefined extends P ? [props?: P, options?: {
9
9
  key?: string | number;
10
- }) => ResourceElement<R, P>;
10
+ }] : [props: P, options?: {
11
+ key?: string | number;
12
+ }]) => ResourceElement<R, P>;
11
13
  export type StateUpdater<S> = S | ((prev: S) => S);
12
14
  export type Destructor = () => void;
13
15
  export type EffectCallback = () => void | Destructor;
@@ -31,14 +33,15 @@ export interface RenderResult {
31
33
  props: any;
32
34
  commitTasks: EffectTask[];
33
35
  }
34
- export interface ResourceFiber {
36
+ export interface ResourceFiber<R, P> {
35
37
  readonly scheduleRerender: () => void;
36
- readonly resourceFn: ResourceFn<any, any>;
38
+ readonly resourceFn: ResourceFn<R, P>;
37
39
  cells: Cell[];
38
40
  currentIndex: number;
39
- commitTasks: EffectTask[];
41
+ renderContext: RenderResult | undefined;
42
+ committedProps: P | undefined;
43
+ isMounted: boolean;
40
44
  isFirstRender: boolean;
41
- committedProps: any;
42
- isRendering: boolean;
45
+ isNeverMounted: boolean;
43
46
  }
44
47
  //# sourceMappingURL=types.d.ts.map
@@ -1 +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,EAA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AG,CAAC;IACX,KAAK,EAAE,GAAG,CAAC;IACX,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa,CAAC,CAAC,EAAE,CAAC;IACjC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,IAAI,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEtC,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IAErB,aAAa,EAAE,YAAY,GAAG,SAAS,CAAC;IACxC,cAAc,EAAE,CAAC,GAAG,SAAS,CAAC;IAE9B,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;CACzB"}
@@ -1 +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":[]}
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":[]}
@@ -1 +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":[]}
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};\n"],"mappings":";AAAA,SAAS,eAAe;AAEjB,IAAM,cAAc,CACzB,IACA,SACM;AACN,SAAO,QAAQ,MAAM,IAAI,IAAI;AAC/B;","names":[]}
@@ -1 +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"}
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;AAgCrD,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"}
@@ -1,30 +1,34 @@
1
1
  // src/hooks/tap-effect.ts
2
2
  import { getCurrentResourceFiber } from "../core/execution-context.js";
3
3
  function getEffectCell() {
4
- const executionContext = getCurrentResourceFiber();
5
- const index = executionContext.currentIndex++;
6
- if (!executionContext.isFirstRender && index >= executionContext.cells.length) {
4
+ const fiber = getCurrentResourceFiber();
5
+ const index = fiber.currentIndex++;
6
+ if (!fiber.isFirstRender && index >= fiber.cells.length) {
7
7
  throw new Error(
8
8
  "Rendered more hooks than during the previous render. Hooks must be called in the exact same order in every render."
9
9
  );
10
10
  }
11
- if (!executionContext.cells[index]) {
11
+ if (!fiber.cells[index]) {
12
12
  const cell2 = {
13
13
  type: "effect",
14
14
  mounted: false
15
15
  };
16
- executionContext.cells[index] = cell2;
16
+ fiber.cells[index] = cell2;
17
17
  }
18
- const cell = executionContext.cells[index];
18
+ const cell = fiber.cells[index];
19
19
  if (cell.type !== "effect") {
20
20
  throw new Error("Hook order changed between renders");
21
21
  }
22
22
  return index;
23
23
  }
24
24
  function tapEffect(effect, deps) {
25
- const executionContext = getCurrentResourceFiber();
25
+ const fiber = getCurrentResourceFiber();
26
26
  const cellIndex = getEffectCell();
27
- executionContext.commitTasks.push({ effect, deps, cellIndex });
27
+ fiber.renderContext.commitTasks.push({
28
+ effect,
29
+ deps,
30
+ cellIndex
31
+ });
28
32
  }
29
33
  export {
30
34
  tapEffect
@@ -1 +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"]}
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 fiber = getCurrentResourceFiber();\n const index = fiber.currentIndex++;\n\n // Check if we're trying to use more hooks than in previous renders\n if (!fiber.isFirstRender && index >= fiber.cells.length) {\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 (!fiber.cells[index]) {\n // Create the effect cell\n const cell: Cell & { type: \"effect\" } = {\n type: \"effect\",\n mounted: false,\n };\n\n fiber.cells[index] = cell;\n }\n\n const cell = fiber.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 fiber = 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 fiber.renderContext!.commitTasks.push({\n effect,\n deps,\n cellIndex,\n });\n}\n"],"mappings":";AAAA,SAAS,+BAA+B;AAGxC,SAAS,gBAAwB;AAC/B,QAAM,QAAQ,wBAAwB;AACtC,QAAM,QAAQ,MAAM;AAGpB,MAAI,CAAC,MAAM,iBAAiB,SAAS,MAAM,MAAM,QAAQ;AACvD,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AAEA,MAAI,CAAC,MAAM,MAAM,KAAK,GAAG;AAEvB,UAAMA,QAAkC;AAAA,MACtC,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAEA,UAAM,MAAM,KAAK,IAAIA;AAAA,EACvB;AAEA,QAAM,OAAO,MAAM,MAAM,KAAK;AAC9B,MAAI,KAAK,SAAS,UAAU;AAC1B,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AAEA,SAAO;AACT;AAOO,SAAS,UACd,QACA,MACM;AACN,QAAM,QAAQ,wBAAwB;AAGtC,QAAM,YAAY,cAAc;AAGhC,QAAM,cAAe,YAAY,KAAK;AAAA,IACpC;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACH;","names":["cell"]}
@@ -0,0 +1,3 @@
1
+ import { ResourceElement } from "../core/types";
2
+ export declare function tapInlineResource<R, P>(element: ResourceElement<R, P>): R;
3
+ //# sourceMappingURL=tap-inline-resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tap-inline-resource.d.ts","sourceRoot":"","sources":["../../src/hooks/tap-inline-resource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAEzE"}
@@ -0,0 +1,8 @@
1
+ // src/hooks/tap-inline-resource.ts
2
+ function tapInlineResource(element) {
3
+ return element.type(element.props);
4
+ }
5
+ export {
6
+ tapInlineResource
7
+ };
8
+ //# sourceMappingURL=tap-inline-resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hooks/tap-inline-resource.ts"],"sourcesContent":["import { ResourceElement } from \"../core/types\";\n\nexport function tapInlineResource<R, P>(element: ResourceElement<R, P>): R {\n return element.type(element.props);\n}\n"],"mappings":";AAEO,SAAS,kBAAwB,SAAmC;AACzE,SAAO,QAAQ,KAAK,QAAQ,KAAK;AACnC;","names":[]}
@@ -1,7 +1,6 @@
1
- interface MutableRefObject<T> {
1
+ export interface RefObject<T> {
2
2
  current: T;
3
3
  }
4
- export declare function tapRef<T>(initialValue: T | (() => T)): MutableRefObject<T>;
5
- export declare function tapRef<T = undefined>(): MutableRefObject<T | undefined>;
6
- export {};
4
+ export declare function tapRef<T>(initialValue: T | (() => T)): RefObject<T>;
5
+ export declare function tapRef<T = undefined>(): RefObject<T | undefined>;
7
6
  //# sourceMappingURL=tap-ref.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"tap-ref.d.ts","sourceRoot":"","sources":["../../src/hooks/tap-ref.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AACrE,wBAAgB,MAAM,CAAC,CAAC,GAAG,SAAS,KAAK,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC"}
@@ -1 +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":[]}
1
+ {"version":3,"sources":["../../src/hooks/tap-ref.ts"],"sourcesContent":["import { tapState } from \"./tap-state\";\n\nexport interface RefObject<T> {\n current: T;\n}\n\nexport function tapRef<T>(initialValue: T | (() => T)): RefObject<T>;\nexport function tapRef<T = undefined>(): RefObject<T | undefined>;\nexport function tapRef<T>(\n initialValue?: T | (() => T),\n): RefObject<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,cAC0B;AAC1B,QAAM,CAAC,KAAK,IAAI,SAAS,OAAO;AAAA,IAC9B,SACE,iBAAiB,UAAa,OAAO,iBAAiB,aACjD,aAAyB,IAC1B;AAAA,EACR,EAAE;AACF,SAAO;AACT;","names":[]}
@@ -1 +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":[]}
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":[]}
@@ -1,5 +1,5 @@
1
1
  import { ResourceElement } from "../core/types";
2
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;
3
+ [K in keyof T]: T[K] extends ResourceElement<infer R, any> ? R : never;
4
4
  };
5
5
  //# sourceMappingURL=tap-resources.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"tap-resources.d.ts","sourceRoot":"","sources":["../../src/hooks/tap-resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAiB,MAAM,eAAe,CAAC;AAW/D,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,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK;CAAE,CAyF5E"}
@@ -1,13 +1,13 @@
1
1
  // src/hooks/tap-resources.ts
2
2
  import { tapEffect } from "./tap-effect.js";
3
- import { tapRef } from "./tap-ref.js";
3
+ import { tapMemo } from "./tap-memo.js";
4
+ import { tapState } from "./tap-state.js";
4
5
  import {
5
6
  createResourceFiber,
6
7
  unmountResource,
7
8
  renderResource,
8
9
  commitResource
9
10
  } from "../core/ResourceFiber.js";
10
- import { tapRerender } from "./tap-rerender.js";
11
11
  function tapResources(elements) {
12
12
  const seenKeys = /* @__PURE__ */ new Set();
13
13
  elements.forEach((element, index) => {
@@ -23,60 +23,56 @@ function tapResources(elements) {
23
23
  }
24
24
  seenKeys.add(element.key);
25
25
  });
26
- const entriesRef = tapRef();
27
- if (!entriesRef.current) {
28
- entriesRef.current = /* @__PURE__ */ new Map();
29
- }
30
- const entries = entriesRef.current;
31
- const rerender = tapRerender();
32
- const currentKeys = /* @__PURE__ */ new Set();
33
- const renderContexts = [];
34
- elements.forEach((element) => {
35
- const key = element.key;
36
- currentKeys.add(key);
37
- let entry = entries.get(key);
38
- if (!entry || entry.type !== element.type) {
39
- if (entry) {
40
- unmountResource(entry.fiber);
26
+ const [stateVersion, rerender] = tapState({});
27
+ const elementsByKey = tapMemo(
28
+ () => new Map(elements.map((element) => [element.key, element])),
29
+ [elements]
30
+ );
31
+ const [fibers] = tapState(
32
+ () => /* @__PURE__ */ new Map()
33
+ );
34
+ const results = tapMemo(() => {
35
+ const resultMap = /* @__PURE__ */ new Map();
36
+ const currentKeys = /* @__PURE__ */ new Set();
37
+ elementsByKey.forEach((element, key) => {
38
+ currentKeys.add(key);
39
+ let fiber = fibers.get(key);
40
+ if (!fiber || fiber.resourceFn !== element.type) {
41
+ if (fiber) unmountResource(fiber);
42
+ fiber = createResourceFiber(element.type, () => rerender({}));
43
+ fibers.set(key, fiber);
41
44
  }
42
- const fiber = createResourceFiber(element.type, rerender);
43
- entry = {
44
- fiber,
45
- type: element.type,
46
- props: element.props,
47
- state: void 0
48
- };
49
- entries.set(key, entry);
50
- }
51
- entry.props = element.props;
52
- const result = renderResource(entry.fiber, element.props);
53
- entry.state = result.state;
54
- renderContexts.push({ entry, result });
55
- });
56
- tapEffect(() => {
57
- renderContexts.forEach(({ entry, result: ctx }) => {
58
- commitResource(entry.fiber, ctx);
45
+ const result = renderResource(fiber, element.props);
46
+ resultMap.set(key, result);
59
47
  });
60
- });
61
- tapEffect(() => {
62
- const keysToRemove = [];
63
- for (const [key, entry] of entries) {
48
+ fibers.forEach((fiber, key) => {
64
49
  if (!currentKeys.has(key)) {
65
- unmountResource(entry.fiber);
66
- keysToRemove.push(key);
50
+ unmountResource(fiber);
51
+ fibers.delete(key);
67
52
  }
68
- }
69
- keysToRemove.forEach((key) => entries.delete(key));
70
- });
53
+ });
54
+ return resultMap;
55
+ }, [elementsByKey, stateVersion]);
56
+ tapEffect(() => {
57
+ results.forEach((result, key) => {
58
+ const fiber = fibers.get(key);
59
+ if (fiber) {
60
+ commitResource(fiber, result);
61
+ }
62
+ });
63
+ }, [results, fibers]);
71
64
  tapEffect(() => {
72
65
  return () => {
73
- entries.forEach((entry) => {
74
- unmountResource(entry.fiber);
66
+ fibers.forEach((fiber) => {
67
+ unmountResource(fiber);
75
68
  });
76
- entries.clear();
69
+ fibers.clear();
77
70
  };
78
- }, []);
79
- return elements.map((element) => entries.get(element.key)?.state);
71
+ }, [fibers]);
72
+ return tapMemo(
73
+ () => elements.map((element) => results.get(element.key)?.state),
74
+ [elements, results]
75
+ );
80
76
  }
81
77
  export {
82
78
  tapResources
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/tap-resources.ts"],"sourcesContent":["import { RenderResult, ResourceElement, ResourceFiber } from \"../core/types\";\nimport { tapEffect } from \"./tap-effect\";\nimport { tapRef } from \"./tap-ref\";\nimport {\n createResourceFiber,\n unmountResource,\n renderResource,\n commitResource,\n} from \"../core/ResourceFiber\";\nimport { tapRerender } from \"./tap-rerender\";\n\ninterface ResourceEntry<R, P> {\n fiber: ResourceFiber;\n type: (props: P) => R;\n props: P;\n state: R;\n}\n\n// TODO make safe for concurrent rendering\nexport function tapResources<\n T extends ReadonlyArray<ResourceElement<any, any>>\n>(\n elements: T\n): { [K in keyof T]: T[K] extends ResourceElement<any, infer R> ? R : never } {\n // Validate that all elements have keys and keys are unique\n const seenKeys = new Set<string | number>();\n elements.forEach((element, index) => {\n if (element.key === undefined) {\n throw new Error(\n `tapResources: All resource elements must have a key. Element at index ${index} is missing a key.`\n );\n }\n if (seenKeys.has(element.key)) {\n throw new Error(\n `tapResources: Duplicate key \"${element.key}\" found. All keys must be unique.`\n );\n }\n seenKeys.add(element.key);\n });\n\n // Use a ref to store resource entries persistently\n const entriesRef = tapRef<Map<string | number, ResourceEntry<any, any>>>();\n if (!entriesRef.current) {\n entriesRef.current = new Map();\n }\n const entries = entriesRef.current;\n\n // State to trigger re-renders when child resources update\n const rerender = tapRerender();\n\n // Process elements and update entries\n const currentKeys = new Set<string | number>();\n const renderContexts: Array<{\n entry: ResourceEntry<any, any>;\n result: RenderResult;\n }> = [];\n\n // First pass: create/update instances and render\n elements.forEach((element) => {\n const key = element.key!;\n currentKeys.add(key);\n\n let entry = entries.get(key);\n\n // Create new fiber if needed or type changed\n if (!entry || entry.type !== element.type) {\n // Clean up old fiber if it exists\n if (entry) {\n unmountResource(entry.fiber);\n }\n\n const fiber = createResourceFiber(element.type, rerender);\n entry = {\n fiber,\n type: element.type,\n props: element.props,\n state: undefined as any,\n };\n entries.set(key, entry);\n }\n\n // Update props if changed\n entry.props = element.props;\n\n // Render with current props\n const result = renderResource(entry.fiber, element.props);\n entry.state = result.state;\n\n renderContexts.push({ entry, result: result });\n });\n\n // No longer need mounting effect since we don't track mount state\n\n // Effect to commit renders\n tapEffect(() => {\n // Commit all renders\n renderContexts.forEach(({ entry, result: ctx }) => {\n commitResource(entry.fiber, ctx);\n });\n });\n\n // Effect to clean up removed resources\n tapEffect(() => {\n // Clean up removed fibers\n const keysToRemove: (string | number)[] = [];\n for (const [key, entry] of entries) {\n if (!currentKeys.has(key)) {\n unmountResource(entry.fiber);\n keysToRemove.push(key);\n }\n }\n keysToRemove.forEach((key) => entries.delete(key));\n });\n\n // Effect for final cleanup when this component unmounts\n tapEffect(() => {\n return () => {\n // Unmount all resources when the parent unmounts\n entries.forEach((entry) => {\n unmountResource(entry.fiber);\n });\n entries.clear();\n };\n }, []);\n\n // Return results in the same order as input elements\n return elements.map((element) => entries.get(element.key!)?.state) as any;\n}\n"],"mappings":";AACA,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAUrB,SAAS,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Ae,MAAM,OAAO,GAAG;AAAA,IACjC,CAAC;AAAA,EACH,CAAC;AAGD,YAAU,MAAM;AAEd,UAAM,eAAoC,CAAC;AAC3C,eAAW,CAAC,KAAK,KAAK,KAAK,SAAS;AAClC,UAAI,CAAC,YAAY,IAAI,GAAG,GAAG;AACzB,wBAAgB,MAAM,KAAK;AAC3B,qBAAa,KAAK,GAAG;AAAA,MACvB;AAAA,IACF;AACA,iBAAa,QAAQ,CAAC,QAAQ,QAAQ,OAAO,GAAG,CAAC;AAAA,EACnD,CAAC;AAGD,YAAU,MAAM;AACd,WAAO,MAAM;AAEX,cAAQ,QAAQ,CAAC,UAAU;AACzB,wBAAgB,MAAM,KAAK;AAAA,MAC7B,CAAC;AACD,cAAQ,MAAM;AAAA,IAChB;AAAA,EACF,GAAG,CAAC,CAAC;AAGL,SAAO,SAAS,IAAI,CAAC,YAAY,QAAQ,IAAI,QAAQ,GAAI,GAAG,KAAK;AACnE;","names":[]}
1
+ {"version":3,"sources":["../../src/hooks/tap-resources.ts"],"sourcesContent":["import { ResourceElement, ResourceFiber } from \"../core/types\";\nimport { tapEffect } from \"./tap-effect\";\nimport { tapMemo } from \"./tap-memo\";\nimport { tapState } from \"./tap-state\";\nimport {\n createResourceFiber,\n unmountResource,\n renderResource,\n commitResource,\n} from \"../core/ResourceFiber\";\n\nexport function tapResources<\n T extends ReadonlyArray<ResourceElement<any, any>>,\n>(\n elements: T,\n): { [K in keyof T]: T[K] extends ResourceElement<infer R, any> ? R : never } {\n // Validate keys\n const seenKeys = new Set<string | number>();\n elements.forEach((element, index) => {\n if (element.key === undefined) {\n throw new Error(\n `tapResources: All resource elements must have a key. Element at index ${index} is missing a key.`,\n );\n }\n if (seenKeys.has(element.key)) {\n throw new Error(\n `tapResources: Duplicate key \"${element.key}\" found. All keys must be unique.`,\n );\n }\n seenKeys.add(element.key);\n });\n\n const [stateVersion, rerender] = tapState({});\n\n // Create a map of current elements by key for efficient lookup\n const elementsByKey = tapMemo(\n () => new Map(elements.map((element) => [element.key!, element])),\n [elements],\n );\n\n // Track fibers persistently across renders\n const [fibers] = tapState(\n () => new Map<string | number, ResourceFiber<any, any>>(),\n );\n\n // Process each element\n const results = tapMemo(() => {\n const resultMap = new Map<string | number, any>();\n const currentKeys = new Set<string | number>();\n\n // Create/update fibers and render\n elementsByKey.forEach((element, key) => {\n currentKeys.add(key);\n\n let fiber = fibers.get(key);\n\n // Create new fiber if needed or type changed\n if (!fiber || fiber.resourceFn !== element.type) {\n if (fiber) unmountResource(fiber);\n fiber = createResourceFiber(element.type, () => rerender({}));\n fibers.set(key, fiber);\n }\n\n // Render with current props\n const result = renderResource(fiber, element.props);\n resultMap.set(key, result);\n });\n\n // Clean up removed fibers\n fibers.forEach((fiber, key) => {\n if (!currentKeys.has(key)) {\n unmountResource(fiber);\n fibers.delete(key);\n }\n });\n\n return resultMap;\n }, [elementsByKey, stateVersion]);\n\n // Commit all renders\n tapEffect(() => {\n results.forEach((result, key) => {\n const fiber = fibers.get(key);\n if (fiber) {\n commitResource(fiber, result);\n }\n });\n }, [results, fibers]);\n\n // Cleanup on unmount\n tapEffect(() => {\n return () => {\n fibers.forEach((fiber) => {\n unmountResource(fiber);\n });\n fibers.clear();\n };\n }, [fibers]);\n\n // Return results in the same order as input elements\n return tapMemo(\n () => elements.map((element) => results.get(element.key!)?.state),\n [elements, results],\n ) as any;\n}\n"],"mappings":";AACA,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,SAAS,aAGd,UAC4E;AAE5E,QAAM,WAAW,oBAAI,IAAqB;AAC1C,WAAS,QAAQ,CAAC,SAAS,UAAU;AACnC,QAAI,QAAQ,QAAQ,QAAW;AAC7B,YAAM,IAAI;AAAA,QACR,yEAAyE,KAAK;AAAA,MAChF;AAAA,IACF;AACA,QAAI,SAAS,IAAI,QAAQ,GAAG,GAAG;AAC7B,YAA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AA,MAC9B;AAAA,IACF,CAAC;AAAA,EACH,GAAG,CAAC,SAAS,MAAM,CAAC;AAGpB,YAAU,MAAM;AACd,WAAO,MAAM;AACX,aAAO,QAAQ,CAAC,UAAU;AACxB,wBAAgB,KAAK;AAAA,MACvB,CAAC;AACD,aAAO,MAAM;AAAA,IACf;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AAGX,SAAO;AAAA,IACL,MAAM,SAAS,IAAI,CAAC,YAAY,QAAQ,IAAI,QAAQ,GAAI,GAAG,KAAK;AAAA,IAChE,CAAC,UAAU,OAAO;AAAA,EACpB;AACF;","names":[]}
@@ -1,4 +1,5 @@
1
- import { StateUpdater } from "../core/types";
1
+ import { StateUpdater, ResourceFiber } from "../core/types";
2
+ export declare const rerender: (fiber: ResourceFiber<any, any>) => void;
2
3
  export declare function tapState<S = undefined>(): [
3
4
  S | undefined,
4
5
  (updater: StateUpdater<S>) => void
@@ -1 +1 @@
1
- {"version":3,"file":"tap-state.d.ts","sourceRoot":"","sources":["../../src/hooks/tap-state.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAQ,MAAM,eAAe,CAAC;AA2DnD,wBAAgB,QAAQ,CAAC,CAAC,GAAG,SAAS,KAAK;IACzC,CAAC,GAAG,SAAS;IACb,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI;CACnC,CAAC;AACF,wBAAgB,QAAQ,CAAC,CAAC,EACxB,OAAO,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GACrB,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC"}
1
+ {"version":3,"file":"tap-state.d.ts","sourceRoot":"","sources":["../../src/hooks/tap-state.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAQ,aAAa,EAAE,MAAM,eAAe,CAAC;AAElE,eAAO,MAAM,QAAQ,GAAI,OAAO,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,SAWtD,CAAC;AAmDF,wBAAgB,QAAQ,CAAC,CAAC,GAAG,SAAS,KAAK;IACzC,CAAC,GAAG,SAAS;IACb,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI;CACnC,CAAC;AACF,wBAAgB,QAAQ,CAAC,CAAC,EACxB,OAAO,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,GACrB,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC"}
@@ -1,14 +1,25 @@
1
1
  // src/hooks/tap-state.ts
2
2
  import { getCurrentResourceFiber } from "../core/execution-context.js";
3
+ var rerender = (fiber) => {
4
+ if (fiber.renderContext) {
5
+ throw new Error("Resource updated during render");
6
+ }
7
+ if (fiber.isNeverMounted) {
8
+ throw new Error("Resource updated before mount");
9
+ }
10
+ if (fiber.isMounted) {
11
+ fiber.scheduleRerender();
12
+ }
13
+ };
3
14
  function getStateCell(initialValue) {
4
- const executionContext = getCurrentResourceFiber();
5
- const index = executionContext.currentIndex++;
6
- if (!executionContext.isFirstRender && index >= executionContext.cells.length) {
15
+ const fiber = getCurrentResourceFiber();
16
+ const index = fiber.currentIndex++;
17
+ if (!fiber.isFirstRender && index >= fiber.cells.length) {
7
18
  throw new Error(
8
19
  "Rendered more hooks than during the previous render. Hooks must be called in the exact same order in every render."
9
20
  );
10
21
  }
11
- if (!executionContext.cells[index]) {
22
+ if (!fiber.cells[index]) {
12
23
  const value = typeof initialValue === "function" ? initialValue() : initialValue;
13
24
  const cell2 = {
14
25
  type: "state",
@@ -18,16 +29,13 @@ function getStateCell(initialValue) {
18
29
  const nextValue = typeof updater === "function" ? updater(currentValue) : updater;
19
30
  if (!Object.is(currentValue, nextValue)) {
20
31
  cell2.value = nextValue;
21
- if (executionContext.isRendering) {
22
- throw new Error("Resource updated during render");
23
- }
24
- executionContext.scheduleRerender();
32
+ rerender(fiber);
25
33
  }
26
34
  }
27
35
  };
28
- executionContext.cells[index] = cell2;
36
+ fiber.cells[index] = cell2;
29
37
  }
30
- const cell = executionContext.cells[index];
38
+ const cell = fiber.cells[index];
31
39
  if (cell.type !== "state") {
32
40
  throw new Error("Hook order changed between renders");
33
41
  }
@@ -38,6 +46,7 @@ function tapState(initial) {
38
46
  return [cell.value, cell.set];
39
47
  }
40
48
  export {
49
+ rerender,
41
50
  tapState
42
51
  };
43
52
  //# sourceMappingURL=tap-state.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/tap-state.ts"],"sourcesContent":["import { getCurrentResourceFiber } from \"../core/execution-context\";\nimport { StateUpdater, Cell } from \"../core/types\";\n\nfunction getStateCell<T>(\n initialValue: T | (() => T)\n): Cell & { type: \"state\" } {\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 // Initialize the value immediately\n const value =\n typeof initialValue === \"function\"\n ? (initialValue as () => T)()\n : initialValue;\n\n const cell: Cell & { type: \"state\" } = {\n type: \"state\",\n value,\n set: (updater: StateUpdater<T>) => {\n const currentValue = cell.value;\n const nextValue =\n typeof updater === \"function\"\n ? (updater as (prev: T) => T)(currentValue)\n : updater;\n\n if (!Object.is(currentValue, nextValue)) {\n cell.value = nextValue;\n\n // Check if called during render (not allowed)\n if (executionContext.isRendering) {\n throw new Error(\"Resource updated during render\");\n }\n executionContext.scheduleRerender();\n }\n },\n };\n\n executionContext.cells[index] = cell;\n }\n\n const cell = executionContext.cells[index];\n if (cell.type !== \"state\") {\n throw new Error(\"Hook order changed between renders\");\n }\n\n return cell as Cell & { type: \"state\" };\n}\n\nexport function tapState<S = undefined>(): [\n S | undefined,\n (updater: StateUpdater<S>) => void\n];\nexport function tapState<S>(\n initial: S | (() => S)\n): [S, (updater: StateUpdater<S>) => void];\nexport function tapState<S>(\n initial?: S | (() => S)\n): [S | undefined, (updater: StateUpdater<S>) => void] {\n const cell = getStateCell(initial as S | (() => S));\n\n return [cell.value, cell.set];\n}\n"],"mappings":";AAAA,SAAS,+BAA+B;AAGxC,SAAS,aACP,cAC0B;AAC1B,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,UAAM,QACJ,OAAO,iBAAiB,aACnB,aAAyB,IAC1B;AAEN,UAAMA,QAAiC;AAAA,MACrC,MAAM;AAAA,MACN;AAAA,MACA,KAAK,CAAC,YAA6B;AACjC,cAAM,eAAeA,MAAK;AAC1B,cAAM,YACJ,OAAO,YAAY,aACd,QAA2B,YAAY,IACxC;AAEN,YAAI,CAAC,OAAO,GAAG,cAAc,SAAS,GAAG;AACvC,UAAAA,MAAK,QAAQ;AAGb,cAAI,iBAAiB,aAAa;AAChC,kBAAM,IAAI,MAAM,gCAAgC;AAAA,UAClD;AACA,2BAAiB,iBAAiB;AAAA,QACpC;AAAA,MACF;AAAA,IACF;AAEA,qBAAiB,MAAM,KAAK,IAAIA;AAAA,EAClC;AAEA,QAAM,OAAO,iBAAiB,MAAM,KAAK;AACzC,MAAI,KAAK,SAAS,SAAS;AACzB,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AAEA,SAAO;AACT;AASO,SAAS,SACd,SACqD;AACrD,QAAM,OAAO,aAAa,OAAwB;AAElD,SAAO,CAAC,KAAK,OAAO,KAAK,GAAG;AAC9B;","names":["cell"]}
1
+ {"version":3,"sources":["../../src/hooks/tap-state.ts"],"sourcesContent":["import { getCurrentResourceFiber } from \"../core/execution-context\";\nimport { StateUpdater, Cell, ResourceFiber } from \"../core/types\";\n\nexport const rerender = (fiber: ResourceFiber<any, any>) => {\n if (fiber.renderContext) {\n throw new Error(\"Resource updated during render\");\n }\n if (fiber.isNeverMounted) {\n throw new Error(\"Resource updated before mount\");\n }\n // Only schedule rerender if currently mounted\n if (fiber.isMounted) {\n fiber.scheduleRerender();\n }\n};\n\nfunction getStateCell<T>(\n initialValue: T | (() => T),\n): Cell & { type: \"state\" } {\n const fiber = getCurrentResourceFiber();\n const index = fiber.currentIndex++;\n\n // Check if we're trying to use more hooks than in previous renders\n if (!fiber.isFirstRender && index >= fiber.cells.length) {\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 (!fiber.cells[index]) {\n // Initialize the value immediately\n const value =\n typeof initialValue === \"function\"\n ? (initialValue as () => T)()\n : initialValue;\n\n const cell: Cell & { type: \"state\" } = {\n type: \"state\",\n value,\n set: (updater: StateUpdater<T>) => {\n const currentValue = cell.value;\n const nextValue =\n typeof updater === \"function\"\n ? (updater as (prev: T) => T)(currentValue)\n : updater;\n\n if (!Object.is(currentValue, nextValue)) {\n cell.value = nextValue;\n rerender(fiber);\n }\n },\n };\n\n fiber.cells[index] = cell;\n }\n\n const cell = fiber.cells[index];\n if (cell.type !== \"state\") {\n throw new Error(\"Hook order changed between renders\");\n }\n\n return cell as Cell & { type: \"state\" };\n}\n\nexport function tapState<S = undefined>(): [\n S | undefined,\n (updater: StateUpdater<S>) => void,\n];\nexport function tapState<S>(\n initial: S | (() => S),\n): [S, (updater: StateUpdater<S>) => void];\nexport function tapState<S>(\n initial?: S | (() => S),\n): [S | undefined, (updater: StateUpdater<S>) => void] {\n const cell = getStateCell(initial as S | (() => S));\n\n return [cell.value, cell.set];\n}\n"],"mappings":";AAAA,SAAS,+BAA+B;AAGjC,IAAM,WAAW,CAAC,UAAmC;AAC1D,MAAI,MAAM,eAAe;AACvB,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AACA,MAAI,MAAM,gBAAgB;AACxB,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACjD;AAEA,MAAI,MAAM,WAAW;AACnB,UAAM,iBAAiB;AAAA,EACzB;AACF;AAEA,SAAS,aACP,cAC0B;AAC1B,QAAM,QAAQ,wBAAwB;AACtC,QAAM,QAAQ,MAAM;AAGpB,MAAI,CAAC,MAAM,iBAAiB,SAAS,MAAM,MAAM,QAAQ;AACvD,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AAEA,MAAI,CAAC,MAAM,MAAM,KAAK,GAAG;AAEvB,UAAM,QACJ,OAAO,iBAAiB,aACnB,aAAyB,IAC1B;AAEN,UAAMA,QAAiC;AAAA,MACrC,MAAM;AAAA,MACN;AAAA,MACA,KAAK,CAAC,YAA6B;AACjC,cAAM,eAAeA,MAAK;AAC1B,cAAM,YACJ,OAAO,YAAY,aACd,QAA2B,YAAY,IACxC;AAEN,YAAI,CAAC,OAAO,GAAG,cAAc,SAAS,GAAG;AACvC,UAAAA,MAAK,QAAQ;AACb,mBAAS,KAAK;AAAA,QAChB;AAAA,MACF;AAAA,IACF;AAEA,UAAM,MAAM,KAAK,IAAIA;AAAA,EACvB;AAEA,QAAM,OAAO,MAAM,MAAM,KAAK;AAC9B,MAAI,KAAK,SAAS,SAAS;AACzB,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AAEA,SAAO;AACT;AASO,SAAS,SACd,SACqD;AACrD,QAAM,OAAO,aAAa,OAAwB;AAElD,SAAO,CAAC,KAAK,OAAO,KAAK,GAAG;AAC9B;","names":["cell"]}
package/dist/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  export { resource } from "./core/resource";
2
2
  export { tapState } from "./hooks/tap-state";
3
3
  export { tapEffect } from "./hooks/tap-effect";
4
- export { tapRef } from "./hooks/tap-ref";
4
+ export { tapRef, type RefObject } from "./hooks/tap-ref";
5
5
  export { tapMemo } from "./hooks/tap-memo";
6
6
  export { tapCallback } from "./hooks/tap-callback";
7
7
  export { tapResource } from "./hooks/tap-resource";
8
+ export { tapInlineResource } from "./hooks/tap-inline-resource";
9
+ export { tapResources } from "./hooks/tap-resources";
8
10
  export { createResource, type ResourceHandle } from "./core/ResourceHandle";
9
11
  export type { ResourceFn, ResourceElement, ResourceElementConstructor, Unsubscribe, StateUpdater, EffectCallback, Destructor, } from "./core/types";
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAInD,OAAO,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5E,YAAY,EACV,UAAU,EACV,eAAe,EACf,0BAA0B,EAC1B,WAAW,EACX,YAAY,EACZ,cAAc,EACd,UAAU,GACX,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGrD,OAAO,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5E,YAAY,EACV,UAAU,EACV,eAAe,EACf,0BAA0B,EAC1B,WAAW,EACX,YAAY,EACZ,cAAc,EACd,UAAU,GACX,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -6,15 +6,19 @@ import { tapRef } from "./hooks/tap-ref.js";
6
6
  import { tapMemo } from "./hooks/tap-memo.js";
7
7
  import { tapCallback } from "./hooks/tap-callback.js";
8
8
  import { tapResource } from "./hooks/tap-resource.js";
9
+ import { tapInlineResource } from "./hooks/tap-inline-resource.js";
10
+ import { tapResources } from "./hooks/tap-resources.js";
9
11
  import { createResource } from "./core/ResourceHandle.js";
10
12
  export {
11
13
  createResource,
12
14
  resource,
13
15
  tapCallback,
14
16
  tapEffect,
17
+ tapInlineResource,
15
18
  tapMemo,
16
19
  tapRef,
17
20
  tapResource,
21
+ tapResources,
18
22
  tapState
19
23
  };
20
24
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { resource } from \"./core/resource\";\n\n// primitive hooks\nexport { tapState } from \"./hooks/tap-state\";\nexport { tapEffect } from \"./hooks/tap-effect\";\n\n// utility hooks\nexport { tapRef } from \"./hooks/tap-ref\";\nexport { tapMemo } from \"./hooks/tap-memo\";\nexport { tapCallback } from \"./hooks/tap-callback\";\n\n// resources\nexport { tapResource } from \"./hooks/tap-resource\";\n// export { tapResources } from \"./hooks/tap-resources\";\n\n// imperative\nexport { createResource, type ResourceHandle } from \"./core/ResourceHandle\";\n\nexport type {\n ResourceFn,\n ResourceElement,\n ResourceElementConstructor,\n Unsubscribe,\n StateUpdater,\n EffectCallback,\n Destructor,\n} from \"./core/types\";\n"],"mappings":";AAAA,SAAS,gBAAgB;AAGzB,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAG1B,SAAS,cAAc;AACvB,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAG5B,SAAS,mBAAmB;AAI5B,SAAS,sBAA2C;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { resource } from \"./core/resource\";\n\n// primitive hooks\nexport { tapState } from \"./hooks/tap-state\";\nexport { tapEffect } from \"./hooks/tap-effect\";\n\n// utility hooks\nexport { tapRef, type RefObject } from \"./hooks/tap-ref\";\nexport { tapMemo } from \"./hooks/tap-memo\";\nexport { tapCallback } from \"./hooks/tap-callback\";\n\n// resources\nexport { tapResource } from \"./hooks/tap-resource\";\nexport { tapInlineResource } from \"./hooks/tap-inline-resource\";\nexport { tapResources } from \"./hooks/tap-resources\";\n\n// imperative\nexport { createResource, type ResourceHandle } from \"./core/ResourceHandle\";\n\nexport type {\n ResourceFn,\n ResourceElement,\n ResourceElementConstructor,\n Unsubscribe,\n StateUpdater,\n EffectCallback,\n Destructor,\n} from \"./core/types\";\n"],"mappings":";AAAA,SAAS,gBAAgB;AAGzB,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAG1B,SAAS,cAA8B;AACvC,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAG5B,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,oBAAoB;AAG7B,SAAS,sBAA2C;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/react/index.ts"],"sourcesContent":["export { useResource } from \"./use-resource\";"],"mappings":";AAAA,SAAS,mBAAmB;","names":[]}
1
+ {"version":3,"sources":["../../src/react/index.ts"],"sourcesContent":["export { useResource } from \"./use-resource\";\n"],"mappings":";AAAA,SAAS,mBAAmB;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"use-resource.d.ts","sourceRoot":"","sources":["../../src/react/use-resource.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAkBhD,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAgBnE"}
1
+ {"version":3,"file":"use-resource.d.ts","sourceRoot":"","sources":["../../src/react/use-resource.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAehD,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAgBnE"}
@@ -6,9 +6,8 @@ import {
6
6
  renderResource,
7
7
  commitResource
8
8
  } from "../core/ResourceFiber.js";
9
- var shouldUseIsomorphicLayoutEffect = globalThis.__ASSISTANT_UI_USE_ISOMORPHIC_LAYOUT_EFFECT__ === true;
10
- var isSSR = typeof window === "undefined" || /ServerSideRendering/.test(window.navigator && window.navigator.userAgent);
11
- var useIsomorphicLayoutEffect = shouldUseIsomorphicLayoutEffect && isSSR ? useEffect : useLayoutEffect;
9
+ var shouldAvoidLayoutEffect = globalThis.__ASSISTANT_UI_DISABLE_LAYOUT_EFFECT__ === true;
10
+ var useIsomorphicLayoutEffect = shouldAvoidLayoutEffect ? useEffect : useLayoutEffect;
12
11
  function useResource(element) {
13
12
  const [, rerender] = useState({});
14
13
  const fiber = useMemo(
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/react/use-resource.ts"],"sourcesContent":["import { useEffect, useLayoutEffect, useMemo, useState } from \"react\";\nimport { ResourceElement } from \"../core/types\";\nimport {\n createResourceFiber,\n unmountResource,\n renderResource,\n commitResource,\n} from \"../core/ResourceFiber\";\n\nconst shouldUseIsomorphicLayoutEffect =\n (globalThis as any).__ASSISTANT_UI_USE_ISOMORPHIC_LAYOUT_EFFECT__ === true;\n\nconst isSSR =\n typeof window === \"undefined\" ||\n /ServerSideRendering/.test(window.navigator && window.navigator.userAgent);\n\nconst useIsomorphicLayoutEffect =\n shouldUseIsomorphicLayoutEffect && isSSR ? useEffect : useLayoutEffect;\n\nexport function useResource<R, P>(element: ResourceElement<R, P>): R {\n const [, rerender] = useState({});\n const fiber = useMemo(\n () => createResourceFiber(element.type, () => rerender({})),\n [element.type]\n );\n\n const result = renderResource(fiber, element.props);\n useIsomorphicLayoutEffect(() => {\n return () => unmountResource(fiber);\n }, []);\n useIsomorphicLayoutEffect(() => {\n commitResource(fiber, result);\n });\n\n return result.state;\n}\n"],"mappings":";AAAA,SAAS,WAAW,iBAAiB,SAAS,gBAAgB;AAE9D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,IAAM,kCACH,WAAmB,kDAAkD;AAExE,IAAM,QACJ,OAAO,WAAW,eAClB,sBAAsB,KAAK,OAAO,aAAa,OAAO,UAAU,SAAS;AAE3E,IAAM,4BACJ,mCAAmC,QAAQ,YAAY;AAElD,SAAS,YAAkB,SAAmC;AACnE,QAAM,CAAC,EAAE,QAAQ,IAAI,SAAS,CAAC,CAAC;AAChC,QAAM,QAAQ;AAAA,IACZ,MAAM,oBAAoB,QAAQ,MAAM,MAAM,SAAS,CAAC,CAAC,CAAC;AAAA,IAC1D,CAAC,QAAQ,IAAI;AAAA,EACf;AAEA,QAAM,SAAS,eAAe,OAAO,QAAQ,KAAK;AAClD,4BAA0B,MAAM;AAC9B,WAAO,MAAM,gBAAgB,KAAK;AAAA,EACpC,GAAG,CAAC,CAAC;AACL,4BAA0B,MAAM;AAC9B,mBAAe,OAAO,MAAM;AAAA,EAC9B,CAAC;AAED,SAAO,OAAO;AAChB;","names":[]}
1
+ {"version":3,"sources":["../../src/react/use-resource.ts"],"sourcesContent":["import { useEffect, useLayoutEffect, useMemo, useState } from \"react\";\nimport { ResourceElement } from \"../core/types\";\nimport {\n createResourceFiber,\n unmountResource,\n renderResource,\n commitResource,\n} from \"../core/ResourceFiber\";\n\nconst shouldAvoidLayoutEffect =\n (globalThis as any).__ASSISTANT_UI_DISABLE_LAYOUT_EFFECT__ === true;\n\nconst useIsomorphicLayoutEffect = shouldAvoidLayoutEffect\n ? useEffect\n : useLayoutEffect;\n\nexport function useResource<R, P>(element: ResourceElement<R, P>): R {\n const [, rerender] = useState({});\n const fiber = useMemo(\n () => createResourceFiber(element.type, () => rerender({})),\n [element.type],\n );\n\n const result = renderResource(fiber, element.props);\n useIsomorphicLayoutEffect(() => {\n return () => unmountResource(fiber);\n }, []);\n useIsomorphicLayoutEffect(() => {\n commitResource(fiber, result);\n });\n\n return result.state;\n}\n"],"mappings":";AAAA,SAAS,WAAW,iBAAiB,SAAS,gBAAgB;AAE9D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,IAAM,0BACH,WAAmB,2CAA2C;AAEjE,IAAM,4BAA4B,0BAC9B,YACA;AAEG,SAAS,YAAkB,SAAmC;AACnE,QAAM,CAAC,EAAE,QAAQ,IAAI,SAAS,CAAC,CAAC;AAChC,QAAM,QAAQ;AAAA,IACZ,MAAM,oBAAoB,QAAQ,MAAM,MAAM,SAAS,CAAC,CAAC,CAAC;AAAA,IAC1D,CAAC,QAAQ,IAAI;AAAA,EACf;AAEA,QAAM,SAAS,eAAe,OAAO,QAAQ,KAAK;AAClD,4BAA0B,MAAM;AAC9B,WAAO,MAAM,gBAAgB,KAAK;AAAA,EACpC,GAAG,CAAC,CAAC;AACL,4BAA0B,MAAM;AAC9B,mBAAe,OAAO,MAAM;AAAA,EAC9B,CAAC;AAED,SAAO,OAAO;AAChB;","names":[]}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@assistant-ui/tap",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "type": "module",
5
5
  "description": "Zero-dependency reactive state management inspired by React hooks",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
+ "sideEffects": false,
8
9
  "author": "AgentbaseAI Inc.",
9
10
  "license": "MIT",
10
11
  "dependencies": {},
@@ -1,2 +0,0 @@
1
- export declare const tapRerender: () => () => void;
2
- //# sourceMappingURL=tap-rerender.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tap-rerender.d.ts","sourceRoot":"","sources":["../../src/hooks/tap-rerender.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,kBAGvB,CAAC"}
@@ -1,10 +0,0 @@
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
@@ -1 +0,0 @@
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":[]}