Hunter-Gu / redo-and-undo-ways

some ways to achieve redo and undo operations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

redo-and-undo-ways

Some ways to achieve redo and undo operations.

The key of redo and undo operations are diff - diff between every operation.

So the problem is how to get diff between operations.

traversal

We can get diff by BFS/DFS, but this way is not good for some operations of array:

  • move
  • add
  • delete

and also this way has performance defect.

interceptor

If you used get/set of lodash, you must be familiar with the string path style:

const obj = {}

set(obj, 'a.b.c', 'a')

get(obj, 'a.b.c', 'default')

We can provide some utils extend from get/set, and intercept to get diff.

Command

The Command pattern is the classic way to do redo and undo operation.

proxy

If you want to intercept assign operation of a object, you may think of proxy which is a meta way to do that.

About

some ways to achieve redo and undo operations

License:MIT License


Languages

Language:TypeScript 100.0%