Giter Club home page Giter Club logo

redux-immutable-undo-tree's Introduction

redux-immutable-undo-tree

Codeship Build Status

Powerful undo tree with Immutable.js data structures modeled after VIM's undo tree, powered by diff/patch changesets.

Work in progress!!!

Uses:

Sounds cool, show me how it works:


  Under the hood, the whole undo tree is stored as an Immutable.js tree. Just like VIM,
  we store changes in series in a 'branch'. We track these changes by wrapping your
  reducer in our own state-tracking function. You can apply certain undo tree traversals
  via our action creators.

    │    ┌┐                                     ┌┐
    │    └┤                                     └┤───┐   │
    │    ┌┤                                     ┌┤  ┌┤   │
    │    └┤                                  ┌──└┤  └│   │
    │    ┌┤                                 ┌┤  ┌┤  ┌┤   │
    │    └┤                                 └▼  └┤  └┤   │
         ┌┤       At any point in time,     ┌┤  ┌┤  ┌┤   │
  time   └┤         we can jump to an       └┤  └┤  └▼
         ┌┤           earlier state.        ┌┤  ┌┤     time
    │    └┤                                 └┤  └┤
    │    ┌┤                                 ┌┤  ┌┤       │
    │    └┤                                 └┤  └┤       │
    │    ┌┤                                 ┌┤  ┌┤       │
    │    └┤                                 └┤  └┤       │
    │    ┌┤                                 ┌┤  ┌┤       │
    ▼    └▼                                 └▼  └▼       │
                                                         ▼


  How do I use it?
  - Wrap your reducer that manages the state tree that you wish to
    have undo functionality for.
  - Apply the undo-tree middleware.
  - Profit! Use built-in action creators for tree traversal.

Example

import { undoable, actionCreators } from 'redux-immutable-undo-tree'
import { createStore, compose, combineReducers, applyMiddleware } from 'redux'

const initialState = {};
const identityReducer = (a) => a;
const rootReducer = combineReducers({
  data: undoable(identityReducer)
})

const store = createStore(
  rootReducer,
  initialState
)

// Go back in time 2 hours ago
store.dispatch(actionCreators.timeSubtract(2, 'hours'))

// Go forwards in time 2 hours
store.dispatch(actionCreators.timeAdd(2, 'hours'))

redux-immutable-undo-tree's People

Contributors

andrewvy avatar

Stargazers

Chris Watson avatar Brian Cannard avatar Samy Al Zahrani avatar

Watchers

James Cloos avatar  avatar

redux-immutable-undo-tree's Issues

Tree Traversal

Need to figure out how to traverse the tree:

  • For getting all paths and nodes while iterating
  • For nodes between two nodes.

State Snapshots at the HEAD of branches

In the event I can't implement #1, the next thing would to save a snapshot of the state at the head of each branch. Then you can apply patches to get to a future state.

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.