useHistorySnapshot.ts 609 B

12345678910111213141516171819202122232425
  1. import debounce from 'lodash/debounce'
  2. import throttle from 'lodash/throttle'
  3. import { ActionTypes, useStore } from '@/store'
  4. export default () => {
  5. const store = useStore()
  6. const addHistorySnapshot = debounce(function() {
  7. store.dispatch(ActionTypes.ADD_SNAPSHOT)
  8. }, 300, { trailing: true })
  9. const redo = throttle(function() {
  10. store.dispatch(ActionTypes.RE_DO)
  11. }, 100, { leading: true, trailing: false })
  12. const undo = throttle(function() {
  13. store.dispatch(ActionTypes.UN_DO)
  14. }, 100, { leading: true, trailing: false })
  15. return {
  16. addHistorySnapshot,
  17. redo,
  18. undo,
  19. }
  20. }