30 lines
1.3 KiB
JavaScript
30 lines
1.3 KiB
JavaScript
import { createContext, useState } from "react"
|
|
import { Event, hydrateClientStorage, useEventLoop } from "/utils/state.js"
|
|
|
|
export const initialState = {"is_hydrated": false, "router": {"session": {"client_token": "", "client_ip": "", "session_id": ""}, "headers": {"host": "", "origin": "", "upgrade": "", "connection": "", "pragma": "", "cache_control": "", "user_agent": "", "sec_websocket_version": "", "sec_websocket_key": "", "sec_websocket_extensions": "", "accept_encoding": "", "accept_language": ""}, "page": {"host": "", "path": "", "raw_path": "", "full_path": "", "full_raw_path": "", "params": {}}}}
|
|
|
|
export const ColorModeContext = createContext(null);
|
|
export const StateContext = createContext(null);
|
|
export const EventLoopContext = createContext(null);
|
|
export const clientStorage = {"cookies": {}, "local_storage": {}}
|
|
|
|
export const initialEvents = () => [
|
|
Event('state.hydrate', hydrateClientStorage(clientStorage)),
|
|
]
|
|
|
|
export const isDevMode = true
|
|
|
|
export function EventLoopProvider({ children }) {
|
|
const [state, addEvents, connectError] = useEventLoop(
|
|
initialState,
|
|
initialEvents,
|
|
clientStorage,
|
|
)
|
|
return (
|
|
<EventLoopContext.Provider value={[addEvents, connectError]}>
|
|
<StateContext.Provider value={state}>
|
|
{children}
|
|
</StateContext.Provider>
|
|
</EventLoopContext.Provider>
|
|
)
|
|
} |