'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
require('../../../../utils/index.cjs');
var raf = require('../../../../utils/vue/raf.cjs');

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

exports.default = useFrameSetState;
//# sourceMappingURL=useFrameSetState.cjs.map
