@zstark/command-stack
v1.2.0
Published
常见的 redo, undo操作. 继承 events.
Downloads
5
Readme
CommandStack
常见的 redo, undo操作. 继承 events.
Quick start
pnpm add @zstark/command-stack
const cs = new CommandStack({ /* handlers */ });
// 记录
cs.dispatch({
type: 'create.shape',
context: { /* any */ },
});
// redo undo
cs.redo();
cs.undo();
exmaple
pnpm instsall
pnpm build:example
pnpm dev
Options
~~处理程序可以是 Promise.~~
- handlers?: Record<ActionTypeEnum, handler>
- options?: { maxLength: number }
Methods
- redo: () => void. 下一步
- undo: () => void. 上一步
- dispatch: (action: Action) => void. 记录行为
- excute () => void. 执行操作. 一般用不到
Action
type Action = {
type: string; // 操作标识
context: any; // 上下文
}
TODO
- [ ] handlers 支持异步.
- [ ] excute
- [ ] ~~合并操作??~~