gritzko / swarm

JavaScript replicated model (M of MVC) library
http://swarmdb.net/
MIT License
2.68k stars 97 forks source link

Reconstitute model from static data #83

Closed mattriverm closed 8 years ago

mattriverm commented 8 years ago

Question. I'm on 0.3.25. In a certain case I have the oplogs as JSON like it is stored by filestorage (_version, _tail with oplogs). I want to hydrate my model with that data, not using Host or storage, how can I do that?

this.spec = new Swarm.Spec('/MyModel#44Gmj+some_id');
this.typeid = this.spec.filter('/#');
let Mr = new MyModel(this.typeid);
// then what?

How do I apply the tail of ops to get a current model?

mattriverm commented 8 years ago

Maybe I'm trying to do something stupid. Just trying to understand how things work, and thought there would be a shortcut. Decided to roll my own read-only storage that serves the model the usual way via host.get().

It confuses me that I have to reset _version in my saved state or I will get replay warnings and the model wont hydrate, but I can live with that.