@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
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
import { createResourceFiber, unmountResourceFiber, renderResourceFiber, commitResourceFiber, } from "./ResourceFiber.js";
|
|
2
|
-
import { tapResourceRoot } from "../tapResourceRoot.js";
|
|
3
1
|
import { resource } from "./resource.js";
|
|
4
2
|
import { isDevelopment } from "./helpers/env.js";
|
|
5
|
-
import { flushResourcesSync, UpdateScheduler } from "./scheduler.js";
|
|
6
3
|
import { createResourceFiberRoot } from "./helpers/root.js";
|
|
4
|
+
import { commitResourceFiber, createResourceFiber, renderResourceFiber, unmountResourceFiber } from "./ResourceFiber.js";
|
|
5
|
+
import { UpdateScheduler, flushResourcesSync } from "./scheduler.js";
|
|
6
|
+
import { tapResourceRoot } from "../tapResourceRoot.js";
|
|
7
|
+
//#region src/core/createResourceRoot.ts
|
|
7
8
|
const SubscribableResource = resource(tapResourceRoot);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
unmount: () => {
|
|
28
|
-
unmountResourceFiber(fiber);
|
|
29
|
-
},
|
|
30
|
-
};
|
|
9
|
+
const createResourceRoot = () => {
|
|
10
|
+
const fiber = createResourceFiber(SubscribableResource, createResourceFiberRoot((callback) => {
|
|
11
|
+
new UpdateScheduler(() => {
|
|
12
|
+
if (callback()) throw new Error("Unexpected rerender of createResourceRoot outer fiber");
|
|
13
|
+
return false;
|
|
14
|
+
}).markDirty();
|
|
15
|
+
}), void 0, isDevelopment ? "root" : null);
|
|
16
|
+
return {
|
|
17
|
+
render: (element) => {
|
|
18
|
+
if (isDevelopment && fiber.devStrictMode === "root") renderResourceFiber(fiber, element);
|
|
19
|
+
const render = renderResourceFiber(fiber, element);
|
|
20
|
+
flushResourcesSync(() => commitResourceFiber(fiber, render));
|
|
21
|
+
return render.output;
|
|
22
|
+
},
|
|
23
|
+
unmount: () => {
|
|
24
|
+
unmountResourceFiber(fiber);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
31
27
|
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { createResourceRoot };
|
|
30
|
+
|
|
32
31
|
//# sourceMappingURL=createResourceRoot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createResourceRoot.js","
|
|
1
|
+
{"version":3,"file":"createResourceRoot.js","names":[],"sources":["../../src/core/createResourceRoot.ts"],"sourcesContent":["import type { ResourceElement } from \"./types\";\nimport {\n createResourceFiber,\n unmountResourceFiber,\n renderResourceFiber,\n commitResourceFiber,\n} from \"./ResourceFiber\";\nimport { tapResourceRoot } from \"../tapResourceRoot\";\nimport { resource } from \"./resource\";\nimport { isDevelopment } from \"./helpers/env\";\nimport { flushResourcesSync, UpdateScheduler } from \"./scheduler\";\nimport { createResourceFiberRoot } from \"./helpers/root\";\n\nconst SubscribableResource = resource(tapResourceRoot);\n\nexport const createResourceRoot = () => {\n const fiber = createResourceFiber<\n tapResourceRoot.SubscribableResource<any>,\n ResourceElement<any>\n >(\n SubscribableResource,\n createResourceFiberRoot((callback) => {\n new UpdateScheduler(() => {\n if (callback()) {\n throw new Error(\n \"Unexpected rerender of createResourceRoot outer fiber\",\n );\n }\n return false;\n }).markDirty();\n }),\n undefined,\n isDevelopment ? \"root\" : null,\n );\n\n return {\n render: <R, P>(element: ResourceElement<R, P>) => {\n // In strict mode, render twice to detect side effects\n if (isDevelopment && fiber.devStrictMode === \"root\") {\n void renderResourceFiber(fiber, element);\n }\n\n const render = renderResourceFiber(fiber, element);\n\n flushResourcesSync(() => commitResourceFiber(fiber, render));\n\n return render.output;\n },\n unmount: () => {\n unmountResourceFiber(fiber);\n },\n };\n};\n"],"mappings":";;;;;;;AAaA,MAAM,uBAAuB,SAAS,eAAe;AAErD,MAAa,2BAA2B;CACtC,MAAM,QAAQ,oBAIZ,sBACA,yBAAyB,aAAa;EACpC,IAAI,sBAAsB;GACxB,IAAI,SAAS,GACX,MAAM,IAAI,MACR,uDACF;GAEF,OAAO;EACT,CAAC,EAAE,UAAU;CACf,CAAC,GACD,KAAA,GACA,gBAAgB,SAAS,IAC3B;CAEA,OAAO;EACL,SAAe,YAAmC;GAEhD,IAAI,iBAAiB,MAAM,kBAAkB,QAC3C,oBAAyB,OAAO,OAAO;GAGzC,MAAM,SAAS,oBAAoB,OAAO,OAAO;GAEjD,yBAAyB,oBAAoB,OAAO,MAAM,CAAC;GAE3D,OAAO,OAAO;EAChB;EACA,eAAe;GACb,qBAAqB,KAAK;EAC5B;CACF;AACF"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {};
|
|
2
|
-
//# sourceMappingURL=callResourceFn.d.ts.map
|
|
1
|
+
export { };
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
//#region src/core/helpers/callResourceFn.ts
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
return fn(props);
|
|
3
|
+
* Renders a resource with the given props.
|
|
4
|
+
* @internal This is for internal use only.
|
|
5
|
+
*/
|
|
6
|
+
function callResourceFn(resource, props) {
|
|
7
|
+
const fn = resource[fnSymbol];
|
|
8
|
+
if (!fn) throw new Error("ResourceElement.type is not a valid Resource");
|
|
9
|
+
return fn(props);
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
* Symbol used to store the ResourceFn in the Resource constructor.
|
|
13
|
+
* @internal This is for internal use only.
|
|
14
|
+
*/
|
|
15
|
+
const fnSymbol = Symbol("fnSymbol");
|
|
16
|
+
//#endregion
|
|
17
|
+
export { callResourceFn, fnSymbol };
|
|
18
|
+
|
|
17
19
|
//# sourceMappingURL=callResourceFn.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callResourceFn.js","
|
|
1
|
+
{"version":3,"file":"callResourceFn.js","names":[],"sources":["../../../src/core/helpers/callResourceFn.ts"],"sourcesContent":["import type { Resource } from \"../types\";\n\n/**\n * Renders a resource with the given props.\n * @internal This is for internal use only.\n */\nexport function callResourceFn<R, P>(resource: Resource<R, P>, props: P): R {\n const fn = (resource as unknown as { [fnSymbol]?: (props: P) => R })[\n fnSymbol\n ];\n if (!fn) {\n throw new Error(\"ResourceElement.type is not a valid Resource\");\n }\n return fn(props);\n}\n\n/**\n * Symbol used to store the ResourceFn in the Resource constructor.\n * @internal This is for internal use only.\n */\nexport const fnSymbol = Symbol(\"fnSymbol\");\n"],"mappings":";;;;;AAMA,SAAgB,eAAqB,UAA0B,OAAa;CAC1E,MAAM,KAAM,SACV;CAEF,IAAI,CAAC,IACH,MAAM,IAAI,MAAM,8CAA8C;CAEhE,OAAO,GAAG,KAAK;AACjB;;;;;AAMA,MAAa,WAAW,OAAO,UAAU"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { RenderResult, ResourceFiber } from "../types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/core/helpers/commit.d.ts
|
|
4
|
+
declare function commitAllEffects(renderResult: RenderResult): void;
|
|
5
|
+
declare function cleanupAllEffects<R, P>(executionContext: ResourceFiber<R, P>): void;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { cleanupAllEffects, commitAllEffects };
|
|
4
8
|
//# sourceMappingURL=commit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commit.d.ts","
|
|
1
|
+
{"version":3,"file":"commit.d.ts","names":[],"sources":["../../../src/core/helpers/commit.ts"],"mappings":";;;iBAEgB,gBAAA,CAAiB,YAA0B,EAAZ,YAAY;AAAA,iBAuB3C,iBAAA,MAAA,CAAwB,gBAAA,EAAkB,aAAA,CAAc,CAAA,EAAG,CAAA"}
|
|
@@ -1,53 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
for (const error of errors) {
|
|
17
|
-
console.error(error);
|
|
18
|
-
}
|
|
19
|
-
throw new AggregateError(errors, "Errors during commit");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
//#region src/core/helpers/commit.ts
|
|
2
|
+
function commitAllEffects(renderResult) {
|
|
3
|
+
const errors = [];
|
|
4
|
+
for (const task of renderResult.effectTasks) try {
|
|
5
|
+
task();
|
|
6
|
+
} catch (error) {
|
|
7
|
+
errors.push(error);
|
|
8
|
+
}
|
|
9
|
+
if (errors.length > 0) if (errors.length === 1) throw errors[0];
|
|
10
|
+
else {
|
|
11
|
+
for (const error of errors) console.error(error);
|
|
12
|
+
throw new AggregateError(errors, "Errors during commit");
|
|
13
|
+
}
|
|
22
14
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
if (errors.length > 0) {
|
|
42
|
-
if (errors.length === 1) {
|
|
43
|
-
throw errors[0];
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
for (const error of errors) {
|
|
47
|
-
console.error(error);
|
|
48
|
-
}
|
|
49
|
-
throw new AggregateError(errors, "Errors during cleanup");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
15
|
+
function cleanupAllEffects(executionContext) {
|
|
16
|
+
const errors = [];
|
|
17
|
+
for (const cell of executionContext.cells) if (cell?.type === "effect") {
|
|
18
|
+
cell.deps = null;
|
|
19
|
+
if (cell.cleanup) try {
|
|
20
|
+
cell.cleanup?.();
|
|
21
|
+
} catch (e) {
|
|
22
|
+
errors.push(e);
|
|
23
|
+
} finally {
|
|
24
|
+
cell.cleanup = void 0;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (errors.length > 0) if (errors.length === 1) throw errors[0];
|
|
28
|
+
else {
|
|
29
|
+
for (const error of errors) console.error(error);
|
|
30
|
+
throw new AggregateError(errors, "Errors during cleanup");
|
|
31
|
+
}
|
|
52
32
|
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { cleanupAllEffects, commitAllEffects };
|
|
35
|
+
|
|
53
36
|
//# sourceMappingURL=commit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commit.js","
|
|
1
|
+
{"version":3,"file":"commit.js","names":[],"sources":["../../../src/core/helpers/commit.ts"],"sourcesContent":["import type { ResourceFiber, RenderResult } from \"../types\";\n\nexport function commitAllEffects(renderResult: RenderResult): void {\n const errors: unknown[] = [];\n\n for (const task of renderResult.effectTasks) {\n try {\n task();\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 during commit\");\n }\n }\n}\n\nexport function cleanupAllEffects<R, P>(executionContext: ResourceFiber<R, P>) {\n const errors: unknown[] = [];\n for (const cell of executionContext.cells) {\n if (cell?.type === \"effect\") {\n cell.deps = null; // Reset deps so effect runs again on next mount\n\n if (cell.cleanup) {\n try {\n cell.cleanup?.();\n } catch (e) {\n errors.push(e);\n } finally {\n cell.cleanup = undefined;\n }\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 during cleanup\");\n }\n }\n}\n"],"mappings":";AAEA,SAAgB,iBAAiB,cAAkC;CACjE,MAAM,SAAoB,CAAC;CAE3B,KAAK,MAAM,QAAQ,aAAa,aAC9B,IAAI;EACF,KAAK;CACP,SAAS,OAAO;EACd,OAAO,KAAK,KAAK;CACnB;CAGF,IAAI,OAAO,SAAS,GAClB,IAAI,OAAO,WAAW,GACpB,MAAM,OAAO;MACR;EACL,KAAK,MAAM,SAAS,QAClB,QAAQ,MAAM,KAAK;EAErB,MAAM,IAAI,eAAe,QAAQ,sBAAsB;CACzD;AAEJ;AAEA,SAAgB,kBAAwB,kBAAuC;CAC7E,MAAM,SAAoB,CAAC;CAC3B,KAAK,MAAM,QAAQ,iBAAiB,OAClC,IAAI,MAAM,SAAS,UAAU;EAC3B,KAAK,OAAO;EAEZ,IAAI,KAAK,SACP,IAAI;GACF,KAAK,UAAU;EACjB,SAAS,GAAG;GACV,OAAO,KAAK,CAAC;EACf,UAAU;GACR,KAAK,UAAU,KAAA;EACjB;CAEJ;CAEF,IAAI,OAAO,SAAS,GAClB,IAAI,OAAO,WAAW,GACpB,MAAM,OAAO;MACR;EACL,KAAK,MAAM,SAAS,QAClB,QAAQ,MAAM,KAAK;EAErB,MAAM,IAAI,eAAe,QAAQ,uBAAuB;CAC1D;AAEJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","
|
|
1
|
+
{"version":3,"file":"env.d.ts","names":[],"sources":["../../../src/core/helpers/env.ts"],"mappings":";cAAa,aAAA"}
|
package/dist/core/helpers/env.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/core/helpers/env.ts
|
|
2
|
+
const isDevelopment = typeof process !== "undefined" && (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test");
|
|
3
|
+
//#endregion
|
|
4
|
+
export { isDevelopment };
|
|
5
|
+
|
|
3
6
|
//# sourceMappingURL=env.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","
|
|
1
|
+
{"version":3,"file":"env.js","names":[],"sources":["../../../src/core/helpers/env.ts"],"sourcesContent":["export const isDevelopment =\n typeof process !== \"undefined\" &&\n (process.env.NODE_ENV === \"development\" || process.env.NODE_ENV === \"test\");\n"],"mappings":";AAAA,MAAa,gBACX,OAAO,YAAY,gBAClB,QAAQ,IAAI,aAAa,iBAAiB,QAAQ,IAAI,aAAa"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { ResourceFiber } from "../types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/core/helpers/execution-context.d.ts
|
|
4
|
+
declare function withResourceFiber<R, P>(fiber: ResourceFiber<R, P>, fn: () => void): void;
|
|
5
|
+
declare function getCurrentResourceFiber(): ResourceFiber<unknown, unknown>;
|
|
6
|
+
declare function getDevStrictMode(enable: boolean): "root" | "child" | null;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { getCurrentResourceFiber, getDevStrictMode, withResourceFiber };
|
|
5
9
|
//# sourceMappingURL=execution-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution-context.d.ts","
|
|
1
|
+
{"version":3,"file":"execution-context.d.ts","names":[],"sources":["../../../src/core/helpers/execution-context.ts"],"mappings":";;;iBAKgB,iBAAA,MAAA,CACd,KAAA,EAAO,aAAA,CAAc,CAAA,EAAG,CAAA,GACxB,EAAA;AAAA,iBAsBc,uBAAA,CAAA,GAA2B,aAAa;AAAA,iBAOxC,gBAAA,CAAiB,MAAe"}
|
|
@@ -1,33 +1,28 @@
|
|
|
1
1
|
import { isDevelopment } from "./env.js";
|
|
2
|
+
//#region src/core/helpers/execution-context.ts
|
|
2
3
|
let currentResourceFiber = null;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
finally {
|
|
17
|
-
currentResourceFiber = previousContext;
|
|
18
|
-
}
|
|
4
|
+
function withResourceFiber(fiber, fn) {
|
|
5
|
+
fiber.currentIndex = 0;
|
|
6
|
+
const previousContext = currentResourceFiber;
|
|
7
|
+
currentResourceFiber = fiber;
|
|
8
|
+
try {
|
|
9
|
+
fn();
|
|
10
|
+
fiber.isFirstRender = false;
|
|
11
|
+
if (fiber.cells.length !== fiber.currentIndex) throw new Error(`Rendered ${fiber.currentIndex} hooks but expected ${fiber.cells.length}. Hooks must be called in the exact same order in every render.`);
|
|
12
|
+
} finally {
|
|
13
|
+
currentResourceFiber = previousContext;
|
|
14
|
+
}
|
|
19
15
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
return currentResourceFiber;
|
|
16
|
+
function getCurrentResourceFiber() {
|
|
17
|
+
if (!currentResourceFiber) throw new Error("No resource fiber available");
|
|
18
|
+
return currentResourceFiber;
|
|
25
19
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return currentResourceFiber.isFirstRender ? "child" : "root";
|
|
31
|
-
return enable ? "root" : null;
|
|
20
|
+
function getDevStrictMode(enable) {
|
|
21
|
+
if (!isDevelopment) return null;
|
|
22
|
+
if (currentResourceFiber?.devStrictMode) return currentResourceFiber.isFirstRender ? "child" : "root";
|
|
23
|
+
return enable ? "root" : null;
|
|
32
24
|
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { getCurrentResourceFiber, getDevStrictMode, withResourceFiber };
|
|
27
|
+
|
|
33
28
|
//# sourceMappingURL=execution-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution-context.js","
|
|
1
|
+
{"version":3,"file":"execution-context.js","names":[],"sources":["../../../src/core/helpers/execution-context.ts"],"sourcesContent":["import { isDevelopment } from \"./env\";\nimport type { ResourceFiber } from \"../types\";\n\nlet currentResourceFiber: ResourceFiber<any, any> | null = null;\n\nexport function withResourceFiber<R, P>(\n fiber: ResourceFiber<R, P>,\n fn: () => void,\n): void {\n fiber.currentIndex = 0;\n\n const previousContext = currentResourceFiber;\n currentResourceFiber = fiber;\n try {\n fn();\n\n fiber.isFirstRender = false;\n\n // ensure hook count matches\n if (fiber.cells.length !== fiber.currentIndex) {\n throw new Error(\n `Rendered ${fiber.currentIndex} hooks but expected ${fiber.cells.length}. ` +\n \"Hooks must be called in the exact same order in every render.\",\n );\n }\n } finally {\n currentResourceFiber = previousContext;\n }\n}\nexport function getCurrentResourceFiber(): ResourceFiber<unknown, unknown> {\n if (!currentResourceFiber) {\n throw new Error(\"No resource fiber available\");\n }\n return currentResourceFiber;\n}\n\nexport function getDevStrictMode(enable: boolean) {\n if (!isDevelopment) return null;\n if (currentResourceFiber?.devStrictMode)\n return currentResourceFiber.isFirstRender ? \"child\" : \"root\";\n\n return enable ? \"root\" : null;\n}\n"],"mappings":";;AAGA,IAAI,uBAAuD;AAE3D,SAAgB,kBACd,OACA,IACM;CACN,MAAM,eAAe;CAErB,MAAM,kBAAkB;CACxB,uBAAuB;CACvB,IAAI;EACF,GAAG;EAEH,MAAM,gBAAgB;EAGtB,IAAI,MAAM,MAAM,WAAW,MAAM,cAC/B,MAAM,IAAI,MACR,YAAY,MAAM,aAAa,sBAAsB,MAAM,MAAM,OAAO,gEAE1E;CAEJ,UAAU;EACR,uBAAuB;CACzB;AACF;AACA,SAAgB,0BAA2D;CACzE,IAAI,CAAC,sBACH,MAAM,IAAI,MAAM,6BAA6B;CAE/C,OAAO;AACT;AAEA,SAAgB,iBAAiB,QAAiB;CAChD,IAAI,CAAC,eAAe,OAAO;CAC3B,IAAI,sBAAsB,eACxB,OAAO,qBAAqB,gBAAgB,UAAU;CAExD,OAAO,SAAS,SAAS;AAC3B"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Cell, ResourceFiber, ResourceFiberRoot } from "../types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/core/helpers/root.d.ts
|
|
4
|
+
declare const createResourceFiberRoot: (dispatchUpdate: (cb: () => boolean) => void) => ResourceFiberRoot;
|
|
5
|
+
declare const commitRoot: (root: ResourceFiberRoot) => void;
|
|
6
|
+
declare const setRootVersion: (root: ResourceFiberRoot, version: number) => void;
|
|
7
|
+
declare const markCellDirty: (fiber: ResourceFiber<any, any>, cell: Cell & {
|
|
8
|
+
type: "reducer";
|
|
7
9
|
}) => void;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { commitRoot, createResourceFiberRoot, markCellDirty, setRootVersion };
|
|
8
12
|
//# sourceMappingURL=root.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.d.ts","
|
|
1
|
+
{"version":3,"file":"root.d.ts","names":[],"sources":["../../../src/core/helpers/root.ts"],"mappings":";;;cAEa,uBAAA,GACX,cAAA,GAAiB,EAAA,6BAChB,iBAQF;AAAA,cAEY,UAAA,GAAc,IAAuB,EAAjB,iBAAiB;AAAA,cAWrC,cAAA,GACX,IAAA,EAAM,iBAAiB,EACvB,OAAA;AAAA,cA+BW,aAAA,GACX,KAAA,EAAO,aAAA,YACP,IAAA,EAAM,IAAI;EAAK,IAAA;AAAA"}
|
|
@@ -1,53 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
//#region src/core/helpers/root.ts
|
|
2
|
+
const createResourceFiberRoot = (dispatchUpdate) => {
|
|
3
|
+
return {
|
|
4
|
+
version: 0,
|
|
5
|
+
committedVersion: 0,
|
|
6
|
+
dispatchUpdate,
|
|
7
|
+
changelog: [],
|
|
8
|
+
dirtyCells: []
|
|
9
|
+
};
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
const commitRoot = (root) => {
|
|
12
|
+
for (const cell of root.dirtyCells) {
|
|
13
|
+
cell.dirty = false;
|
|
14
|
+
cell.queue.clear();
|
|
15
|
+
cell.current = cell.workInProgress;
|
|
16
|
+
}
|
|
17
|
+
root.committedVersion = root.version;
|
|
18
|
+
root.changelog.length = 0;
|
|
19
|
+
root.dirtyCells.length = 0;
|
|
19
20
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
root.changelog.pop();
|
|
39
|
-
}
|
|
40
|
-
// biome-ignore lint/suspicious/useIterableCallbackReturn: forEach callback intentionally has no return
|
|
41
|
-
root.changelog.forEach((apply) => apply());
|
|
42
|
-
commitRoot(root);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
21
|
+
const setRootVersion = (root, version) => {
|
|
22
|
+
const rollback = root.version > version;
|
|
23
|
+
root.version = version;
|
|
24
|
+
if (rollback) {
|
|
25
|
+
for (const cell of root.dirtyCells) {
|
|
26
|
+
cell.dirty = false;
|
|
27
|
+
cell.queue.clear();
|
|
28
|
+
cell.workInProgress = cell.current;
|
|
29
|
+
}
|
|
30
|
+
root.dirtyCells.length = 0;
|
|
31
|
+
if (version === root.committedVersion) root.changelog.length = 0;
|
|
32
|
+
else {
|
|
33
|
+
if (root.committedVersion > version) throw new Error("Version is less than committed version");
|
|
34
|
+
while (root.committedVersion + root.changelog.length > version) root.changelog.pop();
|
|
35
|
+
root.changelog.forEach((apply) => apply());
|
|
36
|
+
commitRoot(root);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
45
39
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
const markCellDirty = (fiber, cell) => {
|
|
41
|
+
if (!cell.dirty) {
|
|
42
|
+
cell.dirty = true;
|
|
43
|
+
fiber.markDirty?.();
|
|
44
|
+
fiber.root.dirtyCells.push(cell);
|
|
45
|
+
}
|
|
52
46
|
};
|
|
47
|
+
//#endregion
|
|
48
|
+
export { commitRoot, createResourceFiberRoot, markCellDirty, setRootVersion };
|
|
49
|
+
|
|
53
50
|
//# sourceMappingURL=root.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root.js","
|
|
1
|
+
{"version":3,"file":"root.js","names":[],"sources":["../../../src/core/helpers/root.ts"],"sourcesContent":["import type { Cell, ResourceFiber, ResourceFiberRoot } from \"../types\";\n\nexport const createResourceFiberRoot = (\n dispatchUpdate: (cb: () => boolean) => void,\n): ResourceFiberRoot => {\n return {\n version: 0,\n committedVersion: 0,\n dispatchUpdate,\n changelog: [],\n dirtyCells: [],\n };\n};\n\nexport const commitRoot = (root: ResourceFiberRoot): void => {\n for (const cell of root.dirtyCells) {\n cell.dirty = false;\n cell.queue.clear();\n cell.current = cell.workInProgress;\n }\n root.committedVersion = root.version;\n root.changelog.length = 0;\n root.dirtyCells.length = 0;\n};\n\nexport const setRootVersion = (\n root: ResourceFiberRoot,\n version: number,\n): void => {\n const rollback = root.version > version;\n root.version = version;\n if (rollback) {\n for (const cell of root.dirtyCells) {\n cell.dirty = false;\n cell.queue.clear();\n cell.workInProgress = cell.current;\n }\n root.dirtyCells.length = 0;\n\n if (version === root.committedVersion) {\n root.changelog.length = 0;\n } else {\n // commit happened without a useEffect update (offscreen API)\n\n if (root.committedVersion > version)\n throw new Error(\"Version is less than committed version\");\n\n while (root.committedVersion + root.changelog.length > version) {\n root.changelog.pop();\n }\n\n // biome-ignore lint/suspicious/useIterableCallbackReturn: forEach callback intentionally has no return\n root.changelog.forEach((apply) => apply());\n commitRoot(root);\n }\n }\n};\n\nexport const markCellDirty = (\n fiber: ResourceFiber<any, any>,\n cell: Cell & { type: \"reducer\" },\n): void => {\n if (!cell.dirty) {\n cell.dirty = true;\n fiber.markDirty?.();\n fiber.root.dirtyCells.push(cell);\n }\n};\n"],"mappings":";AAEA,MAAa,2BACX,mBACsB;CACtB,OAAO;EACL,SAAS;EACT,kBAAkB;EAClB;EACA,WAAW,CAAC;EACZ,YAAY,CAAC;CACf;AACF;AAEA,MAAa,cAAc,SAAkC;CAC3D,KAAK,MAAM,QAAQ,KAAK,YAAY;EAClC,KAAK,QAAQ;EACb,KAAK,MAAM,MAAM;EACjB,KAAK,UAAU,KAAK;CACtB;CACA,KAAK,mBAAmB,KAAK;CAC7B,KAAK,UAAU,SAAS;CACxB,KAAK,WAAW,SAAS;AAC3B;AAEA,MAAa,kBACX,MACA,YACS;CACT,MAAM,WAAW,KAAK,UAAU;CAChC,KAAK,UAAU;CACf,IAAI,UAAU;EACZ,KAAK,MAAM,QAAQ,KAAK,YAAY;GAClC,KAAK,QAAQ;GACb,KAAK,MAAM,MAAM;GACjB,KAAK,iBAAiB,KAAK;EAC7B;EACA,KAAK,WAAW,SAAS;EAEzB,IAAI,YAAY,KAAK,kBACnB,KAAK,UAAU,SAAS;OACnB;GAGL,IAAI,KAAK,mBAAmB,SAC1B,MAAM,IAAI,MAAM,wCAAwC;GAE1D,OAAO,KAAK,mBAAmB,KAAK,UAAU,SAAS,SACrD,KAAK,UAAU,IAAI;GAIrB,KAAK,UAAU,SAAS,UAAU,MAAM,CAAC;GACzC,WAAW,IAAI;EACjB;CACF;AACF;AAEA,MAAa,iBACX,OACA,SACS;CACT,IAAI,CAAC,KAAK,OAAO;EACf,KAAK,QAAQ;EACb,MAAM,YAAY;EAClB,MAAM,KAAK,WAAW,KAAK,IAAI;CACjC;AACF"}
|
package/dist/core/resource.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { ResourceElement } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/core/resource.d.ts
|
|
4
|
+
declare function resource<R>(fn: () => R): () => ResourceElement<R, undefined>;
|
|
5
|
+
declare function resource<R, P>(fn: (props: P) => R): (props: P) => ResourceElement<R, P>;
|
|
6
|
+
declare function resource<R, P>(fn: (props?: P) => R): (props?: P) => ResourceElement<R, P | undefined>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { resource };
|
|
5
9
|
//# sourceMappingURL=resource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.d.ts","
|
|
1
|
+
{"version":3,"file":"resource.d.ts","names":[],"sources":["../../src/core/resource.ts"],"mappings":";;;iBAGgB,QAAA,GAAA,CAAY,EAAA,QAAU,CAAA,SAAU,eAAA,CAAgB,CAAA;AAAA,iBAChD,QAAA,MAAA,CACd,EAAA,GAAK,KAAA,EAAO,CAAA,KAAM,CAAA,IAChB,KAAA,EAAO,CAAA,KAAM,eAAA,CAAgB,CAAA,EAAG,CAAA;AAAA,iBACpB,QAAA,MAAA,CACd,EAAA,GAAK,KAAA,GAAQ,CAAA,KAAM,CAAA,IACjB,KAAA,GAAQ,CAAA,KAAM,eAAA,CAAgB,CAAA,EAAG,CAAA"}
|
package/dist/core/resource.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { fnSymbol } from "./helpers/callResourceFn.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
//#region src/core/resource.ts
|
|
3
|
+
function resource(fn) {
|
|
4
|
+
const type = (props) => {
|
|
5
|
+
return {
|
|
6
|
+
type,
|
|
7
|
+
props
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
type[fnSymbol] = fn;
|
|
11
|
+
return type;
|
|
11
12
|
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { resource };
|
|
15
|
+
|
|
12
16
|
//# sourceMappingURL=resource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.js","
|
|
1
|
+
{"version":3,"file":"resource.js","names":[],"sources":["../../src/core/resource.ts"],"sourcesContent":["import type { ResourceElement } from \"./types\";\nimport { fnSymbol } from \"./helpers/callResourceFn\";\n\nexport function resource<R>(fn: () => R): () => ResourceElement<R, undefined>;\nexport function resource<R, P>(\n fn: (props: P) => R,\n): (props: P) => ResourceElement<R, P>;\nexport function resource<R, P>(\n fn: (props?: P) => R,\n): (props?: P) => ResourceElement<R, P | undefined>;\nexport function resource<R, P = undefined>(fn: (props: P) => R) {\n const type = (props?: P) => {\n return {\n type,\n props: props!,\n } satisfies ResourceElement<R, P>;\n };\n\n type[fnSymbol] = fn;\n\n return type;\n}\n"],"mappings":";;AAUA,SAAgB,SAA2B,IAAqB;CAC9D,MAAM,QAAQ,UAAc;EAC1B,OAAO;GACL;GACO;EACT;CACF;CAEA,KAAK,YAAY;CAEjB,OAAO;AACT"}
|
package/dist/core/scheduler.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
//#region src/core/scheduler.d.ts
|
|
1
2
|
type Task = () => void;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
declare class UpdateScheduler {
|
|
4
|
+
private readonly _task;
|
|
5
|
+
private _isDirty;
|
|
6
|
+
constructor(_task: Task);
|
|
7
|
+
get isDirty(): boolean;
|
|
8
|
+
markDirty(): void;
|
|
9
|
+
runTask(): void;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
declare const flushResourcesSync: <T>(callback: () => T) => T;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { UpdateScheduler, flushResourcesSync };
|
|
12
14
|
//# sourceMappingURL=scheduler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.d.ts","
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","names":[],"sources":["../../src/core/scheduler.ts"],"mappings":";KAAK,IAAA;AAAA,cAaQ,eAAA;EAAA,iBAGkB,KAAA;EAAA,QAFrB,QAAA;cAEqB,KAAA,EAAO,IAAI;EAAA,IAEpC,OAAA,CAAA;EAIJ,SAAA,CAAA;EAOA,OAAA,CAAA;AAAA;AAAA,cAiEW,kBAAA,MAAyB,QAAA,QAAgB,CAAA,KAAI,CAezD"}
|