"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = useRafLock;
var _vue = require("vue");
var _raf = _interopRequireDefault(require("../_util/raf"));
function useRafLock() {
  const state = (0, _vue.ref)(false);
  let rafRef = null;
  const cleanup = () => {
    _raf.default.cancel(rafRef);
  };
  const setDelayState = nextState => {
    cleanup();
    if (nextState) {
      state.value = nextState;
    } else {
      rafRef = (0, _raf.default)(() => {
        state.value = nextState;
      });
    }
  };
  (0, _vue.onMounted)(() => {
    cleanup();
  });
  return [state, setDelayState];
}