1 line
2.0 KiB
Plaintext
1 line
2.0 KiB
Plaintext
{"version":3,"file":"index.js","sources":["../src/index.tsx"],"sourcesContent":["import React, { useRef, Suspense, Fragment } from \"react\";\n\ninterface StorageRef {\n promise?: Promise<void>;\n resolve?: (value: void | PromiseLike<void>) => void;\n}\n\nfunction Suspender({\n freeze,\n children,\n}: {\n freeze: boolean;\n children: React.ReactNode;\n}) {\n const promiseCache = useRef<StorageRef>({}).current;\n if (freeze && !promiseCache.promise) {\n promiseCache.promise = new Promise((resolve) => {\n promiseCache.resolve = resolve;\n });\n throw promiseCache.promise;\n } else if (freeze) {\n throw promiseCache.promise;\n } else if (promiseCache.promise) {\n promiseCache.resolve!();\n promiseCache.promise = undefined;\n }\n\n return <Fragment>{children}</Fragment>;\n}\n\ninterface Props {\n freeze: boolean;\n children: React.ReactNode;\n placeholder?: React.ReactNode;\n}\n\nexport function Freeze({ freeze, children, placeholder = null }: Props) {\n return (\n <Suspense fallback={placeholder}>\n <Suspender freeze={freeze}>{children}</Suspender>\n </Suspense>\n );\n}\n"],"names":["Suspender","freeze","children","promiseCache","useRef","current","promise","Promise","resolve","undefined","React","Fragment","Freeze","placeholder","Suspense","fallback"],"mappings":";;;;;AAOA,SAASA,SAAT;MACEC,cAAAA;MACAC,gBAAAA;AAKA,MAAMC,YAAY,GAAGC,YAAM,CAAa,EAAb,CAAN,CAAuBC,OAA5C;;AACA,MAAIJ,MAAM,IAAI,CAACE,YAAY,CAACG,OAA5B,EAAqC;AACnCH,IAAAA,YAAY,CAACG,OAAb,GAAuB,IAAIC,OAAJ,CAAY,UAACC,OAAD;AACjCL,MAAAA,YAAY,CAACK,OAAb,GAAuBA,OAAvB;AACD,KAFsB,CAAvB;AAGA,UAAML,YAAY,CAACG,OAAnB;AACD,GALD,MAKO,IAAIL,MAAJ,EAAY;AACjB,UAAME,YAAY,CAACG,OAAnB;AACD,GAFM,MAEA,IAAIH,YAAY,CAACG,OAAjB,EAA0B;AAC/BH,IAAAA,YAAY,CAACK,OAAb;AACAL,IAAAA,YAAY,CAACG,OAAb,GAAuBG,SAAvB;AACD;;AAED,SAAOC,4BAAA,CAACC,cAAD,MAAA,EAAWT,QAAX,CAAP;AACD;;SAQeU;MAASX,eAAAA;MAAQC,iBAAAA;gCAAUW;MAAAA,6CAAc;AACvD,SACEH,4BAAA,CAACI,cAAD;AAAUC,IAAAA,QAAQ,EAAEF;GAApB,EACEH,4BAAA,CAACV,SAAD;AAAWC,IAAAA,MAAM,EAAEA;GAAnB,EAA4BC,QAA5B,CADF,CADF;AAKD;;;;"} |