Last active
March 22, 2016 10:17
-
-
Save threepointone/1f0f726d12ab79d29e27 to your computer and use it in GitHub Desktop.
time travel with disto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Dis} from 'disto'; | |
import {photo} from 'disto/record'; | |
let {register, dispatch, lock, unlock} = new Dis(); | |
let store = photo(register({x: 0}, o => ({x: o.x+1}))); // simple increments | |
store.subscribe(o => console.log(o.x)); // 0 | |
let t1 = store.snapshot(); | |
dispatch('xyz'); // 1 | |
dispatch('xyz'); // 2 | |
dispatch('xyz'); // 3 | |
dispatch('xyz'); // 4 | |
let t2 = store.snapshot(); | |
dispatch('xyz'); // 5 | |
dispatch('xyz'); // 6 | |
lock(); | |
dispatch('xyz'); // ignored | |
dispatch('xyz'); // ignored | |
store.goTo(t1); // 0 | |
console.log(store.get()); // {x:0} | |
store.goTo(t2); // 4 | |
store.restore(); // 6 | |
console.log(store.get()); // {x: 6} | |
unlock(); | |
dispatch('xyz'); // 7 | |
dispatch('xyz'); // 8 | |
Author
threepointone
commented
May 11, 2015
- can do snapshots per-store
- doesn't care what you use; immutable, mori, cursors, etc.
open qs
- undo/redo?
- action replay at arbit snapshot
- dispatcher level snapshots
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment