@assistant-ui/tap 0.5.11 → 0.5.12

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 (115) hide show
  1. package/README.md +21 -364
  2. package/dist/core/ResourceFiber.d.ts +9 -5
  3. package/dist/core/ResourceFiber.d.ts.map +1 -1
  4. package/dist/core/ResourceFiber.js +47 -45
  5. package/dist/core/ResourceFiber.js.map +1 -1
  6. package/dist/core/context.d.ts +7 -5
  7. package/dist/core/context.d.ts.map +1 -1
  8. package/dist/core/context.js +16 -15
  9. package/dist/core/context.js.map +1 -1
  10. package/dist/core/createResourceRoot.d.ts +8 -4
  11. package/dist/core/createResourceRoot.d.ts.map +1 -1
  12. package/dist/core/createResourceRoot.js +25 -26
  13. package/dist/core/createResourceRoot.js.map +1 -1
  14. package/dist/core/helpers/callResourceFn.d.ts +1 -2
  15. package/dist/core/helpers/callResourceFn.js +15 -13
  16. package/dist/core/helpers/callResourceFn.js.map +1 -1
  17. package/dist/core/helpers/commit.d.ts +7 -3
  18. package/dist/core/helpers/commit.d.ts.map +1 -1
  19. package/dist/core/helpers/commit.js +33 -50
  20. package/dist/core/helpers/commit.js.map +1 -1
  21. package/dist/core/helpers/env.d.ts +4 -1
  22. package/dist/core/helpers/env.d.ts.map +1 -1
  23. package/dist/core/helpers/env.js +5 -2
  24. package/dist/core/helpers/env.js.map +1 -1
  25. package/dist/core/helpers/execution-context.d.ts +8 -4
  26. package/dist/core/helpers/execution-context.d.ts.map +1 -1
  27. package/dist/core/helpers/execution-context.js +22 -27
  28. package/dist/core/helpers/execution-context.js.map +1 -1
  29. package/dist/core/helpers/root.d.ts +10 -6
  30. package/dist/core/helpers/root.d.ts.map +1 -1
  31. package/dist/core/helpers/root.js +45 -48
  32. package/dist/core/helpers/root.js.map +1 -1
  33. package/dist/core/resource.d.ts +8 -4
  34. package/dist/core/resource.d.ts.map +1 -1
  35. package/dist/core/resource.js +13 -9
  36. package/dist/core/resource.js.map +1 -1
  37. package/dist/core/scheduler.d.ts +11 -9
  38. package/dist/core/scheduler.d.ts.map +1 -1
  39. package/dist/core/scheduler.js +70 -83
  40. package/dist/core/scheduler.js.map +1 -1
  41. package/dist/core/types.d.ts +56 -55
  42. package/dist/core/types.d.ts.map +1 -1
  43. package/dist/core/types.js +0 -2
  44. package/dist/core/withKey.d.ts +6 -2
  45. package/dist/core/withKey.d.ts.map +1 -1
  46. package/dist/core/withKey.js +9 -2
  47. package/dist/core/withKey.js.map +1 -1
  48. package/dist/hooks/tap-callback.d.ts +4 -1
  49. package/dist/hooks/tap-callback.d.ts.map +1 -1
  50. package/dist/hooks/tap-callback.js +6 -3
  51. package/dist/hooks/tap-callback.js.map +1 -1
  52. package/dist/hooks/tap-const.d.ts +4 -1
  53. package/dist/hooks/tap-const.d.ts.map +1 -1
  54. package/dist/hooks/tap-const.js +7 -3
  55. package/dist/hooks/tap-const.js.map +1 -1
  56. package/dist/hooks/tap-effect-event.d.ts +4 -1
  57. package/dist/hooks/tap-effect-event.d.ts.map +1 -1
  58. package/dist/hooks/tap-effect-event.js +31 -29
  59. package/dist/hooks/tap-effect-event.js.map +1 -1
  60. package/dist/hooks/tap-effect.d.ts +8 -5
  61. package/dist/hooks/tap-effect.d.ts.map +1 -1
  62. package/dist/hooks/tap-effect.js +35 -45
  63. package/dist/hooks/tap-effect.js.map +1 -1
  64. package/dist/hooks/tap-memo.d.ts +4 -1
  65. package/dist/hooks/tap-memo.d.ts.map +1 -1
  66. package/dist/hooks/tap-memo.js +17 -13
  67. package/dist/hooks/tap-memo.js.map +1 -1
  68. package/dist/hooks/tap-reducer.d.ts +7 -5
  69. package/dist/hooks/tap-reducer.d.ts.map +1 -1
  70. package/dist/hooks/tap-reducer.js +70 -76
  71. package/dist/hooks/tap-reducer.js.map +1 -1
  72. package/dist/hooks/tap-ref.d.ts +9 -6
  73. package/dist/hooks/tap-ref.d.ts.map +1 -1
  74. package/dist/hooks/tap-ref.js +7 -5
  75. package/dist/hooks/tap-ref.js.map +1 -1
  76. package/dist/hooks/tap-resource.d.ts +7 -3
  77. package/dist/hooks/tap-resource.d.ts.map +1 -1
  78. package/dist/hooks/tap-resource.js +31 -22
  79. package/dist/hooks/tap-resource.js.map +1 -1
  80. package/dist/hooks/tap-resources.d.ts +6 -2
  81. package/dist/hooks/tap-resources.d.ts.map +1 -1
  82. package/dist/hooks/tap-resources.js +74 -96
  83. package/dist/hooks/tap-resources.js.map +1 -1
  84. package/dist/hooks/tap-state.d.ts +7 -7
  85. package/dist/hooks/tap-state.d.ts.map +1 -1
  86. package/dist/hooks/tap-state.js +7 -5
  87. package/dist/hooks/tap-state.js.map +1 -1
  88. package/dist/hooks/utils/depsShallowEqual.d.ts +4 -1
  89. package/dist/hooks/utils/depsShallowEqual.d.ts.map +1 -1
  90. package/dist/hooks/utils/depsShallowEqual.js +8 -8
  91. package/dist/hooks/utils/depsShallowEqual.js.map +1 -1
  92. package/dist/hooks/utils/tapHook.d.ts +8 -4
  93. package/dist/hooks/utils/tapHook.d.ts.map +1 -1
  94. package/dist/hooks/utils/tapHook.js +17 -20
  95. package/dist/hooks/utils/tapHook.js.map +1 -1
  96. package/dist/index.d.ts +18 -18
  97. package/dist/index.js +17 -23
  98. package/dist/react/index.d.ts +2 -2
  99. package/dist/react/index.js +2 -2
  100. package/dist/react/use-resource.d.ts +6 -2
  101. package/dist/react/use-resource.d.ts.map +1 -1
  102. package/dist/react/use-resource.js +41 -36
  103. package/dist/react/use-resource.js.map +1 -1
  104. package/dist/tapResourceRoot.d.ts +18 -14
  105. package/dist/tapResourceRoot.d.ts.map +1 -1
  106. package/dist/tapResourceRoot.js +68 -77
  107. package/dist/tapResourceRoot.js.map +1 -1
  108. package/package.json +8 -8
  109. package/src/core/types.ts +1 -2
  110. package/dist/core/helpers/callResourceFn.d.ts.map +0 -1
  111. package/dist/core/types.js.map +0 -1
  112. package/dist/index.d.ts.map +0 -1
  113. package/dist/index.js.map +0 -1
  114. package/dist/react/index.d.ts.map +0 -1
  115. package/dist/react/index.js.map +0 -1
@@ -1,94 +1,81 @@
1
+ //#region src/core/scheduler.ts
1
2
  const MAX_FLUSH_LIMIT = 50;
2
3
  let flushState = {
3
- schedulers: new Set([]),
4
- isScheduled: false,
4
+ schedulers: /* @__PURE__ */ new Set([]),
5
+ isScheduled: false
6
+ };
7
+ var UpdateScheduler = class {
8
+ _task;
9
+ _isDirty = false;
10
+ constructor(_task) {
11
+ this._task = _task;
12
+ }
13
+ get isDirty() {
14
+ return this._isDirty;
15
+ }
16
+ markDirty() {
17
+ this._isDirty = true;
18
+ flushState.schedulers.add(this);
19
+ scheduleFlush();
20
+ }
21
+ runTask() {
22
+ this._isDirty = false;
23
+ this._task();
24
+ }
5
25
  };
6
- export class UpdateScheduler {
7
- _task;
8
- _isDirty = false;
9
- constructor(_task) {
10
- this._task = _task;
11
- }
12
- get isDirty() {
13
- return this._isDirty;
14
- }
15
- markDirty() {
16
- this._isDirty = true;
17
- flushState.schedulers.add(this);
18
- scheduleFlush();
19
- }
20
- runTask() {
21
- this._isDirty = false;
22
- this._task();
23
- }
24
- }
25
26
  const scheduleFlush = () => {
26
- if (flushState.isScheduled)
27
- return;
28
- flushState.isScheduled = true;
29
- scheduleMacrotask();
27
+ if (flushState.isScheduled) return;
28
+ flushState.isScheduled = true;
29
+ scheduleMacrotask();
30
30
  };
31
31
  const flushScheduled = () => {
32
- try {
33
- const errors = [];
34
- let flushDepth = 0;
35
- for (const scheduler of flushState.schedulers) {
36
- flushState.schedulers.delete(scheduler);
37
- if (!scheduler.isDirty)
38
- continue;
39
- flushDepth++;
40
- if (flushDepth > MAX_FLUSH_LIMIT) {
41
- throw new Error(`Maximum update depth exceeded. This can happen when a resource ` +
42
- `repeatedly calls setState inside tapEffect.`);
43
- }
44
- try {
45
- scheduler.runTask();
46
- }
47
- catch (error) {
48
- errors.push(error);
49
- }
50
- }
51
- if (errors.length > 0) {
52
- if (errors.length === 1) {
53
- throw errors[0];
54
- }
55
- else {
56
- for (const error of errors) {
57
- console.error(error);
58
- }
59
- throw new AggregateError(errors, "Errors occurred during flushSync");
60
- }
61
- }
62
- }
63
- finally {
64
- flushState.schedulers.clear();
65
- flushState.isScheduled = false;
66
- }
32
+ try {
33
+ const errors = [];
34
+ let flushDepth = 0;
35
+ for (const scheduler of flushState.schedulers) {
36
+ flushState.schedulers.delete(scheduler);
37
+ if (!scheduler.isDirty) continue;
38
+ flushDepth++;
39
+ if (flushDepth > MAX_FLUSH_LIMIT) throw new Error("Maximum update depth exceeded. This can happen when a resource repeatedly calls setState inside tapEffect.");
40
+ try {
41
+ scheduler.runTask();
42
+ } catch (error) {
43
+ errors.push(error);
44
+ }
45
+ }
46
+ if (errors.length > 0) if (errors.length === 1) throw errors[0];
47
+ else {
48
+ for (const error of errors) console.error(error);
49
+ throw new AggregateError(errors, "Errors occurred during flushSync");
50
+ }
51
+ } finally {
52
+ flushState.schedulers.clear();
53
+ flushState.isScheduled = false;
54
+ }
67
55
  };
68
- // Use MessageChannel to schedule flushes as macrotasks (like React's scheduler).
69
- // This allows more state updates to batch into a single re-render.
70
56
  const scheduleMacrotask = (() => {
71
- if (typeof MessageChannel !== "undefined") {
72
- const channel = new MessageChannel();
73
- channel.port1.onmessage = flushScheduled;
74
- return () => channel.port2.postMessage(null);
75
- }
76
- // Fallback for environments without MessageChannel
77
- return () => setTimeout(flushScheduled, 0);
57
+ if (typeof MessageChannel !== "undefined") {
58
+ const channel = new MessageChannel();
59
+ channel.port1.onmessage = flushScheduled;
60
+ return () => channel.port2.postMessage(null);
61
+ }
62
+ return () => setTimeout(flushScheduled, 0);
78
63
  })();
79
- export const flushResourcesSync = (callback) => {
80
- const prev = flushState;
81
- flushState = {
82
- schedulers: new Set([]),
83
- isScheduled: true,
84
- };
85
- try {
86
- const result = callback();
87
- flushScheduled();
88
- return result;
89
- }
90
- finally {
91
- flushState = prev;
92
- }
64
+ const flushResourcesSync = (callback) => {
65
+ const prev = flushState;
66
+ flushState = {
67
+ schedulers: /* @__PURE__ */ new Set([]),
68
+ isScheduled: true
69
+ };
70
+ try {
71
+ const result = callback();
72
+ flushScheduled();
73
+ return result;
74
+ } finally {
75
+ flushState = prev;
76
+ }
93
77
  };
78
+ //#endregion
79
+ export { UpdateScheduler, flushResourcesSync };
80
+
94
81
  //# sourceMappingURL=scheduler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../src/core/scheduler.ts"],"names":[],"mappings":"AAOA,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,IAAI,UAAU,GAAqB;IACjC,UAAU,EAAE,IAAI,GAAG,CAAC,EAAE,CAAC;IACvB,WAAW,EAAE,KAAK;CACnB,CAAC;AAEF,MAAM,OAAO,eAAe;IAGG;IAFrB,QAAQ,GAAG,KAAK,CAAC;IAEzB,YAA6B,KAAW;QAAX,UAAK,GAAL,KAAK,CAAM;IAAG,CAAC;IAE5C,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,SAAS;QACP,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QAErB,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChC,aAAa,EAAE,CAAC;IAClB,CAAC;IAED,OAAO;QACL,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;CACF;AAED,MAAM,aAAa,GAAG,GAAG,EAAE;IACzB,IAAI,UAAU,CAAC,WAAW;QAAE,OAAO;IACnC,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC;IAC9B,iBAAiB,EAAE,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,GAAG,EAAE;IAC1B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,EAAE,CAAC;QAClB,IAAI,UAAU,GAAG,CAAC,CAAC;QAEnB,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;YA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I,CAAC,CAAC;IAC/C,CAAC;IACD,mDAAmD;IACnD,OAAO,GAAG,EAAE,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC;AAC7C,CAAC,CAAC,EAAE,CAAC;AAEL,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAI,QAAiB,EAAK,EAAE;IAC5D,MAAM,IAAI,GAAG,UAAU,CAAC;IACxB,UAAU,GAAG;QACX,UAAU,EAAE,IAAI,GAAG,CAAC,EAAE,CAAC;QACvB,WAAW,EAAE,IAAI;KAClB,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,QAAQ,EAAE,CAAC;QAC1B,cAAc,EAAE,CAAC;QAEjB,OAAO,MAAM,CAAC;IAChB,CAAC;YAAS,CAAC;QACT,UAAU,GAAG,IAAI,CAAC;IACpB,CAAC;AACH,CAAC,CAAC"}
1
+ {"version":3,"file":"scheduler.js","names":[],"sources":["../../src/core/scheduler.ts"],"sourcesContent":["type Task = () => void;\n\ntype GlobalFlushState = {\n schedulers: Set<UpdateScheduler>;\n isScheduled: boolean;\n};\n\nconst MAX_FLUSH_LIMIT = 50;\nlet flushState: GlobalFlushState = {\n schedulers: new Set([]),\n isScheduled: false,\n};\n\nexport class UpdateScheduler {\n private _isDirty = false;\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 flushState.schedulers.add(this);\n scheduleFlush();\n }\n\n runTask() {\n this._isDirty = false;\n this._task();\n }\n}\n\nconst scheduleFlush = () => {\n if (flushState.isScheduled) return;\n flushState.isScheduled = true;\n scheduleMacrotask();\n};\n\nconst flushScheduled = () => {\n try {\n const errors = [];\n let flushDepth = 0;\n\n for (const scheduler of flushState.schedulers) {\n flushState.schedulers.delete(scheduler);\n if (!scheduler.isDirty) continue;\n\n flushDepth++;\n\n if (flushDepth > MAX_FLUSH_LIMIT) {\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 try {\n scheduler.runTask();\n } catch (error) {\n errors.push(error);\n }\n }\n\n if (errors.length > 0) {\n if (errors.length === 1) {\n throw errors[0];\n } else {\n for (const error of errors) {\n console.error(error);\n }\n throw new AggregateError(errors, \"Errors occurred during flushSync\");\n }\n }\n } finally {\n flushState.schedulers.clear();\n flushState.isScheduled = false;\n }\n};\n\n// Use MessageChannel to schedule flushes as macrotasks (like React's scheduler).\n// This allows more state updates to batch into a single re-render.\nconst scheduleMacrotask = (() => {\n if (typeof MessageChannel !== \"undefined\") {\n const channel = new MessageChannel();\n channel.port1.onmessage = flushScheduled;\n return () => channel.port2.postMessage(null);\n }\n // Fallback for environments without MessageChannel\n return () => setTimeout(flushScheduled, 0);\n})();\n\nexport const flushResourcesSync = <T>(callback: () => T): T => {\n const prev = flushState;\n flushState = {\n schedulers: new Set([]),\n isScheduled: true,\n };\n\n try {\n const result = callback();\n flushScheduled();\n\n return result;\n } finally {\n flushState = prev;\n }\n};\n"],"mappings":";AAOA,MAAM,kBAAkB;AACxB,IAAI,aAA+B;CACjC,4BAAY,IAAI,IAAI,CAAC,CAAC;CACtB,aAAa;AACf;AAEA,IAAa,kBAAb,MAA6B;CAGE;CAF7B,WAAmB;CAEnB,YAAY,OAA8B;EAAb,KAAA,QAAA;CAAc;CAE3C,IAAI,UAAU;EACZ,OAAO,KAAK;CACd;CAEA,YAAY;EACV,KAAK,WAAW;EAEhB,WAAW,WAAW,IAAI,IAAI;EAC9B,cAAc;CAChB;CAEA,UAAU;EACR,KAAK,WAAW;EAChB,KAAK,MAAM;CACb;AACF;AAEA,MAAM,sBAAsB;CAC1B,IAAI,WAAW,aAAa;CAC5B,WAAW,cAAc;CACzB,kBAAkB;AACpB;AAEA,MAAM,uBAAuB;CAC3B,IAAI;EACF,MAAM,SAAS,CAAC;EAChB,IAAI,aAAa;EAEjB,KAAK,MAAM,aAAa,WAAW,YAAY;GAC7C,WAAW,WAAW,OAAO,SAAS;GACtC,IAAI,CAAC,UAAU,SAAS;GAExB;GAEA,IAAI,aAAa,iBACf,MAAM,IAAI,MACR,4GAEF;GAGF,IAAI;IACF,UAAU,QAAQ;GACpB,SAAS,OAAO;IACd,OAAO,KAAK,KAAK;GACnB;EACF;EAEA,IAAI,OAAO,SAAS,GAClB,IAAI,OAAO,WAAW,GACpB,MAAM,OAAO;OACR;GACL,KAAK,MAAM,SAAS,QAClB,QAAQ,MAAM,KAAK;GAErB,MAAM,IAAI,eAAe,QAAQ,kCAAkC;EACrE;CAEJ,UAAU;EACR,WAAW,WAAW,MAAM;EAC5B,WAAW,cAAc;CAC3B;AACF;AAIA,MAAM,2BAA2B;CAC/B,IAAI,OAAO,mBAAmB,aAAa;EACzC,MAAM,UAAU,IAAI,eAAe;EACnC,QAAQ,MAAM,YAAY;EAC1B,aAAa,QAAQ,MAAM,YAAY,IAAI;CAC7C;CAEA,aAAa,WAAW,gBAAgB,CAAC;AAC3C,GAAG;AAEH,MAAa,sBAAyB,aAAyB;CAC7D,MAAM,OAAO;CACb,aAAa;EACX,4BAAY,IAAI,IAAI,CAAC,CAAC;EACtB,aAAa;CACf;CAEA,IAAI;EACF,MAAM,SAAS,SAAS;EACxB,eAAe;EAEf,OAAO;CACT,UAAU;EACR,aAAa;CACf;AACF"}
@@ -1,64 +1,65 @@
1
- import type { tapEffect } from "../hooks/tap-effect.js";
2
- import type { fnSymbol } from "./helpers/callResourceFn.js";
3
- export type ResourceElement<R, P = any> = {
4
- readonly type: Resource<R, P> & {
5
- [fnSymbol]: (props: P) => R;
6
- };
7
- readonly props: P;
8
- readonly key?: string | number;
1
+ import { tapEffect } from "../hooks/tap-effect.js";
2
+
3
+ //#region src/core/types.d.ts
4
+ type ResourceElement<R, P = any> = {
5
+ readonly type: Resource<R, P>;
6
+ readonly props: P;
7
+ readonly key?: string | number;
9
8
  };
10
- export type Resource<R, P> = (props: P) => ResourceElement<R, P>;
11
- export type ContravariantResource<R, P> = (props: P) => ResourceElement<R>;
12
- export type ExtractResourceReturnType<T> = T extends ResourceElement<infer R, any> ? R : T extends Resource<infer R, any> ? R : never;
13
- export interface ReducerQueueEntry {
14
- readonly action: any;
15
- hasEagerState: boolean;
16
- eagerState: any;
9
+ type Resource<R, P> = (props: P) => ResourceElement<R, P>;
10
+ type ContravariantResource<R, P> = (props: P) => ResourceElement<R>;
11
+ type ExtractResourceReturnType<T> = T extends ResourceElement<infer R, any> ? R : T extends Resource<infer R, any> ? R : never;
12
+ interface ReducerQueueEntry {
13
+ readonly action: any;
14
+ hasEagerState: boolean;
15
+ eagerState: any;
17
16
  }
18
- export type Cell = {
19
- readonly type: "reducer";
20
- readonly dispatch: (action: any) => void;
21
- readonly queue: Set<ReducerQueueEntry>;
22
- dirty: boolean;
23
- workInProgress: any;
24
- current: any;
25
- reducer: (state: any, action: any) => any;
17
+ type Cell = {
18
+ readonly type: "reducer";
19
+ readonly dispatch: (action: any) => void;
20
+ readonly queue: Set<ReducerQueueEntry>;
21
+ dirty: boolean;
22
+ workInProgress: any;
23
+ current: any;
24
+ reducer: (state: any, action: any) => any;
26
25
  } | {
27
- readonly type: "effect";
28
- cleanup: tapEffect.Destructor | undefined;
29
- deps: readonly unknown[] | null | undefined;
26
+ readonly type: "effect";
27
+ cleanup: tapEffect.Destructor | undefined;
28
+ deps: readonly unknown[] | null | undefined;
30
29
  };
31
- export interface EffectTask {
32
- readonly effect: tapEffect.EffectCallback;
33
- readonly deps: readonly unknown[] | undefined;
34
- readonly cell: Cell & {
35
- type: "effect";
36
- };
30
+ interface EffectTask {
31
+ readonly effect: tapEffect.EffectCallback;
32
+ readonly deps: readonly unknown[] | undefined;
33
+ readonly cell: Cell & {
34
+ type: "effect";
35
+ };
37
36
  }
38
- export interface RenderResult {
39
- readonly output: any;
40
- readonly props: any;
41
- readonly effectTasks: (() => void)[];
37
+ interface RenderResult {
38
+ readonly output: any;
39
+ readonly props: any;
40
+ readonly effectTasks: (() => void)[];
42
41
  }
43
- export interface ResourceFiberRoot {
44
- version: number;
45
- committedVersion: number;
46
- readonly changelog: (() => void)[];
47
- readonly dispatchUpdate: (callback: () => boolean) => void;
48
- readonly dirtyCells: (Cell & {
49
- type: "reducer";
50
- })[];
42
+ interface ResourceFiberRoot {
43
+ version: number;
44
+ committedVersion: number;
45
+ readonly changelog: (() => void)[];
46
+ readonly dispatchUpdate: (callback: () => boolean) => void;
47
+ readonly dirtyCells: (Cell & {
48
+ type: "reducer";
49
+ })[];
51
50
  }
52
- export interface ResourceFiber<R, P> {
53
- readonly root: ResourceFiberRoot;
54
- readonly type: Resource<R, P>;
55
- readonly markDirty: (() => void) | undefined;
56
- readonly devStrictMode: "root" | "child" | null;
57
- cells: Cell[];
58
- currentIndex: number;
59
- renderContext: RenderResult | undefined;
60
- isMounted: boolean;
61
- isFirstRender: boolean;
62
- isNeverMounted: boolean;
51
+ interface ResourceFiber<R, P> {
52
+ readonly root: ResourceFiberRoot;
53
+ readonly type: Resource<R, P>;
54
+ readonly markDirty: (() => void) | undefined;
55
+ readonly devStrictMode: "root" | "child" | null;
56
+ cells: Cell[];
57
+ currentIndex: number;
58
+ renderContext: RenderResult | undefined;
59
+ isMounted: boolean;
60
+ isFirstRender: boolean;
61
+ isNeverMounted: boolean;
63
62
  }
63
+ //#endregion
64
+ export { Cell, ContravariantResource, EffectTask, ExtractResourceReturnType, ReducerQueueEntry, RenderResult, Resource, ResourceElement, ResourceFiber, ResourceFiberRoot };
64
65
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,+BAA4B;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,oCAAiC;AAEzD,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,IAAI;IACxC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG;QAA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GAAa,IAAI;IAAK,IAAA;EAAA;AAAA;AAAA,UAGhB,aAAA;EAAA,SACN,IAAA,EAAM,iBAAA;EAAA,SACN,IAAA,EAAM,QAAA,CAAS,CAAA,EAAG,CAAA;EAAA,SAClB,SAAA;EAAA,SACA,aAAA;EAET,KAAA,EAAO,IAAA;EACP,YAAA;EAEA,aAAA,EAAe,YAAA;EAEf,SAAA;EACA,aAAA;EACA,cAAA;AAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1,3 +1,7 @@
1
- import type { ResourceElement } from "./types.js";
2
- export declare function withKey<E extends ResourceElement<any, any>>(key: string | number, element: E): E;
1
+ import { ResourceElement } from "./types.js";
2
+
3
+ //#region src/core/withKey.d.ts
4
+ declare function withKey<E extends ResourceElement<any, any>>(key: string | number, element: E): E;
5
+ //#endregion
6
+ export { withKey };
3
7
  //# sourceMappingURL=withKey.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"withKey.d.ts","sourceRoot":"","sources":["../../src/core/withKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAgB;AAE/C,wBAAgB,OAAO,CAAC,CAAC,SAAS,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,EACzD,GAAG,EAAE,MAAM,GAAG,MAAM,EACpB,OAAO,EAAE,CAAC,GACT,CAAC,CAEH"}
1
+ {"version":3,"file":"withKey.d.ts","names":[],"sources":["../../src/core/withKey.ts"],"mappings":";;;iBAEgB,OAAA,WAAkB,eAAA,WAAA,CAChC,GAAA,mBACA,OAAA,EAAS,CAAA,GACR,CAAA"}
@@ -1,4 +1,11 @@
1
- export function withKey(key, element) {
2
- return { ...element, key };
1
+ //#region src/core/withKey.ts
2
+ function withKey(key, element) {
3
+ return {
4
+ ...element,
5
+ key
6
+ };
3
7
  }
8
+ //#endregion
9
+ export { withKey };
10
+
4
11
  //# sourceMappingURL=withKey.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"withKey.js","sourceRoot":"","sources":["../../src/core/withKey.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,OAAO,CACrB,GAAoB,EACpB,OAAU;IAEV,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,CAAC;AAC7B,CAAC"}
1
+ {"version":3,"file":"withKey.js","names":[],"sources":["../../src/core/withKey.ts"],"sourcesContent":["import type { ResourceElement } from \"./types\";\n\nexport function withKey<E extends ResourceElement<any, any>>(\n key: string | number,\n element: E,\n): E {\n return { ...element, key };\n}\n"],"mappings":";AAEA,SAAgB,QACd,KACA,SACG;CACH,OAAO;EAAE,GAAG;EAAS;CAAI;AAC3B"}
@@ -1,2 +1,5 @@
1
- export declare const tapCallback: <T extends (...args: any[]) => any>(fn: T, deps: readonly unknown[]) => T;
1
+ //#region src/hooks/tap-callback.d.ts
2
+ declare const tapCallback: <T extends (...args: any[]) => any>(fn: T, deps: readonly unknown[]) => T;
3
+ //#endregion
4
+ export { tapCallback };
2
5
  //# sourceMappingURL=tap-callback.d.ts.map
@@ -1 +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,CAGF,CAAC"}
1
+ {"version":3,"file":"tap-callback.d.ts","names":[],"sources":["../../src/hooks/tap-callback.ts"],"mappings":";cAEa,WAAA,iBAA6B,IAAA,iBACxC,EAAA,EAAI,CAAA,EACJ,IAAA,yBACC,CAGF"}
@@ -1,6 +1,9 @@
1
1
  import { tapMemo } from "./tap-memo.js";
2
- export const tapCallback = (fn, deps) => {
3
- // biome-ignore lint/correctness/useExhaustiveDependencies: user provided deps instead of callback identity
4
- return tapMemo(() => fn, deps);
2
+ //#region src/hooks/tap-callback.ts
3
+ const tapCallback = (fn, deps) => {
4
+ return tapMemo(() => fn, deps);
5
5
  };
6
+ //#endregion
7
+ export { tapCallback };
8
+
6
9
  //# sourceMappingURL=tap-callback.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tap-callback.js","sourceRoot":"","sources":["../../src/hooks/tap-callback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,sBAAmB;AAErC,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,EAAK,EACL,IAAwB,EACrB,EAAE;IACL,2GAA2G;IAC3G,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC,CAAC"}
1
+ {"version":3,"file":"tap-callback.js","names":[],"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 // biome-ignore lint/correctness/useExhaustiveDependencies: user provided deps instead of callback identity\n return tapMemo(() => fn, deps);\n};\n"],"mappings":";;AAEA,MAAa,eACX,IACA,SACM;CAEN,OAAO,cAAc,IAAI,IAAI;AAC/B"}
@@ -1,2 +1,5 @@
1
- export declare function tapConst<T>(getValue: () => T, _deps: readonly never[]): T;
1
+ //#region src/hooks/tap-const.d.ts
2
+ declare function tapConst<T>(getValue: () => T, _deps: readonly never[]): T;
3
+ //#endregion
4
+ export { tapConst };
2
5
  //# sourceMappingURL=tap-const.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tap-const.d.ts","sourceRoot":"","sources":["../../src/hooks/tap-const.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,SAAS,KAAK,EAAE,GAAG,CAAC,CAGzE"}
1
+ {"version":3,"file":"tap-const.d.ts","names":[],"sources":["../../src/hooks/tap-const.ts"],"mappings":";iBAEgB,QAAA,GAAA,CAAY,QAAA,QAAgB,CAAA,EAAG,KAAA,qBAA0B,CAAC"}
@@ -1,6 +1,10 @@
1
1
  import { tapState } from "./tap-state.js";
2
- export function tapConst(getValue, _deps) {
3
- const [state] = tapState(getValue);
4
- return state;
2
+ //#region src/hooks/tap-const.ts
3
+ function tapConst(getValue, _deps) {
4
+ const [state] = tapState(getValue);
5
+ return state;
5
6
  }
7
+ //#endregion
8
+ export { tapConst };
9
+
6
10
  //# sourceMappingURL=tap-const.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tap-const.js","sourceRoot":"","sources":["../../src/hooks/tap-const.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,uBAAoB;AAEvC,MAAM,UAAU,QAAQ,CAAI,QAAiB,EAAE,KAAuB;IACpE,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACnC,OAAO,KAAK,CAAC;AACf,CAAC"}
1
+ {"version":3,"file":"tap-const.js","names":[],"sources":["../../src/hooks/tap-const.ts"],"sourcesContent":["import { tapState } from \"./tap-state\";\n\nexport function tapConst<T>(getValue: () => T, _deps: readonly never[]): T {\n const [state] = tapState(getValue);\n return state;\n}\n"],"mappings":";;AAEA,SAAgB,SAAY,UAAmB,OAA4B;CACzE,MAAM,CAAC,SAAS,SAAS,QAAQ;CACjC,OAAO;AACT"}
@@ -1,3 +1,4 @@
1
+ //#region src/hooks/tap-effect-event.d.ts
1
2
  /**
2
3
  * Creates a stable function reference that always calls the most recent version of the callback.
3
4
  * Similar to React's useEffectEvent hook.
@@ -13,5 +14,7 @@
13
14
  * // handleClick reference is stable, but always calls the latest version
14
15
  * ```
15
16
  */
16
- export declare function tapEffectEvent<T extends (...args: any[]) => any>(callback: T): T;
17
+ declare function tapEffectEvent<T extends (...args: any[]) => any>(callback: T): T;
18
+ //#endregion
19
+ export { tapEffectEvent };
17
20
  //# sourceMappingURL=tap-effect-event.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tap-effect-event.d.ts","sourceRoot":"","sources":["../../src/hooks/tap-effect-event.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAC9D,QAAQ,EAAE,CAAC,GACV,CAAC,CAiBH"}
1
+ {"version":3,"file":"tap-effect-event.d.ts","names":[],"sources":["../../src/hooks/tap-effect-event.ts"],"mappings":";;AAqBA;;;;;;;;;;AAEI;;;;iBAFY,cAAA,eAA6B,IAAA,gBAAA,CAC3C,QAAA,EAAU,CAAA,GACT,CAAC"}
@@ -1,34 +1,36 @@
1
- import { tapRef } from "./tap-ref.js";
2
- import { tapEffect } from "./tap-effect.js";
3
1
  import { isDevelopment } from "../core/helpers/env.js";
4
- import { tapCallback } from "./tap-callback.js";
5
2
  import { getCurrentResourceFiber } from "../core/helpers/execution-context.js";
3
+ import { tapEffect } from "./tap-effect.js";
4
+ import { tapRef } from "./tap-ref.js";
5
+ import { tapCallback } from "./tap-callback.js";
6
+ //#region src/hooks/tap-effect-event.ts
6
7
  /**
7
- * Creates a stable function reference that always calls the most recent version of the callback.
8
- * Similar to React's useEffectEvent hook.
9
- *
10
- * @param callback - The callback function to wrap
11
- * @returns A stable function reference that always calls the latest callback
12
- *
13
- * @example
14
- * ```typescript
15
- * const handleClick = tapEffectEvent((value: string) => {
16
- * console.log(value);
17
- * });
18
- * // handleClick reference is stable, but always calls the latest version
19
- * ```
20
- */
21
- export function tapEffectEvent(callback) {
22
- const callbackRef = tapRef(callback);
23
- // TODO this effect needs to run before all userland effects
24
- tapEffect(() => {
25
- callbackRef.current = callback;
26
- });
27
- const fiber = getCurrentResourceFiber();
28
- return tapCallback(((...args) => {
29
- if (isDevelopment && fiber.renderContext)
30
- throw new Error("tapEffectEvent cannot be called during render");
31
- return callbackRef.current(...args);
32
- }), [fiber]);
8
+ * Creates a stable function reference that always calls the most recent version of the callback.
9
+ * Similar to React's useEffectEvent hook.
10
+ *
11
+ * @param callback - The callback function to wrap
12
+ * @returns A stable function reference that always calls the latest callback
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const handleClick = tapEffectEvent((value: string) => {
17
+ * console.log(value);
18
+ * });
19
+ * // handleClick reference is stable, but always calls the latest version
20
+ * ```
21
+ */
22
+ function tapEffectEvent(callback) {
23
+ const callbackRef = tapRef(callback);
24
+ tapEffect(() => {
25
+ callbackRef.current = callback;
26
+ });
27
+ const fiber = getCurrentResourceFiber();
28
+ return tapCallback(((...args) => {
29
+ if (isDevelopment && fiber.renderContext) throw new Error("tapEffectEvent cannot be called during render");
30
+ return callbackRef.current(...args);
31
+ }), [fiber]);
33
32
  }
33
+ //#endregion
34
+ export { tapEffectEvent };
35
+
34
36
  //# sourceMappingURL=tap-effect-event.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tap-effect-event.js","sourceRoot":"","sources":["../../src/hooks/tap-effect-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,qBAAkB;AACnC,OAAO,EAAE,SAAS,EAAE,wBAAqB;AACzC,OAAO,EAAE,aAAa,EAAE,+BAA4B;AACpD,OAAO,EAAE,WAAW,EAAE,0BAAuB;AAC7C,OAAO,EAAE,uBAAuB,EAAE,6CAA0C;AAE5E;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAC5B,QAAW;IAEX,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAErC,4DAA4D;IAC5D,SAAS,CAAC,GAAG,EAAE;QACb,WAAW,CAAC,OAAO,GAAG,QAAQ,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,uBAAuB,EAAE,CAAC;IACxC,OAAO,WAAW,CAChB,CAAC,CAAC,GAAG,IAAmB,EAAE,EAAE;QAC1B,IAAI,aAAa,IAAI,KAAK,CAAC,aAAa;YACtC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACnE,OAAO,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;IACtC,CAAC,CAAM,EACP,CAAC,KAAK,CAAC,CACR,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"tap-effect-event.js","names":[],"sources":["../../src/hooks/tap-effect-event.ts"],"sourcesContent":["import { tapRef } from \"./tap-ref\";\nimport { tapEffect } from \"./tap-effect\";\nimport { isDevelopment } from \"../core/helpers/env\";\nimport { tapCallback } from \"./tap-callback\";\nimport { getCurrentResourceFiber } from \"../core/helpers/execution-context\";\n\n/**\n * Creates a stable function reference that always calls the most recent version of the callback.\n * Similar to React's useEffectEvent hook.\n *\n * @param callback - The callback function to wrap\n * @returns A stable function reference that always calls the latest callback\n *\n * @example\n * ```typescript\n * const handleClick = tapEffectEvent((value: string) => {\n * console.log(value);\n * });\n * // handleClick reference is stable, but always calls the latest version\n * ```\n */\nexport function tapEffectEvent<T extends (...args: any[]) => any>(\n callback: T,\n): T {\n const callbackRef = tapRef(callback);\n\n // TODO this effect needs to run before all userland effects\n tapEffect(() => {\n callbackRef.current = callback;\n });\n\n const fiber = getCurrentResourceFiber();\n return tapCallback(\n ((...args: Parameters<T>) => {\n if (isDevelopment && fiber.renderContext)\n throw new Error(\"tapEffectEvent cannot be called during render\");\n return callbackRef.current(...args);\n }) as T,\n [fiber],\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,eACd,UACG;CACH,MAAM,cAAc,OAAO,QAAQ;CAGnC,gBAAgB;EACd,YAAY,UAAU;CACxB,CAAC;CAED,MAAM,QAAQ,wBAAwB;CACtC,OAAO,cACH,GAAG,SAAwB;EAC3B,IAAI,iBAAiB,MAAM,eACzB,MAAM,IAAI,MAAM,+CAA+C;EACjE,OAAO,YAAY,QAAQ,GAAG,IAAI;CACpC,IACA,CAAC,KAAK,CACR;AACF"}
@@ -1,7 +1,10 @@
1
- export declare namespace tapEffect {
2
- type Destructor = () => void;
3
- type EffectCallback = () => Destructor | undefined;
1
+ //#region src/hooks/tap-effect.d.ts
2
+ declare namespace tapEffect {
3
+ type Destructor = () => void;
4
+ type EffectCallback = () => Destructor | undefined;
4
5
  }
5
- export declare function tapEffect(effect: tapEffect.EffectCallback): void;
6
- export declare function tapEffect(effect: tapEffect.EffectCallback, deps: readonly unknown[]): void;
6
+ declare function tapEffect(effect: tapEffect.EffectCallback): void;
7
+ declare function tapEffect(effect: tapEffect.EffectCallback, deps: readonly unknown[]): void;
8
+ //#endregion
9
+ export { tapEffect };
7
10
  //# sourceMappingURL=tap-effect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tap-effect.d.ts","sourceRoot":"","sources":["../../src/hooks/tap-effect.ts"],"names":[],"mappings":"AAUA,yBAAiB,SAAS,CAAC;IACzB,KAAY,UAAU,GAAG,MAAM,IAAI,CAAC;IACpC,KAAY,cAAc,GAAG,MAAM,UAAU,GAAG,SAAS,CAAC;CAC3D;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC;AAClE,wBAAgB,SAAS,CACvB,MAAM,EAAE,SAAS,CAAC,cAAc,EAChC,IAAI,EAAE,SAAS,OAAO,EAAE,GACvB,IAAI,CAAC"}
1
+ {"version":3,"file":"tap-effect.d.ts","names":[],"sources":["../../src/hooks/tap-effect.ts"],"mappings":";kBAUiB,SAAA;EAAA,KACH,UAAA;EAAA,KACA,cAAA,SAAuB,UAAU;AAAA;AAAA,iBAG/B,SAAA,CAAU,MAAA,EAAQ,SAAA,CAAU,cAAc;AAAA,iBAC1C,SAAA,CACd,MAAA,EAAQ,SAAA,CAAU,cAAc,EAChC,IAAA"}