@hivem/react
Advanced tools
+27
-6
@@ -41,3 +41,3 @@ "use strict"; | ||
| var global_loaded_keys_atom = (0, import_jotai.atom)(/* @__PURE__ */ new Set()); | ||
| var globalDebugAtom = (0, import_jotai.atom)(false); | ||
| var global_debug_atom = (0, import_jotai.atom)(false); | ||
@@ -49,2 +49,3 @@ // src/provider.tsx | ||
| baseUrl = "http://localhost:8080", | ||
| debug = false, | ||
| getAuth, | ||
@@ -58,2 +59,3 @@ children | ||
| const setLoadedKeys = (0, import_jotai2.useSetAtom)(global_loaded_keys_atom); | ||
| const setGlobalDebug = (0, import_jotai2.useSetAtom)(global_debug_atom); | ||
| const [isReady, setIsReady] = (0, import_react.useState)(false); | ||
@@ -64,3 +66,3 @@ const clientRef = (0, import_react.useRef)(null); | ||
| const stableConfig = (0, import_react.useMemo)( | ||
| () => ({ apiKey, baseUrl }), | ||
| () => ({ apiKey, baseUrl, debug }), | ||
| [] | ||
@@ -71,3 +73,4 @@ // intentional: immutable for lifetime | ||
| setConfig(stableConfig); | ||
| }, [setConfig, stableConfig]); | ||
| setGlobalDebug(debug); | ||
| }, [setConfig, stableConfig, setGlobalDebug, debug]); | ||
| (0, import_react.useEffect)(() => { | ||
@@ -134,3 +137,3 @@ if (initializedRef.current) return; | ||
| const { default: defaultValue, debug: localDebug } = options ?? {}; | ||
| const globalDebug = (0, import_jotai3.useAtomValue)(globalDebugAtom); | ||
| const globalDebug = (0, import_jotai3.useAtomValue)(global_debug_atom); | ||
| const debug = globalDebug || localDebug || false; | ||
@@ -227,8 +230,20 @@ const { get, set: clientSet } = useClient(); | ||
| (0, import_react2.useEffect)(() => { | ||
| if (debug) { | ||
| console.log(`[useKey:${key}] atom change: atomValue=${JSON.stringify(atomValue)}, hasValue=${hasValue}`); | ||
| } | ||
| }, [atomValue, hasValue]); | ||
| (0, import_react2.useEffect)(() => { | ||
| if (debug) console.log(`[useKey:${key}] ready check: hasValue=${hasValue}, calling markReady=${hasValue}`); | ||
| if (hasValue) markReady(); | ||
| }, [hasValue, markReady]); | ||
| (0, import_react2.useEffect)(() => { | ||
| if (!hasValue) { | ||
| if (debug) console.log(`[useKey:${key}] sync effect: SKIPPED (hasValue=false), atomValue=${JSON.stringify(atomValue)}`); | ||
| return; | ||
| } | ||
| if (debug) console.log(`[useKey:${key}] sync effect: APPLYING localValue=${JSON.stringify(atomValue)}`); | ||
| setLocalValue(atomValue); | ||
| }, [atomValue]); | ||
| }, [atomValue, hasValue]); | ||
| (0, import_react2.useEffect)(() => { | ||
| if (debug) console.log(`[useKey:${key}] load init: hasLoadedRef=${hasLoadedRef.current}`); | ||
| if (hasLoadedRef.current) return; | ||
@@ -240,3 +255,3 @@ hasLoadedRef.current = true; | ||
| if (debug) { | ||
| console.log(`[useKey:${key}] effect state logs...`); | ||
| console.log(`[useKey:${key}] effect state snapshot logs...`); | ||
| console.log(`[useKey:${key}] state change: localValue = ${JSON.stringify(localValue)}`); | ||
@@ -249,2 +264,8 @@ console.log(`[useKey:${key}] state change: ready = ${ready}`); | ||
| }, [debug, key, localValue, ready, error, fetching, hasValue]); | ||
| (0, import_react2.useEffect)(() => { | ||
| console.log(`[useKey:${key}] MOUNT`); | ||
| return () => { | ||
| console.log(`[useKey:${key}] UNMOUNT`); | ||
| }; | ||
| }, []); | ||
| return { | ||
@@ -251,0 +272,0 @@ value: localValue, |
+2
-1
@@ -7,2 +7,3 @@ import * as react_jsx_runtime from 'react/jsx-runtime'; | ||
| baseUrl?: string; | ||
| debug?: boolean; | ||
| getAuth: () => Promise<{ | ||
@@ -14,3 +15,3 @@ identity: string; | ||
| } | ||
| declare function HivemProvider({ apiKey, baseUrl, getAuth, children, }: HivemProviderProps): react_jsx_runtime.JSX.Element | null; | ||
| declare function HivemProvider({ apiKey, baseUrl, debug, getAuth, children, }: HivemProviderProps): react_jsx_runtime.JSX.Element | null; | ||
@@ -17,0 +18,0 @@ interface ClientMethods { |
+2
-1
@@ -7,2 +7,3 @@ import * as react_jsx_runtime from 'react/jsx-runtime'; | ||
| baseUrl?: string; | ||
| debug?: boolean; | ||
| getAuth: () => Promise<{ | ||
@@ -14,3 +15,3 @@ identity: string; | ||
| } | ||
| declare function HivemProvider({ apiKey, baseUrl, getAuth, children, }: HivemProviderProps): react_jsx_runtime.JSX.Element | null; | ||
| declare function HivemProvider({ apiKey, baseUrl, debug, getAuth, children, }: HivemProviderProps): react_jsx_runtime.JSX.Element | null; | ||
@@ -17,0 +18,0 @@ interface ClientMethods { |
+27
-6
@@ -13,3 +13,3 @@ // src/provider.tsx | ||
| var global_loaded_keys_atom = atom(/* @__PURE__ */ new Set()); | ||
| var globalDebugAtom = atom(false); | ||
| var global_debug_atom = atom(false); | ||
@@ -21,2 +21,3 @@ // src/provider.tsx | ||
| baseUrl = "http://localhost:8080", | ||
| debug = false, | ||
| getAuth, | ||
@@ -30,2 +31,3 @@ children | ||
| const setLoadedKeys = useSetAtom(global_loaded_keys_atom); | ||
| const setGlobalDebug = useSetAtom(global_debug_atom); | ||
| const [isReady, setIsReady] = useState(false); | ||
@@ -36,3 +38,3 @@ const clientRef = useRef(null); | ||
| const stableConfig = useMemo( | ||
| () => ({ apiKey, baseUrl }), | ||
| () => ({ apiKey, baseUrl, debug }), | ||
| [] | ||
@@ -43,3 +45,4 @@ // intentional: immutable for lifetime | ||
| setConfig(stableConfig); | ||
| }, [setConfig, stableConfig]); | ||
| setGlobalDebug(debug); | ||
| }, [setConfig, stableConfig, setGlobalDebug, debug]); | ||
| useEffect(() => { | ||
@@ -106,3 +109,3 @@ if (initializedRef.current) return; | ||
| const { default: defaultValue, debug: localDebug } = options ?? {}; | ||
| const globalDebug = useAtomValue(globalDebugAtom); | ||
| const globalDebug = useAtomValue(global_debug_atom); | ||
| const debug = globalDebug || localDebug || false; | ||
@@ -199,8 +202,20 @@ const { get, set: clientSet } = useClient(); | ||
| useEffect2(() => { | ||
| if (debug) { | ||
| console.log(`[useKey:${key}] atom change: atomValue=${JSON.stringify(atomValue)}, hasValue=${hasValue}`); | ||
| } | ||
| }, [atomValue, hasValue]); | ||
| useEffect2(() => { | ||
| if (debug) console.log(`[useKey:${key}] ready check: hasValue=${hasValue}, calling markReady=${hasValue}`); | ||
| if (hasValue) markReady(); | ||
| }, [hasValue, markReady]); | ||
| useEffect2(() => { | ||
| if (!hasValue) { | ||
| if (debug) console.log(`[useKey:${key}] sync effect: SKIPPED (hasValue=false), atomValue=${JSON.stringify(atomValue)}`); | ||
| return; | ||
| } | ||
| if (debug) console.log(`[useKey:${key}] sync effect: APPLYING localValue=${JSON.stringify(atomValue)}`); | ||
| setLocalValue(atomValue); | ||
| }, [atomValue]); | ||
| }, [atomValue, hasValue]); | ||
| useEffect2(() => { | ||
| if (debug) console.log(`[useKey:${key}] load init: hasLoadedRef=${hasLoadedRef.current}`); | ||
| if (hasLoadedRef.current) return; | ||
@@ -212,3 +227,3 @@ hasLoadedRef.current = true; | ||
| if (debug) { | ||
| console.log(`[useKey:${key}] effect state logs...`); | ||
| console.log(`[useKey:${key}] effect state snapshot logs...`); | ||
| console.log(`[useKey:${key}] state change: localValue = ${JSON.stringify(localValue)}`); | ||
@@ -221,2 +236,8 @@ console.log(`[useKey:${key}] state change: ready = ${ready}`); | ||
| }, [debug, key, localValue, ready, error, fetching, hasValue]); | ||
| useEffect2(() => { | ||
| console.log(`[useKey:${key}] MOUNT`); | ||
| return () => { | ||
| console.log(`[useKey:${key}] UNMOUNT`); | ||
| }; | ||
| }, []); | ||
| return { | ||
@@ -223,0 +244,0 @@ value: localValue, |
+1
-1
| { | ||
| "name": "@hivem/react", | ||
| "version": "0.2.4", | ||
| "version": "0.2.5", | ||
| "description": "React SDK for Hivem - auth-based KV service with sync support", | ||
@@ -5,0 +5,0 @@ "type": "module", |
26439
8.38%634
7.28%