import { ref, reactive, onMounted } from 'vue';
import '../../../../utils/index.mjs';
import { raf } from '../../../../utils/vue/raf.mjs';

function useFrameSetState(initial) {
  const frame = ref(null);
  const state = reactive({ ...initial });
  const queue = ref([]);
  const setFrameState = (newState) => {
    if (frame.value === null) {
      queue.value = [];
      frame.value = raf(() => {
        let memoState;
        queue.value.forEach((queueState) => {
          memoState = { ...memoState, ...queueState };
        });
        Object.assign(state, memoState);
        frame.value = null;
      });
    }
    queue.value.push(newState);
  };
  onMounted(() => {
    frame.value && raf.cancel(frame.value);
  });
  return [state, setFrameState];
}

export { useFrameSetState as default };
//# sourceMappingURL=useFrameSetState.mjs.map
