Skip to content

Commit dd4d3d6

Browse files
committed
For #1: rename editor events
- editorChange --> editorTextChange - changeScroll --> editorScrollChange - changeCursor --> editorCursorChange
1 parent 9c98b83 commit dd4d3d6

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

public/local.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,21 @@ editor.getSession().setMode('ace/mode/javascript');
9292
- connection Send: SocketIO built-in event
9393
- disconnect Send: SocketIO built-in event
9494
- loggedIn Send: handleUserLogin
95-
- editorChange Send: handleUserTyping
95+
- editorTextChange Send: handleUserTyping
9696
Receive: handleEditorChange
9797
- playerListChange Receive: handlePlayerListChange
9898
- updateState Receive: handleUpdateState
9999
- turnChange Receive: handleTurnChange
100-
- changeCursor Send: handleChangeCursor
100+
- editorCursorChange Send: handleChangeCursor
101101
Receive: handleNewCursorData
102-
- changeScroll Send: handleChangeScroll
102+
- editorScrollChange Send: handleeditorScrollChange
103103
Receive: handleNewScrollData
104104
- createNewGist Receive: createNewGist
105105
- newGistLink Receive: handleNewGistLink
106106
Send: (sent after creating or forking)
107107
-------------------------------------------------------------- */
108108
editor.getSession().on('change', handleUserTyping);
109-
editor.getSession().selection.on('changeCursor', handleChangeCursor);
109+
editor.getSession().selection.on('editorCursorChange', handleChangeCursor);
110110
editor.getSession().on('changeScrollLeft', handleChangeScroll);
111111
editor.getSession().on('changeScrollTop', handleChangeScroll);
112112

@@ -149,7 +149,7 @@ function handleUserTyping (event) {
149149
if (socket.id === currentPlayerId) {
150150
//console.log('Sending data to server!')
151151
// Send data to server
152-
socket.emit( 'editorChange', editor.getValue() );
152+
socket.emit( 'editorTextChange', editor.getValue() );
153153
}
154154
}
155155

@@ -177,7 +177,7 @@ function handleUserNameChange (event) {
177177

178178
// Send cursor and selection data to server
179179
function handleChangeCursor (event) {
180-
//console.log('changeCursor fired!');
180+
//console.log('editorCursorChange fired!');
181181
//console.log('%c ' + event, 'color: green; font-weight: bold;');
182182

183183
// Cursor object:
@@ -187,16 +187,16 @@ function handleChangeCursor (event) {
187187
// { end: {column, row}, start: {column, row} }
188188

189189
// Send to server:
190-
socket.emit( 'changeCursor', { cursor: editor.getSession().selection.getCursor(), range: editor.getSession().selection.getRange() } );
190+
socket.emit( 'editorCursorChange', { cursor: editor.getSession().selection.getCursor(), range: editor.getSession().selection.getRange() } );
191191
}
192192

193193
// Send scroll data to server
194194
function handleChangeScroll (event) {
195-
//console.log('changeScroll (left or top) fired!');
195+
//console.log('editorScrollChange (left or top) fired!');
196196
//console.log('%c scrollLeft: ' + editor.getSession().getScrollLeft() + ', scrollTop: ' + editor.getSession().getScrollTop(), 'color: green; font-weight: bold;');
197197

198198
// Send to server:
199-
socket.emit('changeScroll', { scrollLeft: editor.getSession().getScrollLeft(), scrollTop: editor.getSession().getScrollTop() });
199+
socket.emit('editorScrollChange', { scrollLeft: editor.getSession().getScrollLeft(), scrollTop: editor.getSession().getScrollTop() });
200200
}
201201

202202
// TODO: Test 'input' event some more in different browsers!
@@ -205,9 +205,9 @@ function handleChangeScroll (event) {
205205
/* -------------------------------------------------
206206
EVENT LISTENERS / RECEIVE DATA FROM SERVER
207207
---------------------------------------------------- */
208-
socket.on('editorChange', handleEditorChange);
209-
socket.on('changeCursor', handleNewCursorData);
210-
socket.on('changeScroll', handleNewScrollData);
208+
socket.on('editorTextChange', handleEditorChange);
209+
socket.on('editorCursorChange', handleNewCursorData);
210+
socket.on('editorScrollChange', handleNewScrollData);
211211
socket.on('playerListChange', handlePlayerListChange);
212212
socket.on('updateState', handleUpdateState);
213213
socket.on('turnChange', handleTurnChange);
@@ -216,7 +216,7 @@ socket.on('newGistLink', handleNewGistLink);
216216

217217
// When receiving new editorInputView data from server
218218
function handleEditorChange (data) {
219-
//console.log('editorChange event received!');
219+
//console.log('editorTextChange event received!');
220220
//console.log('%c ' + data, 'color: blue; font-weight: bold;');
221221

222222
updateEditorView(data);
@@ -234,7 +234,7 @@ function handleNewCursorData (data) {
234234

235235
// When receiving new scroll data from server
236236
function handleNewScrollData (data) {
237-
//console.log('%c scrollChange event received!', 'color: blue; font-weight: bold;');
237+
//console.log('%c editorScrollChange event received!', 'color: blue; font-weight: bold;');
238238
//console.dir(data);
239239

240240
// Set Ace editor's scroll position to match

server.js

+21-21
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ server.listen(port, function() {
6767
/* ------------------------------------------------------------
6868
EVENT NAMES: SERVER FUNCTIONS:
6969
- loggedIn io.emit: playerListChange
70-
socket.emit: editorChange, changeScroll, changeCursor, turnChange
70+
socket.emit: editorTextChange, editorScrollChange, editorCursorChange, turnChange
7171
- disconnect Broadcast: playerListChange
72-
- editorChange Broadcast: editorChange
73-
- changeCursor Broadcast: changeCursor
74-
- changeScroll Broadcast: changeScroll
72+
- editorTextChange Broadcast: editorTextChange
73+
- editorCursorChange Broadcast: editorCursorChange
74+
- editorScrollChange Broadcast: editorScrollChange
7575
- updateState Broadcast: updateState
7676
- turnChange Broadcast: turnChange
7777
- createNewGist Broadcast: createNewGist
@@ -114,12 +114,12 @@ io.on('connection', function (socket) {
114114
playerList.push(socket.id);
115115

116116
// Send current state of the text editor to the new client, to initialize!
117-
socket.emit('editorChange', editorContent);
117+
socket.emit('editorTextChange', editorContent);
118118
if (editorScroll != null) {
119-
socket.emit('changeScroll', editorScroll);
119+
socket.emit('editorScrollChange', editorScroll);
120120
}
121121
if (editorCursorAndSelection != null) {
122-
socket.emit('changeCursor', editorCursorAndSelection);
122+
socket.emit('editorCursorChange', editorCursorAndSelection);
123123
}
124124

125125
// Initialize the turn (and timer) with first connected user
@@ -204,10 +204,10 @@ io.on('connection', function (socket) {
204204
}
205205
});
206206

207-
// When "editorChange" event received, update editor state and broadcast it back out
208-
socket.on('editorChange', function (data) {
207+
// When "editorTextChange" event received, update editor state and broadcast it back out
208+
socket.on('editorTextChange', function (data) {
209209

210-
//console.log('editorChange event received!');
210+
//console.log('editorTextChange event received!');
211211
//console.log(data);
212212

213213
// Double check that this user is allowed to type (in case of client-side tampering with the JS!)
@@ -216,17 +216,17 @@ io.on('connection', function (socket) {
216216
editorContent = data;
217217

218218
// Broadcast updated editor content to other clients
219-
socket.broadcast.emit('editorChange', editorContent);
219+
socket.broadcast.emit('editorTextChange', editorContent);
220220

221221
//console.log('Broadcasting editorContent to other clients!');
222222
}
223223

224224
});
225225

226-
// When "changeCursor" event received, update editor state and broadcast it back out
227-
socket.on('changeCursor', function (data) {
226+
// When "editorCursorChange" event received, update editor state and broadcast it back out
227+
socket.on('editorCursorChange', function (data) {
228228

229-
//console.log('changeCursor event received!');
229+
//console.log('editorCursorChange event received!');
230230
//console.log(data);
231231

232232
// Double check that this user is allowed to broadcast (in case of client-side tampering with the JS!)
@@ -235,17 +235,17 @@ io.on('connection', function (socket) {
235235
editorCursorAndSelection = data;
236236

237237
// Broadcast data to other clients
238-
socket.broadcast.emit('changeCursor', editorCursorAndSelection);
238+
socket.broadcast.emit('editorCursorChange', editorCursorAndSelection);
239239

240-
//console.log('Broadcasting changeCursor to other clients!');
240+
//console.log('Broadcasting editorCursorChange to other clients!');
241241
}
242242

243243
});
244244

245-
// When "changeScroll" event received, update editor state and broadcast it back out
246-
socket.on('changeScroll', function (data) {
245+
// When "editorScrollChange" event received, update editor state and broadcast it back out
246+
socket.on('editorScrollChange', function (data) {
247247

248-
//console.log('changeScroll event received!');
248+
//console.log('editorScrollChange event received!');
249249
//console.log(data);
250250

251251
// Double check that this user is allowed to broadcast (in case of client-side tampering with the JS!)
@@ -254,9 +254,9 @@ io.on('connection', function (socket) {
254254
editorScroll = data;
255255

256256
// Broadcast data to other clients
257-
socket.broadcast.emit('changeScroll', editorScroll);
257+
socket.broadcast.emit('editorScrollChange', editorScroll);
258258

259-
//console.log('Broadcasting changeScroll to other clients!');
259+
//console.log('Broadcasting editorScrollChange to other clients!');
260260
}
261261

262262
});

0 commit comments

Comments
 (0)