PromoCursed/node_modules/.cache/babel-loader/4350c5609a60a9de20b29b89fd161a732469d2b3829416d72970e13e4fdfcd42.json

1 line
6.2 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"ast":null,"code":"import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport { useRef, useState, useEffect } from 'react';\n/**\n * Execute code before next frame but async\n */\nexport function useLayoutState(defaultState) {\n var stateRef = useRef(defaultState);\n var _useState = useState({}),\n _useState2 = _slicedToArray(_useState, 2),\n forceUpdate = _useState2[1];\n var lastPromiseRef = useRef(null);\n var updateBatchRef = useRef([]);\n function setFrameState(updater) {\n updateBatchRef.current.push(updater);\n var promise = Promise.resolve();\n lastPromiseRef.current = promise;\n promise.then(function () {\n if (lastPromiseRef.current === promise) {\n var prevBatch = updateBatchRef.current;\n var prevState = stateRef.current;\n updateBatchRef.current = [];\n prevBatch.forEach(function (batchUpdater) {\n stateRef.current = batchUpdater(stateRef.current);\n });\n lastPromiseRef.current = null;\n if (prevState !== stateRef.current) {\n forceUpdate({});\n }\n }\n });\n }\n useEffect(function () {\n return function () {\n lastPromiseRef.current = null;\n };\n }, []);\n return [stateRef.current, setFrameState];\n}\n\n/** Lock frame, when frame pass reset the lock. */\nexport function useTimeoutLock(defaultState) {\n var frameRef = useRef(defaultState || null);\n var timeoutRef = useRef();\n function cleanUp() {\n window.clearTimeout(timeoutRef.current);\n }\n function setState(newState) {\n frameRef.current = newState;\n cleanUp();\n timeoutRef.current = window.setTimeout(function () {\n frameRef.current = null;\n timeoutRef.current = undefined;\n }, 100);\n }\n function getState() {\n return frameRef.current;\n }\n useEffect(function () {\n return cleanUp;\n }, []);\n return [setState, getState];\n}","map":{"version":3,"names":["_slicedToArray","useRef","useState","useEffect","useLayoutState","defaultState","stateRef","_useState","_useState2","forceUpdate","lastPromiseRef","updateBatchRef","setFrameState","updater","current","push","promise","Promise","resolve","then","prevBatch","prevState","forEach","batchUpdater","useTimeoutLock","frameRef","timeoutRef","cleanUp","window","clearTimeout","setState","newState","setTimeout","undefined","getState"],"sources":["C:/Users/Аришина)/source/repos/PromoCursed/node_modules/rc-table/es/hooks/useFrame.js"],"sourcesContent":["import _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport { useRef, useState, useEffect } from 'react';\n/**\n * Execute code before next frame but async\n */\nexport function useLayoutState(defaultState) {\n var stateRef = useRef(defaultState);\n var _useState = useState({}),\n _useState2 = _slicedToArray(_useState, 2),\n forceUpdate = _useState2[1];\n var lastPromiseRef = useRef(null);\n var updateBatchRef = useRef([]);\n function setFrameState(updater) {\n updateBatchRef.current.push(updater);\n var promise = Promise.resolve();\n lastPromiseRef.current = promise;\n promise.then(function () {\n if (lastPromiseRef.current === promise) {\n var prevBatch = updateBatchRef.current;\n var prevState = stateRef.current;\n updateBatchRef.current = [];\n prevBatch.forEach(function (batchUpdater) {\n stateRef.current = batchUpdater(stateRef.current);\n });\n lastPromiseRef.current = null;\n if (prevState !== stateRef.current) {\n forceUpdate({});\n }\n }\n });\n }\n useEffect(function () {\n return function () {\n lastPromiseRef.current = null;\n };\n }, []);\n return [stateRef.current, setFrameState];\n}\n\n/** Lock frame, when frame pass reset the lock. */\nexport function useTimeoutLock(defaultState) {\n var frameRef = useRef(defaultState || null);\n var timeoutRef = useRef();\n function cleanUp() {\n window.clearTimeout(timeoutRef.current);\n }\n function setState(newState) {\n frameRef.current = newState;\n c