UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

79 lines (77 loc) 2.8 kB
"use strict"; 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: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__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: true }), mod); var RouteInfoContext_exports = {}; __export(RouteInfoContext_exports, { RouteInfoContext: () => RouteInfoContext, RouteInfoContextProvider: () => RouteInfoContextProvider }); module.exports = __toCommonJS(RouteInfoContext_exports); var import_jsx_runtime = require("react/jsx-runtime"); var import_core = require("@react-navigation/core"); var import_react = require("react"); var import_getRouteInfo = require("./getRouteInfo.native.js"); var RouteInfoContext = /* @__PURE__ */(0, import_react.createContext)(void 0); function RouteInfoContextProvider(param) { var { children } = param; var currentState = (0, import_core.useStateForPath)(); var currentStateRef = (0, import_react.useRef)(void 0); var lastStateRef = (0, import_react.useRef)(void 0); var cachedRouteInfoValueRef = (0, import_react.useRef)(void 0); var lazilyCalculatedRouteInfo = (0, import_react.useRef)(void 0); if (currentState && currentStateRef.current !== currentState) { lazilyCalculatedRouteInfo.current = makeLazilyCalculatedRouteInfo({ currentStateRef, lastStateRef, cachedRouteInfoValueRef }); } currentStateRef.current = currentState; return /* @__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"); } if (!cachedRouteInfoValueRef.current || lastStateRef.current !== state) { cachedRouteInfoValueRef.current = (0, import_getRouteInfo.getRouteInfo)(state); lastStateRef.current = state; } return cachedRouteInfoValueRef.current[p]; } }); } //# sourceMappingURL=RouteInfoContext.native.js.map