b929b3728dfd2482bdd3c1b86d0ce528.json 3.63 KB
{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\n/**\n * Similar with `useLock`, but this hook will always execute last value.\n * When set to `true`, it will keep `true` for a short time even if `false` is set.\n */\n\nexport default function useDelayReset() {\n  var timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;\n\n  var _React$useState = React.useState(false),\n      _React$useState2 = _slicedToArray(_React$useState, 2),\n      bool = _React$useState2[0],\n      setBool = _React$useState2[1];\n\n  var delayRef = React.useRef(null);\n\n  var cancelLatest = function cancelLatest() {\n    window.clearTimeout(delayRef.current);\n  };\n\n  React.useEffect(function () {\n    return cancelLatest;\n  }, []);\n\n  var delaySetBool = function delaySetBool(value, callback) {\n    cancelLatest();\n    delayRef.current = window.setTimeout(function () {\n      setBool(value);\n\n      if (callback) {\n        callback();\n      }\n    }, timeout);\n  };\n\n  return [bool, delaySetBool, cancelLatest];\n}","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/rc-select/es/hooks/useDelayReset.js"],"names":["_slicedToArray","React","useDelayReset","timeout","arguments","length","undefined","_React$useState","useState","_React$useState2","bool","setBool","delayRef","useRef","cancelLatest","window","clearTimeout","current","useEffect","delaySetBool","value","callback","setTimeout"],"mappings":"AAAA,OAAOA,cAAP,MAA2B,0CAA3B;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA;AACA;AACA;AACA;;AAEA,eAAe,SAASC,aAAT,GAAyB;AACtC,MAAIC,OAAO,GAAGC,SAAS,CAACC,MAAV,GAAmB,CAAnB,IAAwBD,SAAS,CAAC,CAAD,CAAT,KAAiBE,SAAzC,GAAqDF,SAAS,CAAC,CAAD,CAA9D,GAAoE,EAAlF;;AAEA,MAAIG,eAAe,GAAGN,KAAK,CAACO,QAAN,CAAe,KAAf,CAAtB;AAAA,MACIC,gBAAgB,GAAGT,cAAc,CAACO,eAAD,EAAkB,CAAlB,CADrC;AAAA,MAEIG,IAAI,GAAGD,gBAAgB,CAAC,CAAD,CAF3B;AAAA,MAGIE,OAAO,GAAGF,gBAAgB,CAAC,CAAD,CAH9B;;AAKA,MAAIG,QAAQ,GAAGX,KAAK,CAACY,MAAN,CAAa,IAAb,CAAf;;AAEA,MAAIC,YAAY,GAAG,SAASA,YAAT,GAAwB;AACzCC,IAAAA,MAAM,CAACC,YAAP,CAAoBJ,QAAQ,CAACK,OAA7B;AACD,GAFD;;AAIAhB,EAAAA,KAAK,CAACiB,SAAN,CAAgB,YAAY;AAC1B,WAAOJ,YAAP;AACD,GAFD,EAEG,EAFH;;AAIA,MAAIK,YAAY,GAAG,SAASA,YAAT,CAAsBC,KAAtB,EAA6BC,QAA7B,EAAuC;AACxDP,IAAAA,YAAY;AACZF,IAAAA,QAAQ,CAACK,OAAT,GAAmBF,MAAM,CAACO,UAAP,CAAkB,YAAY;AAC/CX,MAAAA,OAAO,CAACS,KAAD,CAAP;;AAEA,UAAIC,QAAJ,EAAc;AACZA,QAAAA,QAAQ;AACT;AACF,KANkB,EAMhBlB,OANgB,CAAnB;AAOD,GATD;;AAWA,SAAO,CAACO,IAAD,EAAOS,YAAP,EAAqBL,YAArB,CAAP;AACD","sourcesContent":["import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\n/**\n * Similar with `useLock`, but this hook will always execute last value.\n * When set to `true`, it will keep `true` for a short time even if `false` is set.\n */\n\nexport default function useDelayReset() {\n  var timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;\n\n  var _React$useState = React.useState(false),\n      _React$useState2 = _slicedToArray(_React$useState, 2),\n      bool = _React$useState2[0],\n      setBool = _React$useState2[1];\n\n  var delayRef = React.useRef(null);\n\n  var cancelLatest = function cancelLatest() {\n    window.clearTimeout(delayRef.current);\n  };\n\n  React.useEffect(function () {\n    return cancelLatest;\n  }, []);\n\n  var delaySetBool = function delaySetBool(value, callback) {\n    cancelLatest();\n    delayRef.current = window.setTimeout(function () {\n      setBool(value);\n\n      if (callback) {\n        callback();\n      }\n    }, timeout);\n  };\n\n  return [bool, delaySetBool, cancelLatest];\n}"]},"metadata":{},"sourceType":"module"}