UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

48 lines (45 loc) • 1.63 kB
import { getActionFromState } from "@react-navigation/native"; import { getReactNavigationConfig } from "../getReactNavigationConfig.mjs"; import { addEventListener, getDefaultLinkingPrefixes, getInitialURL, getPathFromState, getStateFromPath } from "../link/linking.mjs"; import { normalizeLinkingConfig } from "../link/getLinking.mjs"; import { evictOldest } from "../utils/evictOldest.mjs"; function getNavigationConfig(routes, metaOnly = true) { return getReactNavigationConfig(routes, metaOnly); } function getLinkingConfig(routes, metaOnly = true, linking) { const config = getNavigationConfig(routes, metaOnly); const resolvedLinking = normalizeLinkingConfig(linking, getDefaultLinkingPrefixes()); return { prefixes: resolvedLinking.prefixes, filter: resolvedLinking.filter, config, getInitialURL, subscribe: addEventListener, getStateFromPath: getStateFromPathMemoized, getPathFromState(state, options) { return getPathFromState(state, { ...config, ...options }) ?? "/"; }, getActionFromState }; } const stateCache = /* @__PURE__ */ new Map(); const STATE_CACHE_THRESHOLD = 5e3; const STATE_CACHE_EVICTION = 1e3; function clearStateCache() { stateCache.clear(); } function getStateFromPathMemoized(path, options) { const cached = stateCache.get(path); if (cached) { return cached; } const result = getStateFromPath(path, options); evictOldest(stateCache, STATE_CACHE_THRESHOLD, STATE_CACHE_EVICTION); stateCache.set(path, result); return result; } export { clearStateCache, getLinkingConfig, getNavigationConfig, stateCache }; //# sourceMappingURL=getLinkingConfig.mjs.map