one
Version:
One is a new React Framework that makes Vite serve both native and web.
61 lines • 2.55 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: !0
});
},
__copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
return to;
};
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
value: !0
}), mod);
var RouteInfoContext_exports = {};
__export(RouteInfoContext_exports, {
RouteInfoContext: () => RouteInfoContext,
RouteInfoContextProvider: () => RouteInfoContextProvider
});
module.exports = __toCommonJS(RouteInfoContext_exports);
var import_react = require("react"),
import_core = require("@react-navigation/core"),
import_router = require("./router.cjs"),
import_jsx_runtime = require("react/jsx-runtime");
const RouteInfoContext = (0, import_react.createContext)(void 0);
function RouteInfoContextProvider({
children
}) {
const currentState = (0, import_core.useStateForPath)(),
currentStateRef = (0, import_react.useRef)(void 0),
lastStateRef = (0, import_react.useRef)(void 0),
cachedRouteInfoValueRef = (0, import_react.useRef)(void 0),
lazilyCalculatedRouteInfo = (0, import_react.useRef)();
return currentState && currentStateRef.current !== currentState && (lazilyCalculatedRouteInfo.current = makeLazilyCalculatedRouteInfo({
currentStateRef,
lastStateRef,
cachedRouteInfoValueRef
})), currentStateRef.current = currentState, /* @__PURE__ */(0, import_jsx_runtime.jsx)(RouteInfoContext.Provider, {
value: currentState ? lazilyCalculatedRouteInfo.current : void 0,
children
});
}
function makeLazilyCalculatedRouteInfo({
currentStateRef,
lastStateRef,
cachedRouteInfoValueRef
}) {
return new Proxy({}, {
get(_, p) {
const state = currentStateRef.current;
if (!state) throw new Error("[lazilyCalculatedRouteInfo] cannot get state");
return (!cachedRouteInfoValueRef.current || lastStateRef.current !== state) && (cachedRouteInfoValueRef.current = (0, import_router.getRouteInfo)(state), lastStateRef.current = state), cachedRouteInfoValueRef.current[p];
}
});
}