GT2/Ejectable/node_modules/@react-navigation/native/lib/module/useThenable.js.map

1 line
1.9 KiB
Plaintext
Raw Normal View History

2021-08-16 00:14:59 +00:00
{"version":3,"sources":["useThenable.tsx"],"names":["React","useThenable","create","promise","useState","initialState","undefined","then","result","state","setState","resolved","useEffect","cancelled","resolve"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,eAAe,SAASC,WAAT,CAAwBC,MAAxB,EAAsD;AACnE,QAAM,CAACC,OAAD,IAAYH,KAAK,CAACI,QAAN,CAAeF,MAAf,CAAlB;AAEA,MAAIG,YAAsC,GAAG,CAAC,KAAD,EAAQC,SAAR,CAA7C,CAHmE,CAKnE;;AACAH,EAAAA,OAAO,CAACI,IAAR,CAAcC,MAAD,IAAY;AACvBH,IAAAA,YAAY,GAAG,CAAC,IAAD,EAAOG,MAAP,CAAf;AACD,GAFD;AAIA,QAAM,CAACC,KAAD,EAAQC,QAAR,IAAoBV,KAAK,CAACI,QAAN,CAAeC,YAAf,CAA1B;AACA,QAAM,CAACM,QAAD,IAAaF,KAAnB;AAEAT,EAAAA,KAAK,CAACY,SAAN,CAAgB,MAAM;AACpB,QAAIC,SAAS,GAAG,KAAhB;;AAEA,UAAMC,OAAO,GAAG,YAAY;AAC1B,UAAIN,MAAJ;;AAEA,UAAI;AACFA,QAAAA,MAAM,GAAG,MAAML,OAAf;AACD,OAFD,SAEU;AACR,YAAI,CAACU,SAAL,EAAgB;AACdH,UAAAA,QAAQ,CAAC,CAAC,IAAD,EAAOF,MAAP,CAAD,CAAR;AACD;AACF;AACF,KAVD;;AAYA,QAAI,CAACG,QAAL,EAAe;AACbG,MAAAA,OAAO;AACR;;AAED,WAAO,MAAM;AACXD,MAAAA,SAAS,GAAG,IAAZ;AACD,KAFD;AAGD,GAtBD,EAsBG,CAACV,OAAD,EAAUQ,QAAV,CAtBH;AAwBA,SAAOF,KAAP;AACD","sourcesContent":["import * as React from 'react';\n\nexport default function useThenable<T>(create: () => PromiseLike<T>) {\n const [promise] = React.useState(create);\n\n let initialState: [boolean, T | undefined] = [false, undefined];\n\n // Check if our thenable is synchronous\n promise.then((result) => {\n initialState = [true, result];\n });\n\n const [state, setState] = React.useState(initialState);\n const [resolved] = state;\n\n React.useEffect(() => {\n let cancelled = false;\n\n const resolve = async () => {\n let result;\n\n try {\n result = await promise;\n } finally {\n if (!cancelled) {\n setState([true, result]);\n }\n }\n };\n\n if (!resolved) {\n resolve();\n }\n\n return () => {\n cancelled = true;\n };\n }, [promise, resolved]);\n\n return state;\n}\n"]}