"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = useDelay;
var _vue = require("vue");
var _raf = _interopRequireDefault(require("../../_util/raf"));
function useDelay(callback) {
  const idRef = (0, _vue.ref)(0);
  const clearRef = () => {
    _raf.default.cancel(idRef.value);
  };
  (0, _vue.onBeforeUnmount)(() => {
    clearRef();
  });
  const triggerFn = () => {
    clearRef();
    idRef.value = (0, _raf.default)(callback);
  };
  return triggerFn;
}