c18a7cca94bab1b83a6ed0adf22072ad.json
4.07 KB
{"ast":null,"code":"import * as React from 'react';\nimport useForceUpdate from '../../_util/hooks/useForceUpdate';\n/**\n * Always debounce error to avoid [error -> null -> error] blink\n */\n\nexport default function useCacheErrors(errors, changeTrigger, directly) {\n var cacheRef = React.useRef({\n errors: errors,\n visible: !!errors.length\n });\n var forceUpdate = useForceUpdate();\n\n var update = function update() {\n var prevVisible = cacheRef.current.visible;\n var newVisible = !!errors.length;\n var prevErrors = cacheRef.current.errors;\n cacheRef.current.errors = errors;\n cacheRef.current.visible = newVisible;\n\n if (prevVisible !== newVisible) {\n changeTrigger(newVisible);\n } else if (prevErrors.length !== errors.length || prevErrors.some(function (prevErr, index) {\n return prevErr !== errors[index];\n })) {\n forceUpdate();\n }\n };\n\n React.useEffect(function () {\n if (!directly) {\n var timeout = setTimeout(update, 10);\n return function () {\n return clearTimeout(timeout);\n };\n }\n }, [errors]);\n\n if (directly) {\n update();\n }\n\n return [cacheRef.current.visible, cacheRef.current.errors];\n}","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/antd/es/form/hooks/useCacheErrors.js"],"names":["React","useForceUpdate","useCacheErrors","errors","changeTrigger","directly","cacheRef","useRef","visible","length","forceUpdate","update","prevVisible","current","newVisible","prevErrors","some","prevErr","index","useEffect","timeout","setTimeout","clearTimeout"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,OAAOC,cAAP,MAA2B,kCAA3B;AACA;AACA;AACA;;AAEA,eAAe,SAASC,cAAT,CAAwBC,MAAxB,EAAgCC,aAAhC,EAA+CC,QAA/C,EAAyD;AACtE,MAAIC,QAAQ,GAAGN,KAAK,CAACO,MAAN,CAAa;AAC1BJ,IAAAA,MAAM,EAAEA,MADkB;AAE1BK,IAAAA,OAAO,EAAE,CAAC,CAACL,MAAM,CAACM;AAFQ,GAAb,CAAf;AAIA,MAAIC,WAAW,GAAGT,cAAc,EAAhC;;AAEA,MAAIU,MAAM,GAAG,SAASA,MAAT,GAAkB;AAC7B,QAAIC,WAAW,GAAGN,QAAQ,CAACO,OAAT,CAAiBL,OAAnC;AACA,QAAIM,UAAU,GAAG,CAAC,CAACX,MAAM,CAACM,MAA1B;AACA,QAAIM,UAAU,GAAGT,QAAQ,CAACO,OAAT,CAAiBV,MAAlC;AACAG,IAAAA,QAAQ,CAACO,OAAT,CAAiBV,MAAjB,GAA0BA,MAA1B;AACAG,IAAAA,QAAQ,CAACO,OAAT,CAAiBL,OAAjB,GAA2BM,UAA3B;;AAEA,QAAIF,WAAW,KAAKE,UAApB,EAAgC;AAC9BV,MAAAA,aAAa,CAACU,UAAD,CAAb;AACD,KAFD,MAEO,IAAIC,UAAU,CAACN,MAAX,KAAsBN,MAAM,CAACM,MAA7B,IAAuCM,UAAU,CAACC,IAAX,CAAgB,UAAUC,OAAV,EAAmBC,KAAnB,EAA0B;AAC1F,aAAOD,OAAO,KAAKd,MAAM,CAACe,KAAD,CAAzB;AACD,KAFiD,CAA3C,EAEH;AACFR,MAAAA,WAAW;AACZ;AACF,GAdD;;AAgBAV,EAAAA,KAAK,CAACmB,SAAN,CAAgB,YAAY;AAC1B,QAAI,CAACd,QAAL,EAAe;AACb,UAAIe,OAAO,GAAGC,UAAU,CAACV,MAAD,EAAS,EAAT,CAAxB;AACA,aAAO,YAAY;AACjB,eAAOW,YAAY,CAACF,OAAD,CAAnB;AACD,OAFD;AAGD;AACF,GAPD,EAOG,CAACjB,MAAD,CAPH;;AASA,MAAIE,QAAJ,EAAc;AACZM,IAAAA,MAAM;AACP;;AAED,SAAO,CAACL,QAAQ,CAACO,OAAT,CAAiBL,OAAlB,EAA2BF,QAAQ,CAACO,OAAT,CAAiBV,MAA5C,CAAP;AACD","sourcesContent":["import * as React from 'react';\nimport useForceUpdate from '../../_util/hooks/useForceUpdate';\n/**\n * Always debounce error to avoid [error -> null -> error] blink\n */\n\nexport default function useCacheErrors(errors, changeTrigger, directly) {\n var cacheRef = React.useRef({\n errors: errors,\n visible: !!errors.length\n });\n var forceUpdate = useForceUpdate();\n\n var update = function update() {\n var prevVisible = cacheRef.current.visible;\n var newVisible = !!errors.length;\n var prevErrors = cacheRef.current.errors;\n cacheRef.current.errors = errors;\n cacheRef.current.visible = newVisible;\n\n if (prevVisible !== newVisible) {\n changeTrigger(newVisible);\n } else if (prevErrors.length !== errors.length || prevErrors.some(function (prevErr, index) {\n return prevErr !== errors[index];\n })) {\n forceUpdate();\n }\n };\n\n React.useEffect(function () {\n if (!directly) {\n var timeout = setTimeout(update, 10);\n return function () {\n return clearTimeout(timeout);\n };\n }\n }, [errors]);\n\n if (directly) {\n update();\n }\n\n return [cacheRef.current.visible, cacheRef.current.errors];\n}"]},"metadata":{},"sourceType":"module"}