GT2/Ejectable/node_modules/@react-navigation/routers/lib/commonjs/BaseRouter.js.map

1 line
3.9 KiB
Plaintext
Raw Normal View History

2021-08-16 00:14:59 +00:00
{"version":3,"sources":["BaseRouter.tsx"],"names":["BaseRouter","getStateForAction","state","action","type","index","source","routes","findIndex","r","key","map","i","params","payload","nextState","length","some","route","routeNames","includes","name","stale","shouldActionChangeFocus"],"mappings":";;;;;;;AAAA;;AAOA;AACA;AACA;AACA;AACA,MAAMA,UAAU,GAAG;AACjBC,EAAAA,iBAAiB,CACfC,KADe,EAEfC,MAFe,EAGqB;AACpC,YAAQA,MAAM,CAACC,IAAf;AACE,WAAK,YAAL;AAAmB;AACjB,gBAAMC,KAAK,GAAGF,MAAM,CAACG,MAAP,GACVJ,KAAK,CAACK,MAAN,CAAaC,SAAb,CAAwBC,CAAD,IAAOA,CAAC,CAACC,GAAF,KAAUP,MAAM,CAACG,MAA/C,CADU,GAEVJ,KAAK,CAACG,KAFV;;AAIA,cAAIA,KAAK,KAAK,CAAC,CAAf,EAAkB;AAChB,mBAAO,IAAP;AACD;;AAED,iBAAO,EACL,GAAGH,KADE;AAELK,YAAAA,MAAM,EAAEL,KAAK,CAACK,MAAN,CAAaI,GAAb,CAAiB,CAACF,CAAD,EAAIG,CAAJ,KACvBA,CAAC,KAAKP,KAAN,GACI,EAAE,GAAGI,CAAL;AAAQI,cAAAA,MAAM,EAAE,EAAE,GAAGJ,CAAC,CAACI,MAAP;AAAe,mBAAGV,MAAM,CAACW,OAAP,CAAeD;AAAjC;AAAhB,aADJ,GAEIJ,CAHE;AAFH,WAAP;AAQD;;AAED,WAAK,OAAL;AAAc;AACZ,gBAAMM,SAAS,GAAGZ,MAAM,CAACW,OAAzB;;AAEA,cACEC,SAAS,CAACR,MAAV,CAAiBS,MAAjB,KAA4B,CAA5B,IACAD,SAAS,CAACR,MAAV,CAAiBU,IAAjB,CACGC,KAAD,IAA6B,CAAChB,KAAK,CAACiB,UAAN,CAAiBC,QAAjB,CAA0BF,KAAK,CAACG,IAAhC,CADhC,CAFF,EAKE;AACA,mBAAO,IAAP;AACD;;AAED,cAAIN,SAAS,CAACO,KAAV,KAAoB,KAAxB,EAA+B;AAC7B,gBACEpB,KAAK,CAACiB,UAAN,CAAiBH,MAAjB,KAA4BD,SAAS,CAACI,UAAV,CAAqBH,MAAjD,IACAD,SAAS,CAACI,UAAV,CAAqBF,IAArB,CACGI,IAAD,IAAU,CAACnB,KAAK,CAACiB,UAAN,CAAiBC,QAAjB,CAA0BC,IAA1B,CADb,CAFF,EAKE;AACA,qBAAO,IAAP;AACD;;AAED,mBAAO,EACL,GAAGN,SADE;AAELR,cAAAA,MAAM,EAAEQ,SAAS,CAACR,MAAV,CAAiBI,GAAjB,CAAsBO,KAAD,IAC3BA,KAAK,CAACR,GAAN,GAAYQ,KAAZ,GAAoB,EAAE,GAAGA,KAAL;AAAYR,gBAAAA,GAAG,YAAKQ,KAAK,CAACG,IAAX,cAAmB,wBAAnB;AAAf,eADd;AAFH,aAAP;AAMD;;AAED,iBAAON,SAAP;AACD;;AAED;AACE,eAAO,IAAP;AAtDJ;AAwDD,GA7DgB;;AA+DjBQ,EAAAA,uBAAuB,CAACpB,MAAD,EAAiC;AACtD,WAAOA,MAAM,CAACC,IAAP,KAAgB,UAAvB;AACD;;AAjEgB,CAAnB;eAoEeJ,U","sourcesContent":["import { nanoid } from 'nanoid/non-secure';\nimport type {\n CommonNavigationAction,\n NavigationState,\n PartialState,\n} from './types';\n\n/**\n * Base router object that can be used when writing custom routers.\n * This provides few helper methods to handle common actions such as `RESET`.\n */\nconst BaseRouter = {\n getStateForAction<State extends NavigationState>(\n state: State,\n action: CommonNavigationAction\n ): State | PartialState<State> | null {\n switch (action.type) {\n case 'SET_PARAMS': {\n const index = action.source\n ? state.routes.findIndex((r) => r.key === action.source)\n : state.index;\n\n if (index === -1) {\n return null;\n }\n\n return {\n ...state,\n routes: state.routes.map((r, i) =>\n i === index\n ? { ...r, params: { ...r.params, ...action.payload.params } }\n : r\n ),\n };\n }\n\n case 'RESET': {\n const nextState = action.payload as State | PartialState<State>;\n\n if (\n nextState.routes.length === 0 ||\n nextState.routes.some(\n (route: { name: string }) => !state.routeNames.includes(route.name)\n )\n ) {\n return null;\n }\n\n if (nextState.stale === false) {\n if (\n state.routeNames.length !== nextState.routeNames.length ||\n nextState.routeNames.some(\n (name) => !state.routeNames.includes(name)\n )\n ) {\n return null;\n }\n\n return {\n ...nextState,\n routes: nextState.routes.map((route) =>\n route.key ? route : { ...route, key: `${route.name}-${nanoid()}` }\n ),\n };\n }\n\n return nextState;\n }\n\n default:\n return null;\n }\n },\n\n shouldActionChangeFocus(action: CommonNavigationAction) {\n return action.type === 'NAVIGATE';\n },\n};\n\nexport default BaseRouter;\n"]}