'use strict';

var vue = require('vue');
var raf = require('../../_util/raf.js');

function useLayoutState(defaultState) {
  const stateRef = vue.shallowRef(defaultState);
  let rafId;
  const updateBatchRef = vue.shallowRef([]);
  function setFrameState(updater) {
    updateBatchRef.value.push(updater);
    raf.default.cancel(rafId);
    rafId = raf.default(() => {
      const prevBatch = updateBatchRef.value;
      updateBatchRef.value = [];
      prevBatch.forEach((batchUpdater) => {
        stateRef.value = batchUpdater(stateRef.value);
      });
    });
  }
  vue.onBeforeUnmount(() => {
    raf.default.cancel(rafId);
  });
  return [stateRef, setFrameState];
}
function useTimeoutLock(defaultState) {
  const frameRef = vue.ref(defaultState || null);
  const timeoutRef = vue.ref();
  function cleanUp() {
    clearTimeout(timeoutRef.value);
  }
  function setState(newState) {
    frameRef.value = newState;
    cleanUp();
    timeoutRef.value = setTimeout(() => {
      frameRef.value = null;
      timeoutRef.value = void 0;
    }, 100);
  }
  function getState() {
    return frameRef.value;
  }
  vue.onBeforeUnmount(() => {
    cleanUp();
  });
  return [setState, getState];
}

exports.useLayoutState = useLayoutState;
exports.useTimeoutLock = useTimeoutLock;
//# sourceMappingURL=useFrame.js.map
