repoweaver
Version:
A GitHub App that skillfully weaves multiple templates together to create and update repositories with intelligent merge strategies
1 lines • 5.8 kB
JSON
{"ast":null,"code":"\"use strict\";\n\nimport * as React from 'react';\nimport useLatestCallback from 'use-latest-callback';\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector';\nimport { useClientLayoutEffect } from \"./useClientLayoutEffect.js\";\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nexport function useNavigationState(selector) {\n const stateListener = React.useContext(NavigationStateListenerContext);\n if (stateListener == null) {\n throw new Error(\"Couldn't get the navigation state. Is your component inside a navigator?\");\n }\n const value = useSyncExternalStoreWithSelector(stateListener.subscribe, stateListener.getState, stateListener.getState, selector);\n return value;\n}\nexport function NavigationStateListenerProvider({\n state,\n children\n}) {\n const listeners = React.useRef([]);\n const getState = useLatestCallback(() => state);\n const subscribe = useLatestCallback(callback => {\n listeners.current.push(callback);\n return () => {\n listeners.current = listeners.current.filter(cb => cb !== callback);\n };\n });\n useClientLayoutEffect(() => {\n listeners.current.forEach(callback => callback());\n }, [state]);\n const context = React.useMemo(() => ({\n getState,\n subscribe\n }), [getState, subscribe]);\n return _jsx(NavigationStateListenerContext.Provider, {\n value: context,\n children: children\n });\n}\nconst NavigationStateListenerContext = React.createContext(undefined);","map":{"version":3,"names":["React","useLatestCallback","useSyncExternalStoreWithSelector","useClientLayoutEffect","jsx","_jsx","useNavigationState","selector","stateListener","useContext","NavigationStateListenerContext","Error","value","subscribe","getState","NavigationStateListenerProvider","state","children","listeners","useRef","callback","current","push","filter","cb","forEach","context","useMemo","Provider","createContext","undefined"],"sources":["/Users/pmouli/Documents/GitHub.nosync/boots-strapper/mobile/node_modules/@react-navigation/core/src/useNavigationState.tsx"],"sourcesContent":["import type { NavigationState, ParamListBase } from '@react-navigation/routers';\nimport * as React from 'react';\nimport useLatestCallback from 'use-latest-callback';\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/with-selector';\n\nimport { useClientLayoutEffect } from './useClientLayoutEffect';\n\ntype Selector<ParamList extends ParamListBase, T> = (\n state: NavigationState<ParamList>\n) => T;\n\n/**\n * Hook to get a value from the current navigation state using a selector.\n *\n * @param selector Selector function to get a value from the state.\n */\nexport function useNavigationState<ParamList extends ParamListBase, T>(\n selector: Selector<ParamList, T>\n): T {\n const stateListener = React.useContext(NavigationStateListenerContext);\n\n if (stateListener == null) {\n throw new Error(\n \"Couldn't get the navigation state. Is your component inside a navigator?\"\n );\n }\n\n const value = useSyncExternalStoreWithSelector(\n stateListener.subscribe,\n // @ts-expect-error: this is unsafe, but needed to make the generic work\n stateListener.getState,\n stateListener.getState,\n selector\n );\n\n return value;\n}\n\nexport function NavigationStateListenerProvider({\n state,\n children,\n}: {\n state: NavigationState<ParamListBase>;\n children: React.ReactNode;\n}) {\n const listeners = React.useRef<(() => void)[]>([]);\n\n const getState = useLatestCallback(() => state);\n\n const subscribe = useLatestCallback((callback: () => void) => {\n listeners.current.push(callback);\n\n return () => {\n listeners.current = listeners.current.filter((cb) => cb !== callback);\n };\n });\n\n useClientLayoutEffect(() => {\n listeners.current.forEach((callback) => callback());\n }, [state]);\n\n const context = React.useMemo(\n () => ({\n getState,\n subscribe,\n }),\n [getState, subscribe]\n );\n\n return (\n <NavigationStateListenerContext.Provider value={context}>\n {children}\n </NavigationStateListenerContext.Provider>\n );\n}\n\nconst NavigationStateListenerContext = React.createContext<\n | {\n getState: () => NavigationState<ParamListBase>;\n subscribe: (callback: () => void) => () => void;\n }\n | undefined\n>(undefined);\n"],"mappings":";;AACA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,OAAOC,iBAAiB,MAAM,qBAAqB;AACnD,SAASC,gCAAgC,QAAQ,uCAAuC;AAExF,SAASC,qBAAqB;AAAkC,SAAAC,GAAA,IAAAC,IAAA;AAWhE,OAAO,SAASC,kBAAkBA,CAChCC,QAAgC,EAC7B;EACH,MAAMC,aAAa,GAAGR,KAAK,CAACS,UAAU,CAACC,8BAA8B,CAAC;EAEtE,IAAIF,a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