Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 83f1545

Browse files
committed
append 'on' to all hooks
1 parent c9a696f commit 83f1545

File tree

7 files changed

+57
-57
lines changed

7 files changed

+57
-57
lines changed

example/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ chatManager.connect()
2626
currentUser.subscribeToRoom(
2727
roomToSubscribeTo.id,
2828
{
29-
newMessage: message => {
29+
onNewMessage: message => {
3030
console.log('new message:', message)
3131
const messagesList = document.getElementById('messages')
3232
const messageItem = document.createElement('li')

src/current-user.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ export class CurrentUser {
313313
hooks: {
314314
newCursor: cursor => {
315315
if (
316-
hooks.newReadCursor && cursor.type === 0 &&
316+
hooks.onNewReadCursor && cursor.type === 0 &&
317317
cursor.userId !== this.id
318318
) {
319-
hooks.newReadCursor(cursor)
319+
hooks.onNewReadCursor(cursor)
320320
}
321321
}
322322
},
@@ -452,10 +452,10 @@ export class CurrentUser {
452452
hooks: {
453453
newCursor: cursor => {
454454
if (
455-
hooks.newReadCursor && cursor.type === 0 &&
455+
hooks.onNewReadCursor && cursor.type === 0 &&
456456
this.isMemberOf(cursor.roomId)
457457
) {
458-
hooks.newReadCursor(cursor)
458+
hooks.onNewReadCursor(cursor)
459459
}
460460
}
461461
},

src/message-subscription.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ export class MessageSubscription {
6666
flushBuffer = () => {
6767
while (!isEmpty(this.messageBuffer) && head(this.messageBuffer).ready) {
6868
const message = this.messageBuffer.shift().message
69-
if (this.hooks.newMessage) {
70-
this.hooks.newMessage(message)
69+
if (this.hooks.onNewMessage) {
70+
this.hooks.onNewMessage(message)
7171
}
7272
}
7373
}

src/presence-subscription.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ export class PresenceSubscription {
8282
map(parsePresence, userStates)
8383
)
8484

85-
onCameOnline = user => this.callRelevantHooks('userCameOnline', user)
85+
onCameOnline = user => this.callRelevantHooks('onUserCameOnline', user)
8686

87-
onWentOffline = user => this.callRelevantHooks('userWentOffline', user)
87+
onWentOffline = user => this.callRelevantHooks('onUserWentOffline', user)
8888

8989
callRelevantHooks = (hookName, user) => {
9090
if (this.hooks[hookName]) {

src/typing-indicators.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ export class TypingIndicators {
5151
}
5252

5353
onStarted = (room, user, hooks, roomHooks) => {
54-
if (hooks.userStartedTyping) {
55-
hooks.userStartedTyping(room, user)
54+
if (hooks.onUserStartedTyping) {
55+
hooks.onUserStartedTyping(room, user)
5656
}
57-
if (roomHooks[room.id] && roomHooks[room.id].userStartedTyping) {
58-
roomHooks[room.id].userStartedTyping(user)
57+
if (roomHooks[room.id] && roomHooks[room.id].onUserStartedTyping) {
58+
roomHooks[room.id].onUserStartedTyping(user)
5959
}
6060
}
6161

6262
onStopped = (room, user, hooks, roomHooks) => {
63-
if (hooks.userStoppedTyping) {
64-
hooks.userStoppedTyping(room, user)
63+
if (hooks.onUserStoppedTyping) {
64+
hooks.onUserStoppedTyping(room, user)
6565
}
66-
if (roomHooks[room.id] && roomHooks[room.id].userStoppedTyping) {
67-
roomHooks[room.id].userStoppedTyping(user)
66+
if (roomHooks[room.id] && roomHooks[room.id].onUserStoppedTyping) {
67+
roomHooks[room.id].onUserStoppedTyping(user)
6868
}
6969
}
7070
}

src/user-subscription.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,32 +69,32 @@ export class UserSubscription {
6969
onAddedToRoom = ({ room: roomData }) => {
7070
const basicRoom = parseBasicRoom(roomData)
7171
this.roomStore.set(basicRoom.id, basicRoom).then(room => {
72-
if (this.hooks.addedToRoom) {
73-
this.hooks.addedToRoom(room)
72+
if (this.hooks.onAddedToRoom) {
73+
this.hooks.onAddedToRoom(room)
7474
}
7575
})
7676
}
7777

7878
onRemovedFromRoom = ({ room_id: roomId }) => {
7979
this.roomStore.pop(roomId).then(room => {
8080
// room will be undefined if we left with leaveRoom
81-
if (room && this.hooks.removedFromRoom) {
82-
this.hooks.removedFromRoom(room)
81+
if (room && this.hooks.onRemovedFromRoom) {
82+
this.hooks.onRemovedFromRoom(room)
8383
}
8484
})
8585
}
8686

8787
onUserJoined = ({ room_id: roomId, user_id: userId }) => {
8888
this.roomStore.addUserToRoom(roomId, userId).then(room => {
8989
this.userStore.get(userId).then(user => {
90-
if (this.hooks.userJoinedRoom) {
91-
this.hooks.userJoinedRoom(room, user)
90+
if (this.hooks.onUserJoinedRoom) {
91+
this.hooks.onUserJoinedRoom(room, user)
9292
}
9393
if (
9494
this.roomSubscriptions[roomId] &&
95-
this.roomSubscriptions[roomId].hooks.userJoined
95+
this.roomSubscriptions[roomId].hooks.onUserJoined
9696
) {
97-
this.roomSubscriptions[roomId].hooks.userJoined(user)
97+
this.roomSubscriptions[roomId].hooks.onUserJoined(user)
9898
}
9999
})
100100
})
@@ -103,14 +103,14 @@ export class UserSubscription {
103103
onUserLeft = ({ room_id: roomId, user_id: userId }) => {
104104
this.roomStore.removeUserFromRoom(roomId, userId).then(room => {
105105
this.userStore.get(userId).then(user => {
106-
if (this.hooks.userLeftRoom) {
107-
this.hooks.userLeftRoom(room, user)
106+
if (this.hooks.onUserLeftRoom) {
107+
this.hooks.onUserLeftRoom(room, user)
108108
}
109109
if (
110110
this.roomSubscriptions[roomId] &&
111-
this.roomSubscriptions[roomId].hooks.userLeft
111+
this.roomSubscriptions[roomId].hooks.onUserLeft
112112
) {
113-
this.roomSubscriptions[roomId].hooks.userLeft(user)
113+
this.roomSubscriptions[roomId].hooks.onUserLeft(user)
114114
}
115115
})
116116
})
@@ -119,16 +119,16 @@ export class UserSubscription {
119119
onRoomUpdated = ({ room: roomData }) => {
120120
const updates = parseBasicRoom(roomData)
121121
this.roomStore.update(updates.id, updates).then(room => {
122-
if (this.hooks.roomUpdated) {
123-
this.hooks.roomUpdated(room)
122+
if (this.hooks.onRoomUpdated) {
123+
this.hooks.onRoomUpdated(room)
124124
}
125125
})
126126
}
127127

128128
onRoomDeleted = ({ room_id: roomId }) => {
129129
this.roomStore.pop(roomId).then(room => {
130-
if (room && this.hooks.roomDeleted) {
131-
this.hooks.roomDeleted(room)
130+
if (room && this.hooks.onRoomDeleted) {
131+
this.hooks.onRoomDeleted(room)
132132
}
133133
})
134134
}

tests/main.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ test('own read cursor undefined if not set', t => {
255255

256256
test('new read cursor hook [Alice sets her read cursor in her room]', t => {
257257
Promise.all([fetchUser(t, 'alice'), fetchUser(t, 'alice', {
258-
newReadCursor: cursor => {
258+
onNewReadCursor: cursor => {
259259
t.equal(cursor.position, 42)
260260
t.equal(cursor.user.name, 'Alice')
261261
t.equal(cursor.room.name, `Alice's room`)
@@ -285,7 +285,7 @@ test('get own read cursor', t => {
285285
test(`added to room hook [creates Bob & Bob's room]`, t => {
286286
let alice
287287
fetchUser(t, 'alice', {
288-
addedToRoom: room => {
288+
onAddedToRoom: room => {
289289
t.equal(room.name, `Bob's room`)
290290
t.true(
291291
any(r => r.id === room.id, alice.rooms),
@@ -314,7 +314,7 @@ test(`added to room hook [creates Bob & Bob's room]`, t => {
314314
// (since then he will already be online)
315315
test('user came online hook (user sub)', t => {
316316
fetchUser(t, 'alice', {
317-
userCameOnline: user => {
317+
onUserCameOnline: user => {
318318
t.equal(user.id, 'bob')
319319
t.equal(user.presence.state, 'online')
320320
t.end()
@@ -327,7 +327,7 @@ test('user came online hook (user sub)', t => {
327327

328328
test('user went offline hook (user sub)', t => {
329329
fetchUser(t, 'alice', {
330-
userWentOffline: user => {
330+
onUserWentOffline: user => {
331331
t.equal(user.id, 'bob')
332332
t.equal(user.presence.state, 'offline')
333333
t.end()
@@ -342,12 +342,12 @@ test('typing indicators (user sub)', t => {
342342
let started
343343
Promise.all([
344344
fetchUser(t, 'alice', {
345-
userStartedTyping: (room, user) => {
345+
onUserStartedTyping: (room, user) => {
346346
started = Date.now()
347347
t.equal(room.id, bobsRoom.id)
348348
t.equal(user.id, 'bob')
349349
},
350-
userStoppedTyping: (room, user) => {
350+
onUserStoppedTyping: (room, user) => {
351351
t.equal(room.id, bobsRoom.id)
352352
t.equal(user.id, 'bob')
353353
t.true(Date.now() - started > 1000, 'fired more than 1s after start')
@@ -366,7 +366,7 @@ test('typing indicators (user sub)', t => {
366366

367367
test('user left room hook (user sub) [removes Bob from his own room]', t => {
368368
fetchUser(t, 'alice', {
369-
userLeftRoom: (room, user) => {
369+
onUserLeftRoom: (room, user) => {
370370
t.equal(room.id, bobsRoom.id)
371371
t.equal(user.id, 'bob')
372372
t.end()
@@ -384,7 +384,7 @@ test('user left room hook (user sub) [removes Bob from his own room]', t => {
384384

385385
test('user joined room hook (user sub) [Bob rejoins his own room]', t => {
386386
fetchUser(t, 'alice', {
387-
userJoinedRoom: (room, user) => {
387+
onUserJoinedRoom: (room, user) => {
388388
t.equal(room.id, bobsRoom.id)
389389
t.equal(user.id, 'bob')
390390
t.end()
@@ -402,7 +402,7 @@ test('user joined room hook (user sub) [Bob rejoins his own room]', t => {
402402

403403
test('room updated hook', t => {
404404
fetchUser(t, 'alice', {
405-
roomUpdated: room => {
405+
onRoomUpdated: room => {
406406
t.equal(room.id, bobsRoom.id)
407407
t.equal(room.name, `Bob's renamed room`)
408408
t.end()
@@ -420,7 +420,7 @@ test('room updated hook', t => {
420420

421421
test(`removed from room hook [removes Alice from Bob's room]`, t => {
422422
fetchUser(t, 'alice', {
423-
removedFromRoom: room => {
423+
onRemovedFromRoom: room => {
424424
t.equal(room.id, bobsRoom.id)
425425
t.end()
426426
}
@@ -437,7 +437,7 @@ test(`removed from room hook [removes Alice from Bob's room]`, t => {
437437

438438
test(`room deleted hook [destroys Alice's room]`, t => {
439439
fetchUser(t, 'alice', {
440-
roomDeleted: room => {
440+
onRoomDeleted: room => {
441441
t.equal(room.id, alicesRoom.id)
442442
t.end()
443443
}
@@ -668,7 +668,7 @@ test('subscribe to room and fetch initial messages', t => {
668668
.then(alice => alice.subscribeToRoom({
669669
roomId: bobsRoom.id,
670670
hooks: {
671-
newMessage: concatBatch(4, messages => {
671+
onNewMessage: concatBatch(4, messages => {
672672
t.deepEqual(map(m => m.text, messages), ['hello', 'hey', 'hi', 'ho'])
673673
t.equal(messages[0].sender.name, 'Alice')
674674
t.equal(messages[0].room.name, `Bob's new room`)
@@ -685,7 +685,7 @@ test('subscribe to room and fetch last two message only', t => {
685685
.then(alice => alice.subscribeToRoom({
686686
roomId: bobsRoom.id,
687687
hooks: {
688-
newMessage: concatBatch(2, messages => {
688+
onNewMessage: concatBatch(2, messages => {
689689
t.deepEqual(map(m => m.text, messages), ['hi', 'ho'])
690690
t.end()
691691
})
@@ -701,7 +701,7 @@ test('subscribe to room and receive sent messages', t => {
701701
.then(alice => alice.subscribeToRoom({
702702
roomId: bobsRoom.id,
703703
hooks: {
704-
newMessage: concatBatch(3, messages => {
704+
onNewMessage: concatBatch(3, messages => {
705705
t.deepEqual(map(m => m.text, messages), ['yo', 'yoo', 'yooo'])
706706
t.equal(messages[0].sender.name, 'Alice')
707707
t.equal(messages[0].room.name, `Bob's new room`)
@@ -720,7 +720,7 @@ test('unsubscribe from room', t => {
720720
.then(alice => alice.subscribeToRoom({
721721
roomId: bobsRoom.id,
722722
hooks: {
723-
newMessage: once(m => {
723+
onNewMessage: once(m => {
724724
endWithErr(t, 'should not be called after unsubscribe')
725725
})
726726
},
@@ -859,7 +859,7 @@ test(`user joined hook [Carol joins Bob's room]`, t => {
859859
.then(alice => alice.subscribeToRoom({
860860
roomId: bobsRoom.id,
861861
hooks: {
862-
userJoined: once(user => {
862+
onUserJoined: once(user => {
863863
t.equal(user.id, 'carol')
864864
t.equal(user.name, 'Carol')
865865
t.end()
@@ -883,7 +883,7 @@ test('user came online hook', t => {
883883
.then(alice => alice.subscribeToRoom({
884884
roomId: bobsRoom.id,
885885
hooks: {
886-
userCameOnline: once(user => {
886+
onUserCameOnline: once(user => {
887887
t.equal(user.id, 'carol')
888888
t.equal(user.name, 'Carol')
889889
t.equal(user.presence.state, 'online')
@@ -901,7 +901,7 @@ test('user went offline hook', t => {
901901
.then(alice => alice.subscribeToRoom({
902902
roomId: bobsRoom.id,
903903
hooks: {
904-
userWentOffline: once(user => {
904+
onUserWentOffline: once(user => {
905905
t.equal(user.id, 'carol')
906906
t.equal(user.name, 'Carol')
907907
t.equal(user.presence.state, 'offline')
@@ -921,12 +921,12 @@ test('typing indicators', t => {
921921
.then(alice => alice.subscribeToRoom({
922922
roomId: bobsRoom.id,
923923
hooks: {
924-
userStartedTyping: once(user => {
924+
onUserStartedTyping: once(user => {
925925
started = Date.now()
926926
t.equal(user.id, 'carol')
927927
t.equal(user.name, 'Carol')
928928
}),
929-
userStoppedTyping: once(user => {
929+
onUserStoppedTyping: once(user => {
930930
t.equal(user.id, 'carol')
931931
t.equal(user.name, 'Carol')
932932
t.true(Date.now() - started > 1000, 'fired more than 1s after start')
@@ -949,7 +949,7 @@ test(`user left hook [removes Carol from Bob's room]`, t => {
949949
.then(alice => alice.subscribeToRoom({
950950
roomId: bobsRoom.id,
951951
hooks: {
952-
userLeft: once(user => {
952+
onUserLeft: once(user => {
953953
t.equal(user.id, 'carol')
954954
t.equal(user.name, 'Carol')
955955
t.end()
@@ -976,7 +976,7 @@ test(`new read cursor hook [Bob sets his read cursor in Alice's room]`, t => {
976976
.then(alice => alice.subscribeToRoom({
977977
roomId: alicesRoom.id,
978978
hooks: {
979-
newReadCursor: cursor => {
979+
onNewReadCursor: cursor => {
980980
t.equal(cursor.position, 128)
981981
t.equal(cursor.user.name, 'Bob')
982982
t.equal(cursor.room.name, `Alice's new room`)
@@ -1070,7 +1070,7 @@ test('[setup] promote Alice to admin', t => {
10701070

10711071
test(`update room [renames Bob's room]`, t => {
10721072
fetchUser(t, 'alice', {
1073-
roomUpdated: room => {
1073+
onRoomUpdated: room => {
10741074
t.equal(room.id, bobsRoom.id)
10751075
t.equal(room.name, `Bob's updated room`)
10761076
t.end()
@@ -1088,7 +1088,7 @@ test(`update room [renames Bob's room]`, t => {
10881088
test(`delete room [deletes Bob's room]`, t => {
10891089
let alice
10901090
fetchUser(t, 'alice', {
1091-
roomDeleted: room => {
1091+
onRoomDeleted: room => {
10921092
t.equal(room.id, bobsRoom.id)
10931093
t.false(
10941094
any(r => r.id === bobsRoom.id, alice.rooms),

0 commit comments

Comments
 (0)