Skip to content

Commit

Permalink
Improve logging by assigning each RGA its own id number. (This is esp…
Browse files Browse the repository at this point in the history
…ecially useful since each "welcome" event has the browser creating a new RGA, so there can be more than one even for a single document.)
  • Loading branch information
jorendorff committed Apr 12, 2016
1 parent 2875edb commit 628f1af
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/rga.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var MAX_REPLICA_ID_BITS = 16;
function RGA(id, history, queue) {
if (typeof id !== "number" || (id | 0) !== id || id < 0 || id >= (1 << MAX_REPLICA_ID_BITS))
throw new TypeError("RGA constructor: first argument is not a valid id");
this._idForLogging = RGA._nextIdForLogging++;
this.id = id;
this.left = {next: undefined, timestamp: -1, atom: undefined, removed: false};
this._index = new Map([[this.left.timestamp, this.left]]);
Expand All @@ -30,6 +31,7 @@ function RGA(id, history, queue) {
}
}

RGA._nextIdForLogging = 100;
RGA._logging = false;

RGA._browserQueue = {
Expand Down Expand Up @@ -158,7 +160,9 @@ RGA.prototype = {

_log: function () {
if (RGA._logging)
console.log.apply(console, arguments);
console.log
.bind(console, "{" + this.constructor.name + this._idForLogging + "}:")
.apply(undefined, arguments);
}
};

Expand Down Expand Up @@ -309,6 +313,8 @@ RGA.AceEditorRGA = function AceEditorRGA(id, editor, history, queue) {

RGA.AceEditorRGA.prototype = Object.create(RGA.prototype);
Object.assign(RGA.AceEditorRGA.prototype, {
constructor: RGA.AceEditorRGA,

// Return the {row, column} coordinates of the character with timestamp t.
getRowColumnBefore: function (t) {
if (t === this.left.timestamp)
Expand Down

0 comments on commit 628f1af

Please sign in to comment.