import { onMounted, ref } from 'vue';
import raf from '../_util/raf';
export default function useRafLock() {
  const state = ref(false);
  let rafRef = null;
  const cleanup = () => {
    raf.cancel(rafRef);
  };
  const setDelayState = nextState => {
    cleanup();
    if (nextState) {
      state.value = nextState;
    } else {
      rafRef = raf(() => {
        state.value = nextState;
      });
    }
  };
  onMounted(() => {
    cleanup();
  });
  return [state, setDelayState];
}