one
Version:
One is a new React Framework that makes Vite serve both native and web.
67 lines (65 loc) • 2.71 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_jsx_runtime = require("react/jsx-runtime"),
import_core = require("@react-navigation/core"),
import_react = require("react"),
import_getRouteInfo = require("./getRouteInfo.native.js"),
RouteInfoContext = /* @__PURE__ */(0, import_react.createContext)(void 0);
function RouteInfoContextProvider(param) {
var {
children
} = param,
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)(void 0);
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(param) {
var {
currentStateRef,
lastStateRef,
cachedRouteInfoValueRef
} = param;
return new Proxy({}, {
get(_, p) {
var state = currentStateRef.current;
if (!state) throw new Error("[lazilyCalculatedRouteInfo] cannot get state");
return (!cachedRouteInfoValueRef.current || lastStateRef.current !== state) && (cachedRouteInfoValueRef.current = (0, import_getRouteInfo.getRouteInfo)(state), lastStateRef.current = state), cachedRouteInfoValueRef.current[p];
}
});
}
//# sourceMappingURL=RouteInfoContext.native.js.map