1122920423db3f56d81b17ce3533d916.json
6.45 KB
{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { STEP_PREPARE, STEP_ACTIVE, STEP_START, STEP_ACTIVATED, STEP_NONE } from '../interface';\nimport useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';\nimport useNextFrame from './useNextFrame';\nvar STEP_QUEUE = [STEP_PREPARE, STEP_START, STEP_ACTIVE, STEP_ACTIVATED];\n/** Skip current step */\n\nexport var SkipStep = false;\n/** Current step should be update in */\n\nexport var DoStep = true;\nexport function isActive(step) {\n return step === STEP_ACTIVE || step === STEP_ACTIVATED;\n}\nexport default (function (status, callback) {\n var _React$useState = React.useState(STEP_NONE),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n step = _React$useState2[0],\n setStep = _React$useState2[1];\n\n var _useNextFrame = useNextFrame(),\n _useNextFrame2 = _slicedToArray(_useNextFrame, 2),\n nextFrame = _useNextFrame2[0],\n cancelNextFrame = _useNextFrame2[1];\n\n function startQueue() {\n setStep(STEP_PREPARE);\n }\n\n useIsomorphicLayoutEffect(function () {\n if (step !== STEP_NONE && step !== STEP_ACTIVATED) {\n var index = STEP_QUEUE.indexOf(step);\n var nextStep = STEP_QUEUE[index + 1];\n var result = callback(step);\n\n if (result === SkipStep) {\n // Skip when no needed\n setStep(nextStep);\n } else {\n // Do as frame for step update\n nextFrame(function (info) {\n function doNext() {\n // Skip since current queue is ood\n if (info.isCanceled()) return;\n setStep(nextStep);\n }\n\n if (result === true) {\n doNext();\n } else {\n // Only promise should be async\n Promise.resolve(result).then(doNext);\n }\n });\n }\n }\n }, [status, step]);\n React.useEffect(function () {\n return function () {\n cancelNextFrame();\n };\n }, []);\n return [startQueue, step];\n});","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/rc-motion/es/hooks/useStepQueue.js"],"names":["_slicedToArray","React","STEP_PREPARE","STEP_ACTIVE","STEP_START","STEP_ACTIVATED","STEP_NONE","useIsomorphicLayoutEffect","useNextFrame","STEP_QUEUE","SkipStep","DoStep","isActive","step","status","callback","_React$useState","useState","_React$useState2","setStep","_useNextFrame","_useNextFrame2","nextFrame","cancelNextFrame","startQueue","index","indexOf","nextStep","result","info","doNext","isCanceled","Promise","resolve","then","useEffect"],"mappings":"AAAA,OAAOA,cAAP,MAA2B,0CAA3B;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SAASC,YAAT,EAAuBC,WAAvB,EAAoCC,UAApC,EAAgDC,cAAhD,EAAgEC,SAAhE,QAAiF,cAAjF;AACA,OAAOC,yBAAP,MAAsC,6BAAtC;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AACA,IAAIC,UAAU,GAAG,CAACP,YAAD,EAAeE,UAAf,EAA2BD,WAA3B,EAAwCE,cAAxC,CAAjB;AACA;;AAEA,OAAO,IAAIK,QAAQ,GAAG,KAAf;AACP;;AAEA,OAAO,IAAIC,MAAM,GAAG,IAAb;AACP,OAAO,SAASC,QAAT,CAAkBC,IAAlB,EAAwB;AAC7B,SAAOA,IAAI,KAAKV,WAAT,IAAwBU,IAAI,KAAKR,cAAxC;AACD;AACD,gBAAgB,UAAUS,MAAV,EAAkBC,QAAlB,EAA4B;AAC1C,MAAIC,eAAe,GAAGf,KAAK,CAACgB,QAAN,CAAeX,SAAf,CAAtB;AAAA,MACIY,gBAAgB,GAAGlB,cAAc,CAACgB,eAAD,EAAkB,CAAlB,CADrC;AAAA,MAEIH,IAAI,GAAGK,gBAAgB,CAAC,CAAD,CAF3B;AAAA,MAGIC,OAAO,GAAGD,gBAAgB,CAAC,CAAD,CAH9B;;AAKA,MAAIE,aAAa,GAAGZ,YAAY,EAAhC;AAAA,MACIa,cAAc,GAAGrB,cAAc,CAACoB,aAAD,EAAgB,CAAhB,CADnC;AAAA,MAEIE,SAAS,GAAGD,cAAc,CAAC,CAAD,CAF9B;AAAA,MAGIE,eAAe,GAAGF,cAAc,CAAC,CAAD,CAHpC;;AAKA,WAASG,UAAT,GAAsB;AACpBL,IAAAA,OAAO,CAACjB,YAAD,CAAP;AACD;;AAEDK,EAAAA,yBAAyB,CAAC,YAAY;AACpC,QAAIM,IAAI,KAAKP,SAAT,IAAsBO,IAAI,KAAKR,cAAnC,EAAmD;AACjD,UAAIoB,KAAK,GAAGhB,UAAU,CAACiB,OAAX,CAAmBb,IAAnB,CAAZ;AACA,UAAIc,QAAQ,GAAGlB,UAAU,CAACgB,KAAK,GAAG,CAAT,CAAzB;AACA,UAAIG,MAAM,GAAGb,QAAQ,CAACF,IAAD,CAArB;;AAEA,UAAIe,MAAM,KAAKlB,QAAf,EAAyB;AACvB;AACAS,QAAAA,OAAO,CAACQ,QAAD,CAAP;AACD,OAHD,MAGO;AACL;AACAL,QAAAA,SAAS,CAAC,UAAUO,IAAV,EAAgB;AACxB,mBAASC,MAAT,GAAkB;AAChB;AACA,gBAAID,IAAI,CAACE,UAAL,EAAJ,EAAuB;AACvBZ,YAAAA,OAAO,CAACQ,QAAD,CAAP;AACD;;AAED,cAAIC,MAAM,KAAK,IAAf,EAAqB;AACnBE,YAAAA,MAAM;AACP,WAFD,MAEO;AACL;AACAE,YAAAA,OAAO,CAACC,OAAR,CAAgBL,MAAhB,EAAwBM,IAAxB,CAA6BJ,MAA7B;AACD;AACF,SAbQ,CAAT;AAcD;AACF;AACF,GA3BwB,EA2BtB,CAAChB,MAAD,EAASD,IAAT,CA3BsB,CAAzB;AA4BAZ,EAAAA,KAAK,CAACkC,SAAN,CAAgB,YAAY;AAC1B,WAAO,YAAY;AACjBZ,MAAAA,eAAe;AAChB,KAFD;AAGD,GAJD,EAIG,EAJH;AAKA,SAAO,CAACC,UAAD,EAAaX,IAAb,CAAP;AACD,CAjDD","sourcesContent":["import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport { STEP_PREPARE, STEP_ACTIVE, STEP_START, STEP_ACTIVATED, STEP_NONE } from '../interface';\nimport useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';\nimport useNextFrame from './useNextFrame';\nvar STEP_QUEUE = [STEP_PREPARE, STEP_START, STEP_ACTIVE, STEP_ACTIVATED];\n/** Skip current step */\n\nexport var SkipStep = false;\n/** Current step should be update in */\n\nexport var DoStep = true;\nexport function isActive(step) {\n return step === STEP_ACTIVE || step === STEP_ACTIVATED;\n}\nexport default (function (status, callback) {\n var _React$useState = React.useState(STEP_NONE),\n _React$useState2 = _slicedToArray(_React$useState, 2),\n step = _React$useState2[0],\n setStep = _React$useState2[1];\n\n var _useNextFrame = useNextFrame(),\n _useNextFrame2 = _slicedToArray(_useNextFrame, 2),\n nextFrame = _useNextFrame2[0],\n cancelNextFrame = _useNextFrame2[1];\n\n function startQueue() {\n setStep(STEP_PREPARE);\n }\n\n useIsomorphicLayoutEffect(function () {\n if (step !== STEP_NONE && step !== STEP_ACTIVATED) {\n var index = STEP_QUEUE.indexOf(step);\n var nextStep = STEP_QUEUE[index + 1];\n var result = callback(step);\n\n if (result === SkipStep) {\n // Skip when no needed\n setStep(nextStep);\n } else {\n // Do as frame for step update\n nextFrame(function (info) {\n function doNext() {\n // Skip since current queue is ood\n if (info.isCanceled()) return;\n setStep(nextStep);\n }\n\n if (result === true) {\n doNext();\n } else {\n // Only promise should be async\n Promise.resolve(result).then(doNext);\n }\n });\n }\n }\n }, [status, step]);\n React.useEffect(function () {\n return function () {\n cancelNextFrame();\n };\n }, []);\n return [startQueue, step];\n});"]},"metadata":{},"sourceType":"module"}