You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
5.5 KiB

{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/defineProperty\";\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }\nimport * as React from 'react';\nimport isArrayEqual from \"./isArrayEqual\";\nimport NavigationBuilderContext from \"./NavigationBuilderContext\";\nimport NavigationRouteContext from \"./NavigationRouteContext\";\nexport default function useOnGetState(_ref) {\n var getState = _ref.getState,\n getStateListeners = _ref.getStateListeners;\n var _React$useContext = React.useContext(NavigationBuilderContext),\n addKeyedListener = _React$useContext.addKeyedListener;\n var route = React.useContext(NavigationRouteContext);\n var key = route ? route.key : 'root';\n var getRehydratedState = React.useCallback(function () {\n var state = getState();\n var routes = state.routes.map(function (route) {\n var _getStateListeners$ro;\n var childState = (_getStateListeners$ro = getStateListeners[route.key]) === null || _getStateListeners$ro === void 0 ? void 0 : _getStateListeners$ro.call(getStateListeners);\n if (route.state === childState) {\n return route;\n }\n return _objectSpread(_objectSpread({}, route), {}, {\n state: childState\n });\n });\n if (isArrayEqual(state.routes, routes)) {\n return state;\n }\n return _objectSpread(_objectSpread({}, state), {}, {\n routes: routes\n });\n }, [getState, getStateListeners]);\n React.useEffect(function () {\n return addKeyedListener === null || addKeyedListener === void 0 ? void 0 : addKeyedListener('getState', key, getRehydratedState);\n }, [addKeyedListener, getRehydratedState, key]);\n}","map":{"version":3,"sources":["useOnGetState.tsx"],"names":["React","isArrayEqual","NavigationBuilderContext","NavigationRouteContext","useOnGetState","getState","getStateListeners","addKeyedListener","useContext","route","key","getRehydratedState","useCallback","state","routes","map","childState","useEffect"],"mappings":";;;AACA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,OAAOC,YAAY;AACnB,OAAOC,wBAAwB;AAG/B,OAAOC,sBAAsB;AAO7B,eAAe,SAASC,aAAa,CAAA,IAAA,EAGzB;EAH0B,IACpCC,QAAQ,GAEA,IAAA,CAFRA,QAAQ;IACRC,iBAAAA,GACQ,IAAA,CADRA,iBAAAA;EAEA,wBAA6BN,KAAK,CAACQ,UAAU,CAACN,wBAAwB,CAAC;IAA/DK,gBAAAA,qBAAAA,gBAAAA;EACR,IAAME,KAAK,GAAGT,KAAK,CAACQ,UAAU,CAACL,sBAAsB,CAAC;EACtD,IAAMO,GAAG,GAAGD,KAAK,GAAGA,KAAK,CAACC,GAAG,GAAG,MAAM;EAEtC,IAAMC,kBAAkB,GAAGX,KAAK,CAACY,WAAW,CAAC,YAAM;IACjD,IAAMC,KAAK,GAAGR,QAAQ,EAAE;IAGxB,IAAMS,MAAM,GAAGD,KAAK,CAACC,MAAM,CAACC,GAAG,CAAEN,UAAAA,KAAK,EAAK;MAAA,IAAA,qBAAA;MACzC,IAAMO,UAAU,GAAA,CAAA,qBAAA,GAAGV,iBAAiB,CAACG,KAAK,CAACC,GAAG,CAAC,MAAA,IAAA,IAAA,qBAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAA5BJ,qBAAAA,CAAAA,IAAAA,CAAAA,iBAAiB,CAAe;MAEnD,IAAIG,KAAK,CAACI,KAAK,KAAKG,UAAU,EAAE;QAC9B,OAAOP,KAAK;MACd;MAEA,uCAAYA,KAAK;QAAEI,KAAK,EAAEG;MAAAA;IAC5B,CAAC,CAAC;IAEF,IAAIf,YAAY,CAACY,KAAK,CAACC,MAAM,EAAEA,MAAM,CAAC,EAAE;MACtC,OAAOD,KAAK;IACd;IAEA,uCAAYA,KAAK;MAAEC,MAAAA,EAAAA;IAAAA;EACrB,CAAC,EAAE,CAACT,QAAQ,EAAEC,iBAAiB,CAAC,CAAC;EAEjCN,KAAK,CAACiB,SAAS,CAAC,YAAM;IACpB,OAAOV,gBAAgB,KAAA,IAAA,IAAhBA,gBAAgB,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAhBA,gBAAgB,CAAG,UAAU,EAAEG,GAAG,EAAEC,kBAAkB,CAAC;EAChE,CAAC,EAAE,CAACJ,gBAAgB,EAAEI,kBAAkB,EAAED,GAAG,CAAC,CAAC;AACjD","sourceRoot":"../../src","sourcesContent":["import * as React from 'react';\nimport isArrayEqual from './isArrayEqual';\nimport NavigationBuilderContext from './NavigationBuilderContext';\nimport NavigationRouteContext from './NavigationRouteContext';\nexport default function useOnGetState(_ref) {\n let {\n getState,\n getStateListeners\n } = _ref;\n const {\n addKeyedListener\n } = React.useContext(NavigationBuilderContext);\n const route = React.useContext(NavigationRouteContext);\n const key = route ? route.key : 'root';\n const getRehydratedState = React.useCallback(() => {\n const state = getState();\n\n // Avoid returning new route objects if we don't need to\n const routes = state.routes.map(route => {\n var _getStateListeners$ro;\n const childState = (_getStateListeners$ro = getStateListeners[route.key]) === null || _getStateListeners$ro === void 0 ? void 0 : _getStateListeners$ro.call(getStateListeners);\n if (route.state === childState) {\n return route;\n }\n return {\n ...route,\n state: childState\n };\n });\n if (isArrayEqual(state.routes, routes)) {\n return state;\n }\n return {\n ...state,\n routes\n };\n }, [getState, getStateListeners]);\n React.useEffect(() => {\n return addKeyedListener === null || addKeyedListener === void 0 ? void 0 : addKeyedListener('getState', key, getRehydratedState);\n }, [addKeyedListener, getRehydratedState, key]);\n}\n//# sourceMappingURL=useOnGetState.js.map"]},"metadata":{},"sourceType":"module"}