GithubHelp home page GithubHelp logo

gaoding-inc / stateshot Goto Github PK

View Code? Open in Web Editor NEW
191.0 5.0 11.0 187 KB

💾 Non-aggressive history state management with structure sharing.

HTML 0.76% JavaScript 99.24%
history-management state-management undo-redo json state javascript history-state

stateshot's People

Contributors

doodlewind avatar doouding avatar wsafight avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

stateshot's Issues

Mixed async / sync push yields redundant records

Current Behavior

history.push(state).then(() => {
  console.log(history.length) // 2
})
history.pushSync(state)

In this case history.length should be 1 since sync push is expected to clear the pending state.

Build tool integration

Rollup need a few more setup but is better in bundle size. It can also fix the webpack require error.

Hash test

Makes sense since we may make hashFunc replaceable.

请教一下大佬关于图片撤销重做用你们这个库怎么实现?

1、看了你们这个库的实现原理分析,大致理解是你们这个库应该是快照式撤销重做类库?
2、图片处理涉及到distructive 和 non-destructive操作,还有添加图层类操作,图层与原图一起变换操作等一系列操作,那么用你们这个库怎么实现?或者你们有类似的示例吗?

有几个小错误

const history = new History()
const state = { a: 1, b: 2 }
history.pushSync({ ...state })
history.pushSync({ ...state, ...{ a: 2 } })
history.pushSync({ ...state, ...{ a: 3 } });
history.undo();
history.undo();
let r1 = history.get();    // { a: 1, b: 2, children: undefined }
history.pushSync({ ...state, ...{ c: 1 } });
let r2 = history.get();
let r3 = history.length;   // 3  应该等于2
history.undo();
let r4 = history.get();    // { a: 1, b: 2, children: undefined }

存在的几点问题

  1. 默认的defaultRule会使得get方法返回值中带有children字段
  2. history.length值应该是this.$records.filter(record => record).length,r3应该为2

immutable support

Using libs like immer to replace our hash implementation is promising and trivial. Another options needed.

Dumping history

Snippet for "dumping" history records:

// in chrome console
copy(oldHistoryStore)
// in reproduction page
const data = { ... } // paste
history.$index = data.$index
history.$records = data.$records
history.$chunks = data.$chunks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.