(initialValue: T)
| 887 | }; |
| 888 | |
| 889 | export const createContext = <T>(initialValue: T) => { |
| 890 | const contextId = crypto.randomUUID(); |
| 891 | |
| 892 | currentTreeRef.defaultContextState.push({ |
| 893 | contextId, |
| 894 | state: initialValue, |
| 895 | }); |
| 896 | return { |
| 897 | // will not impl consumer |
| 898 | |
| 899 | Provider: (data: { |
| 900 | value: T; |
| 901 | children: Array< |
| 902 | ReactComponentInternalMetadata | null | false | undefined |
| 903 | >; |
| 904 | }) => { |
| 905 | if ( |
| 906 | typeof data.value === "object" && |
| 907 | data.value && |
| 908 | "__internal-context" in data.value |
| 909 | ) { |
| 910 | return contextId as unknown as ReturnType<typeof createElement>; |
| 911 | } |
| 912 | const el = createElement("div", null, ...data.children); // for i have sinned, ideally would of used a fragment |
| 913 | console.log(el); |
| 914 | if (!(el.kind === "real-element")) { |
| 915 | throw new Error(); |
| 916 | } |
| 917 | el.provider = { |
| 918 | state: data.value, |
| 919 | contextId, |
| 920 | }; |
| 921 | return el; |
| 922 | }, |
| 923 | }; |
| 924 | }; |
| 925 | |
| 926 | /** |
| 927 | * |
nothing calls this directly
no test coverage detected