PPTist/src/hooks/useHistorySnapshot.ts
2021-06-09 22:14:52 +08:00

27 lines
636 B
TypeScript

import { debounce, throttle} from 'lodash'
import { ActionTypes, useStore } from '@/store'
export default () => {
const store = useStore()
// 添加历史快照(历史记录)
const addHistorySnapshot = debounce(function() {
store.dispatch(ActionTypes.ADD_SNAPSHOT)
}, 300, { trailing: true })
// 重做
const redo = throttle(function() {
store.dispatch(ActionTypes.RE_DO)
}, 100, { leading: true, trailing: false })
// 撤销
const undo = throttle(function() {
store.dispatch(ActionTypes.UN_DO)
}, 100, { leading: true, trailing: false })
return {
addHistorySnapshot,
redo,
undo,
}
}