Skip to content

Commit

Permalink
Move Socket-to-editor code from index.html to rga.js.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorendorff committed Apr 12, 2016
1 parent 628f1af commit 1a1fc65
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 1 addition & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,7 @@
editor.getSession().setMode("ace/mode/javascript");

var socket = io();
socket.on("welcome", function (event) {
// `local` is this window's replica of the document we're editing together.
var local = new RGA.AceEditorRGA(event.id, editor, event.history);
RGA.tieToSocket(local, socket);
editor.focus();

window.D = {
editor: editor,
local: local
};
});
RGA.AceEditorRGA.setup(editor, socket);
});
</script>
</body>
Expand Down
10 changes: 10 additions & 0 deletions lib/rga.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,5 +512,15 @@ Object.assign(RGA.AceEditorRGA.prototype, {
}
});

// Tie an Ace editor to a socket.
RGA.AceEditorRGA.setup = function (editor, socket) {
var local = undefined;
socket.on("welcome", function (event) {
local = new RGA.AceEditorRGA(event.id, editor, event.history);
RGA.tieToSocket(local, socket);
editor.focus();
});
};

if (typeof module !== "undefined")
exports = module.exports = RGA;

0 comments on commit 1a1fc65

Please sign in to comment.