-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetch snapshot of previous version #45
Comments
@codingisacopingstrategy do you have a workaround for this? |
@g-borgulya @codingisacopingstrategy See this related thread josephg/ShareJS#12 From there, here's an implementation of getSnapshotAtRevision by @luto . The algorithm is:
Here's a copy of the implementation (authored by @luto): function getSnapshotAtRevision(docname, v, cb)
{
var snapshot
, ops = []
async.waterfall(
[
// get latest revision
function (cb)
{
model.getSnapshot(docname,
function (err, _snapshot)
{
snapshot = _snapshot;
cb(err);
}
);
},
// get ops that happend between `v` and `snapshot.v`
function (cb)
{
if(v == snapshot.v)
return cb();
model.getOps(docname, v, snapshot.v,
function (err, _ops)
{
ops = _ops;
cb(err);
}
);
},
// invert and apply ops
function (cb)
{
var json = sharejs.types.json;
var content = snapshot.snapshot;
var err = null;
try
{
for (var i = ops.length - 1; i >= 0; i--) // reverse order
{
var op = ops[i].op;
op = json.invert(op);
content = json.apply(content, op);
}
}
catch (_err)
{
err = _err;
}
cb(err, content);
}
],
cb
);
} |
Nice!! Thank you, @curran . |
@g-borgulya My pleasure! It would be amazing to integrate something like this into the project. One possible stumbling block is that I'm not sure all OT Types are invertable. Maybe there could be a variant that builds up the doc by replaying all ops in the forward direction from the beginning. |
I started packaging the above code into a library: https://github.com/curran/sharedb-snapshot/tree/master |
I agree that this would be a useful feature. I'm implementing a search and replace feature and in this case it would be useful being able to apply the replace operations on the snapshot version at the time of the search; applying the replace operations on the current version could not work if a change is applied in the meantime. |
@curran nice, thank you ;) |
This was implemented in #220 |
Hello—
The docs state how I can fetch the operations leading up to a previous version, but not how I can apply these operations to then obtain a snapshot of that version. I wonder if you could add this to the docs?
Feature request: ideally, I would be able to pass a version argument to the fetch method, to directly request a snapshot of a certain version.
Thanks for share.js and kind regards,
The text was updated successfully, but these errors were encountered: