Skip to content

Commit 7380679

Browse files
committed
- fix removing RT command listener for Channel
1 parent 5d40380 commit 7380679

File tree

5 files changed

+59
-5
lines changed

5 files changed

+59
-5
lines changed

backendless.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ declare module Backendless {
12191219

12201220
removeCommandListener(callback: (command: Object) => void): ChannelClass;
12211221

1222-
removeCommandListeners(): ChannelClass;
1222+
removeCommandListeners(callback?: (command: Object) => void): ChannelClass;
12231223

12241224
addUserStatusListener(callback: (userStates: Object) => void, onError?: (error: Object) => void): ChannelClass;
12251225

src/messaging/channel/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ export default class Channel extends RTScopeConnector {
115115
return this
116116
}
117117

118+
removeCommandListener(callback) {
119+
super.removeCommandListeners.call(this, callback)
120+
121+
return this
122+
}
123+
118124
removeCommandListeners(callback) {
119125
super.removeCommandListeners.call(this, callback)
120126

src/rso/connection.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ export default class RemoteSharedObject extends RTScopeConnector {
9494
return this
9595
}
9696

97+
removeCommandListener(callback) {
98+
super.removeCommandListeners.call(this, callback)
99+
100+
return this
101+
}
102+
97103
removeCommandListeners(callback) {
98104
super.removeCommandListeners.call(this, callback)
99105

test/unit/specs/messaging/channel.js

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,8 @@ describe('<Messaging> Channel', function() {
947947
expect(sub3.name).to.be.equal('PUB_SUB_COMMANDS')
948948
expect(sub3.options).to.be.eql({ channel: 'TEST_CHANNEL_NAME' })
949949

950-
channel.removeCommandListeners(callback1)
951-
channel.removeCommandListeners(callback2)
950+
channel.removeCommandListener(callback1)
951+
channel.removeCommandListener(callback2)
952952

953953
const subOff1 = await subOff1Promise
954954
const subOff2 = await subOff2Promise
@@ -958,6 +958,48 @@ describe('<Messaging> Channel', function() {
958958

959959
})
960960

961+
it('removes all simple listeners', async () => {
962+
const sub1Promise = rtClient.getNext_SUB_ON() // PUB_SUB_CONNECT
963+
const sub2Promise = rtClient.getNext_SUB_ON() // PUB_SUB_COMMANDS
964+
const sub3Promise = rtClient.getNext_SUB_ON() // PUB_SUB_COMMANDS
965+
const subOff1Promise = rtClient.getNext_SUB_OFF() // PUB_SUB_COMMANDS
966+
const subOff2Promise = rtClient.getNext_SUB_OFF() // PUB_SUB_COMMANDS
967+
968+
const callback1 = () => ({})
969+
const callback2 = () => ({})
970+
971+
channel.addCommandListener(callback1)
972+
channel.addCommandListener(callback2)
973+
974+
const sub1 = await sub1Promise
975+
976+
expect(sub1.id).to.be.a('string')
977+
expect(sub1.name).to.be.equal('PUB_SUB_CONNECT')
978+
expect(sub1.options).to.be.eql({ channel: 'TEST_CHANNEL_NAME' })
979+
980+
rtClient.subReady(sub1.id)
981+
982+
const sub2 = await sub2Promise
983+
984+
expect(sub2.id).to.be.a('string')
985+
expect(sub2.name).to.be.equal('PUB_SUB_COMMANDS')
986+
expect(sub2.options).to.be.eql({ channel: 'TEST_CHANNEL_NAME' })
987+
988+
const sub3 = await sub3Promise
989+
990+
expect(sub3.id).to.be.a('string')
991+
expect(sub3.name).to.be.equal('PUB_SUB_COMMANDS')
992+
expect(sub3.options).to.be.eql({ channel: 'TEST_CHANNEL_NAME' })
993+
994+
channel.removeCommandListeners()
995+
996+
const subOff1 = await subOff1Promise
997+
const subOff2 = await subOff2Promise
998+
999+
expect(sub2.id).to.be.equal(subOff1.id)
1000+
expect(sub3.id).to.be.equal(subOff2.id)
1001+
})
1002+
9611003
it('sends command', async () => {
9621004
const sub1Promise = rtClient.getNext_SUB_ON() // PUB_SUB_CONNECT
9631005

test/unit/specs/rso.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ describe('RSO', function() {
259259
expect(sub3.name).to.be.equal('RSO_COMMANDS')
260260
expect(sub3.options).to.be.eql({ name: 'TEST_RSO_NAME' })
261261

262-
rso.removeCommandListeners(callback1)
263-
rso.removeCommandListeners(callback2)
262+
rso.removeCommandListener(callback1)
263+
rso.removeCommandListener(callback2)
264264

265265
const subOff1 = await subOff1Promise
266266
const subOff2 = await subOff2Promise

0 commit comments

Comments
 (0)