17af30280a1beb5f7be4295e87073e50.json
4.16 KB
{"ast":null,"code":"import { useRef, useEffect } from 'react';\nimport raf from \"rc-util/es/raf\";\nimport useForceUpdate from '../_util/hooks/useForceUpdate'; // Note. Only for upload usage. Do not export to global util hooks\n\nexport default function useFreshState(defaultValue, propValue) {\n var valueRef = useRef(defaultValue);\n var forceUpdate = useForceUpdate();\n var rafRef = useRef(); // Set value\n\n function setValue(newValue) {\n valueRef.current = newValue;\n forceUpdate();\n }\n\n function cleanUp() {\n raf.cancel(rafRef.current);\n }\n\n function rafSyncValue(newValue) {\n cleanUp();\n rafRef.current = raf(function () {\n setValue(newValue);\n });\n } // Get value\n\n\n function getValue() {\n var displayValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\n\n if (displayValue) {\n return propValue || valueRef.current;\n }\n\n return valueRef.current;\n } // Effect will always update in a next frame to avoid sync state overwrite current processing state\n\n\n useEffect(function () {\n if (propValue) {\n rafSyncValue(propValue);\n }\n }, [propValue]); // Clean up\n\n useEffect(function () {\n return function () {\n cleanUp();\n };\n }, []);\n return [getValue, setValue];\n}","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/antd/es/upload/useFreshState.js"],"names":["useRef","useEffect","raf","useForceUpdate","useFreshState","defaultValue","propValue","valueRef","forceUpdate","rafRef","setValue","newValue","current","cleanUp","cancel","rafSyncValue","getValue","displayValue","arguments","length","undefined"],"mappings":"AAAA,SAASA,MAAT,EAAiBC,SAAjB,QAAkC,OAAlC;AACA,OAAOC,GAAP,MAAgB,gBAAhB;AACA,OAAOC,cAAP,MAA2B,+BAA3B,C,CAA4D;;AAE5D,eAAe,SAASC,aAAT,CAAuBC,YAAvB,EAAqCC,SAArC,EAAgD;AAC7D,MAAIC,QAAQ,GAAGP,MAAM,CAACK,YAAD,CAArB;AACA,MAAIG,WAAW,GAAGL,cAAc,EAAhC;AACA,MAAIM,MAAM,GAAGT,MAAM,EAAnB,CAH6D,CAGtC;;AAEvB,WAASU,QAAT,CAAkBC,QAAlB,EAA4B;AAC1BJ,IAAAA,QAAQ,CAACK,OAAT,GAAmBD,QAAnB;AACAH,IAAAA,WAAW;AACZ;;AAED,WAASK,OAAT,GAAmB;AACjBX,IAAAA,GAAG,CAACY,MAAJ,CAAWL,MAAM,CAACG,OAAlB;AACD;;AAED,WAASG,YAAT,CAAsBJ,QAAtB,EAAgC;AAC9BE,IAAAA,OAAO;AACPJ,IAAAA,MAAM,CAACG,OAAP,GAAiBV,GAAG,CAAC,YAAY;AAC/BQ,MAAAA,QAAQ,CAACC,QAAD,CAAR;AACD,KAFmB,CAApB;AAGD,GAnB4D,CAmB3D;;;AAGF,WAASK,QAAT,GAAoB;AAClB,QAAIC,YAAY,GAAGC,SAAS,CAACC,MAAV,GAAmB,CAAnB,IAAwBD,SAAS,CAAC,CAAD,CAAT,KAAiBE,SAAzC,GAAqDF,SAAS,CAAC,CAAD,CAA9D,GAAoE,KAAvF;;AAEA,QAAID,YAAJ,EAAkB;AAChB,aAAOX,SAAS,IAAIC,QAAQ,CAACK,OAA7B;AACD;;AAED,WAAOL,QAAQ,CAACK,OAAhB;AACD,GA9B4D,CA8B3D;;;AAGFX,EAAAA,SAAS,CAAC,YAAY;AACpB,QAAIK,SAAJ,EAAe;AACbS,MAAAA,YAAY,CAACT,SAAD,CAAZ;AACD;AACF,GAJQ,EAIN,CAACA,SAAD,CAJM,CAAT,CAjC6D,CAqC5C;;AAEjBL,EAAAA,SAAS,CAAC,YAAY;AACpB,WAAO,YAAY;AACjBY,MAAAA,OAAO;AACR,KAFD;AAGD,GAJQ,EAIN,EAJM,CAAT;AAKA,SAAO,CAACG,QAAD,EAAWN,QAAX,CAAP;AACD","sourcesContent":["import { useRef, useEffect } from 'react';\nimport raf from \"rc-util/es/raf\";\nimport useForceUpdate from '../_util/hooks/useForceUpdate'; // Note. Only for upload usage. Do not export to global util hooks\n\nexport default function useFreshState(defaultValue, propValue) {\n var valueRef = useRef(defaultValue);\n var forceUpdate = useForceUpdate();\n var rafRef = useRef(); // Set value\n\n function setValue(newValue) {\n valueRef.current = newValue;\n forceUpdate();\n }\n\n function cleanUp() {\n raf.cancel(rafRef.current);\n }\n\n function rafSyncValue(newValue) {\n cleanUp();\n rafRef.current = raf(function () {\n setValue(newValue);\n });\n } // Get value\n\n\n function getValue() {\n var displayValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;\n\n if (displayValue) {\n return propValue || valueRef.current;\n }\n\n return valueRef.current;\n } // Effect will always update in a next frame to avoid sync state overwrite current processing state\n\n\n useEffect(function () {\n if (propValue) {\n rafSyncValue(propValue);\n }\n }, [propValue]); // Clean up\n\n useEffect(function () {\n return function () {\n cleanUp();\n };\n }, []);\n return [getValue, setValue];\n}"]},"metadata":{},"sourceType":"module"}