Comments (8)
@g-borgulya @codingisacopingstrategy See this related thread josephg/ShareJS#12
From there, here's an implementation of getSnapshotAtRevision by @luto . The algorithm is:
- Fetch the current snapshot
- Fetch the ops between the current snapshot and the desired snapshot
- For each op in reverse order, invert it and apply it to the snapshot.
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
);
}
from sharedb.
@codingisacopingstrategy do you have a workaround for this?
from sharedb.
Nice!! Thank you, @curran .
from sharedb.
@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.
from sharedb.
I started packaging the above code into a library: https://github.com/curran/sharedb-snapshot/tree/master
from sharedb.
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.
from sharedb.
@curran nice, thank you ;)
from sharedb.
This was implemented in #220
from sharedb.
Related Issues (20)
- preventCompose not changing HOT 1
- Callback when user disconnects from presence HOT 2
- ShareDB in Edge Computing
- Import Error in React(Typescript) HOT 2
- Issue in the "async" dependency HOT 2
- Invalid op submitted. Op version newer than current snapshot HOT 10
- Full offline mode (createSubscribeQuery) HOT 13
- `EventEmitter` memory leak warning for too many remote presence clients HOT 1
- Encrypted Data? HOT 1
- Middleware Errors are Fatal HOT 2
- Example using Vite HOT 3
- Upgrade Dependencies in Examples
- Upgrade dependencies
- CI Broken on 3.3.0 release commit HOT 1
- How to pass options through to server? HOT 3
- Question client doc handleOp not debounce ?
- `TypeError Cannot read properties of null (reading 'callback')` when receiving subscribe response with no inflight subscribe HOT 4
- Feature suggestion: type accessors HOT 3
- Q: How multiple `Doc`s guarantee transactions? HOT 2
- Collaborative text field using react with debounce HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sharedb.