@assistant-ui/tap 0.5.10 → 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.
- package/README.md +21 -364
- package/dist/core/ResourceFiber.d.ts +9 -5
- package/dist/core/ResourceFiber.d.ts.map +1 -1
- package/dist/core/ResourceFiber.js +47 -45
- package/dist/core/ResourceFiber.js.map +1 -1
- package/dist/core/context.d.ts +7 -5
- package/dist/core/context.d.ts.map +1 -1
- package/dist/core/context.js +16 -15
- package/dist/core/context.js.map +1 -1
- package/dist/core/createResourceRoot.d.ts +8 -4
- package/dist/core/createResourceRoot.d.ts.map +1 -1
- package/dist/core/createResourceRoot.js +25 -26
- package/dist/core/createResourceRoot.js.map +1 -1
- package/dist/core/helpers/callResourceFn.d.ts +1 -2
- package/dist/core/helpers/callResourceFn.js +15 -13
- package/dist/core/helpers/callResourceFn.js.map +1 -1
- package/dist/core/helpers/commit.d.ts +7 -3
- package/dist/core/helpers/commit.d.ts.map +1 -1
- package/dist/core/helpers/commit.js +33 -50
- package/dist/core/helpers/commit.js.map +1 -1
- package/dist/core/helpers/env.d.ts +4 -1
- package/dist/core/helpers/env.d.ts.map +1 -1
- package/dist/core/helpers/env.js +5 -2
- package/dist/core/helpers/env.js.map +1 -1
- package/dist/core/helpers/execution-context.d.ts +8 -4
- package/dist/core/helpers/execution-context.d.ts.map +1 -1
- package/dist/core/helpers/execution-context.js +22 -27
- package/dist/core/helpers/execution-context.js.map +1 -1
- package/dist/core/helpers/root.d.ts +10 -6
- package/dist/core/helpers/root.d.ts.map +1 -1
- package/dist/core/helpers/root.js +45 -48
- package/dist/core/helpers/root.js.map +1 -1
- package/dist/core/resource.d.ts +8 -4
- package/dist/core/resource.d.ts.map +1 -1
- package/dist/core/resource.js +13 -9
- package/dist/core/resource.js.map +1 -1
- package/dist/core/scheduler.d.ts +11 -9
- package/dist/core/scheduler.d.ts.map +1 -1
- package/dist/core/scheduler.js +70 -83
- package/dist/core/scheduler.js.map +1 -1
- package/dist/core/types.d.ts +56 -55
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js +0 -2
- package/dist/core/withKey.d.ts +6 -2
- package/dist/core/withKey.d.ts.map +1 -1
- package/dist/core/withKey.js +9 -2
- package/dist/core/withKey.js.map +1 -1
- package/dist/hooks/tap-callback.d.ts +4 -1
- package/dist/hooks/tap-callback.d.ts.map +1 -1
- package/dist/hooks/tap-callback.js +6 -3
- package/dist/hooks/tap-callback.js.map +1 -1
- package/dist/hooks/tap-const.d.ts +4 -1
- package/dist/hooks/tap-const.d.ts.map +1 -1
- package/dist/hooks/tap-const.js +7 -3
- package/dist/hooks/tap-const.js.map +1 -1
- package/dist/hooks/tap-effect-event.d.ts +4 -1
- package/dist/hooks/tap-effect-event.d.ts.map +1 -1
- package/dist/hooks/tap-effect-event.js +31 -29
- package/dist/hooks/tap-effect-event.js.map +1 -1
- package/dist/hooks/tap-effect.d.ts +8 -5
- package/dist/hooks/tap-effect.d.ts.map +1 -1
- package/dist/hooks/tap-effect.js +35 -45
- package/dist/hooks/tap-effect.js.map +1 -1
- package/dist/hooks/tap-memo.d.ts +4 -1
- package/dist/hooks/tap-memo.d.ts.map +1 -1
- package/dist/hooks/tap-memo.js +17 -13
- package/dist/hooks/tap-memo.js.map +1 -1
- package/dist/hooks/tap-reducer.d.ts +7 -5
- package/dist/hooks/tap-reducer.d.ts.map +1 -1
- package/dist/hooks/tap-reducer.js +70 -76
- package/dist/hooks/tap-reducer.js.map +1 -1
- package/dist/hooks/tap-ref.d.ts +9 -6
- package/dist/hooks/tap-ref.d.ts.map +1 -1
- package/dist/hooks/tap-ref.js +7 -5
- package/dist/hooks/tap-ref.js.map +1 -1
- package/dist/hooks/tap-resource.d.ts +7 -3
- package/dist/hooks/tap-resource.d.ts.map +1 -1
- package/dist/hooks/tap-resource.js +31 -22
- package/dist/hooks/tap-resource.js.map +1 -1
- package/dist/hooks/tap-resources.d.ts +6 -2
- package/dist/hooks/tap-resources.d.ts.map +1 -1
- package/dist/hooks/tap-resources.js +74 -96
- package/dist/hooks/tap-resources.js.map +1 -1
- package/dist/hooks/tap-state.d.ts +7 -7
- package/dist/hooks/tap-state.d.ts.map +1 -1
- package/dist/hooks/tap-state.js +7 -5
- package/dist/hooks/tap-state.js.map +1 -1
- package/dist/hooks/utils/depsShallowEqual.d.ts +4 -1
- package/dist/hooks/utils/depsShallowEqual.d.ts.map +1 -1
- package/dist/hooks/utils/depsShallowEqual.js +8 -8
- package/dist/hooks/utils/depsShallowEqual.js.map +1 -1
- package/dist/hooks/utils/tapHook.d.ts +8 -4
- package/dist/hooks/utils/tapHook.d.ts.map +1 -1
- package/dist/hooks/utils/tapHook.js +17 -20
- package/dist/hooks/utils/tapHook.js.map +1 -1
- package/dist/index.d.ts +18 -18
- package/dist/index.js +17 -23
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +2 -2
- package/dist/react/use-resource.d.ts +6 -2
- package/dist/react/use-resource.d.ts.map +1 -1
- package/dist/react/use-resource.js +41 -36
- package/dist/react/use-resource.js.map +1 -1
- package/dist/tapResourceRoot.d.ts +18 -14
- package/dist/tapResourceRoot.d.ts.map +1 -1
- package/dist/tapResourceRoot.js +68 -77
- package/dist/tapResourceRoot.js.map +1 -1
- package/package.json +9 -9
- package/src/core/types.ts +1 -2
- package/dist/core/helpers/callResourceFn.d.ts.map +0 -1
- package/dist/core/types.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react/index.js.map +0 -1
package/dist/core/scheduler.js
CHANGED
|
@@ -1,94 +1,81 @@
|
|
|
1
|
+
//#region src/core/scheduler.ts
|
|
1
2
|
const MAX_FLUSH_LIMIT = 50;
|
|
2
3
|
let flushState = {
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
scheduleMacrotask();
|
|
27
|
+
if (flushState.isScheduled) return;
|
|
28
|
+
flushState.isScheduled = true;
|
|
29
|
+
scheduleMacrotask();
|
|
30
30
|
};
|
|
31
31
|
const flushScheduled = () => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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","
|
|
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"}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -1,64 +1,65 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
readonly type: "effect";
|
|
27
|
+
cleanup: tapEffect.Destructor | undefined;
|
|
28
|
+
deps: readonly unknown[] | null | undefined;
|
|
30
29
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
interface RenderResult {
|
|
38
|
+
readonly output: any;
|
|
39
|
+
readonly props: any;
|
|
40
|
+
readonly effectTasks: (() => void)[];
|
|
42
41
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
package/dist/core/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/core/types.ts"],"mappings":";;;KAEY,eAAA;EAAA,SACD,IAAA,EAAM,QAAA,CAAS,CAAA,EAAG,CAAA;EAAA,SAClB,KAAA,EAAO,CAAA;EAAA,SACP,GAAA;AAAA;AAAA,KAGC,QAAA,UAAkB,KAAA,EAAO,CAAA,KAAM,eAAA,CAAgB,CAAA,EAAG,CAAA;AAAA,KAClD,qBAAA,UAA+B,KAAA,EAAO,CAAA,KAAM,eAAA,CAAgB,CAAA;AAAA,KAE5D,yBAAA,MACV,CAAA,SAAU,eAAA,iBACN,CAAA,GACA,CAAA,SAAU,QAAA,iBACR,CAAA;AAAA,UAGS,iBAAA;EAAA,SACN,MAAA;EACT,aAAA;EACA,UAAA;AAAA;AAAA,KAGU,IAAA;EAAA,SAEG,IAAA;EAAA,SACA,QAAA,GAAW,MAAA;EAAA,SAEX,KAAA,EAAO,GAAA,CAAI,iBAAA;EACpB,KAAA;EACA,cAAA;EACA,OAAA;EACA,OAAA,GAAU,KAAA,OAAY,MAAA;AAAA;EAAA,SAGb,IAAA;EACT,OAAA,EAAS,SAAA,CAAU,UAAA;EACnB,IAAA;AAAA;AAAA,UAGW,UAAA;EAAA,SACN,MAAA,EAAQ,SAAA,CAAU,cAAA;EAAA,SAClB,IAAA;EAAA,SACA,IAAA,EAAM,IAAI;IAAK,IAAA;EAAA;AAAA;AAAA,UAGT,YAAA;EAAA,SACN,MAAA;EAAA,SACA,KAAA;EAAA,SACA,WAAA;AAAA;AAAA,UAGM,iBAAA;EACf,OAAA;EACA,gBAAA;EAAA,SACS,SAAA;EAAA,SAEA,cAAA,GAAiB,QAAA;EAAA,SACjB,UAAA,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"}
|
package/dist/core/types.js
CHANGED
package/dist/core/withKey.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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","
|
|
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"}
|
package/dist/core/withKey.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
package/dist/core/withKey.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withKey.js","
|
|
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
|
-
|
|
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","
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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","
|
|
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
|
-
|
|
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","
|
|
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"}
|
package/dist/hooks/tap-const.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { tapState } from "./tap-state.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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","
|
|
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
|
-
|
|
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","
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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","
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region src/hooks/tap-effect.d.ts
|
|
2
|
+
declare namespace tapEffect {
|
|
3
|
+
type Destructor = () => void;
|
|
4
|
+
type EffectCallback = () => Destructor | undefined;
|
|
4
5
|
}
|
|
5
|
-
|
|
6
|
-
|
|
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","
|
|
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"}
|