Files
SnowLuma/.pnpm-store/v11/files/50/726aaa1a60e29878a0971c0e4a4c59a06c3bbe3fdaa3a529aa53788d3143e9953e0eca31967d333cb86e6ca701ff546f58d4ed35e3c72cd60be50c5564f6b2
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

42 lines
1.0 KiB
Plaintext

import { DOM_ERROR_HANDLER } from "../constants.js";
import { setInternalTagFlag } from "./utils.js";
import { globalContexts } from "../context.js";
//#region src/jsx/dom/context.ts
const createContextProviderFunction = (values) => ({ value, children }) => {
if (!children) return;
const props = { children: [{
tag: setInternalTagFlag(() => {
values.push(value);
}),
props: {}
}] };
if (Array.isArray(children)) props.children.push(...children.flat());
else props.children.push(children);
props.children.push({
tag: setInternalTagFlag(() => {
values.pop();
}),
props: {}
});
const res = {
tag: "",
props,
type: ""
};
res[DOM_ERROR_HANDLER] = (err) => {
values.pop();
throw err;
};
return res;
};
const createContext = (defaultValue) => {
const values = [defaultValue];
const context = createContextProviderFunction(values);
context.values = values;
context.Provider = context;
globalContexts.push(context);
return context;
};
//#endregion
export { createContext, createContextProviderFunction };