1.2.0 • Published 8 months ago

@zstark/command-stack v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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

8 months ago

1.1.0

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago