Skip to content

Instantly share code, notes, and snippets.

@threepointone
Last active March 22, 2016 10:17
Show Gist options
  • Save threepointone/1f0f726d12ab79d29e27 to your computer and use it in GitHub Desktop.
Save threepointone/1f0f726d12ab79d29e27 to your computer and use it in GitHub Desktop.
time travel with disto
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
@threepointone
Copy link
Author

  • can do snapshots per-store
  • doesn't care what you use; immutable, mori, cursors, etc.

@threepointone
Copy link
Author

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