@zstark/command-stack

1.2.0 • Public • Published

CommandStack

常见的 redo, undo操作. 继承 events.

publish license Commit Verison

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

Live Demo

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
  • [ ] 合并操作??

Readme

Keywords

Package Sidebar

Install

npm i @zstark/command-stack

Weekly Downloads

1

Version

1.2.0

License

MIT

Unpacked Size

48.2 kB

Total Files

9

Last publish

Collaborators

  • hodo