I am using firebase, firepad and ace technology. I am able to write a document by firepad and ace and stores it in firebase, at different times.I see history being generated in firebase. Next thing is I need to add piece of code, where I can retrieve the document at any point in history. I wrote the following code:
sObj.once('value', function(historySnapshot){
// Get each revision Id
historySnapshot.forEach(function(itemSnapshot) {
var name = 'history/'+itemSnapshot.name();
console.log(name);
var idref = sObj.child(name);
/* Here I can read each revision object, find the operation and apply that change
in ace editor */
});
});
One way to read revision object is JSon parsing, know what operation is there. Apply that operation on the editor. constructing code what operation corresponds to what can be tedious.
Other than this are there any functions, which can avoid parsing and can directly tell me what operation to apply.
I saw getText function but that tells the current value. I need to see value at any point in the given history.
This is doable, but non-trivial so I'll provide some pointers but not a full answer. Sorry.
The code of interest is probably FirebaseAdapter.prototype.monitorHistoryStartingAt_.
If you pass it 0, it’ll start at the beginning of the history (rather than at a more recent checkpoint). By default, it reads all revisions, so you'll also need to modify it to stop at the revision you want to display. Then once it queues those operations (from 0 through the one of interest) in pendingReceivedRevisions_, it'll call handleInitialRevisions_ which will combine them all together and apply them to get you up-to-date at that point in history.
You'll then want to make sure that the editor is readonly, since you can't sensibly modify the old version.
Hope this helps.