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

Commit 0fa6b58

Browse files
committed
Change storing listener by numeric address representation
Before `getRaw` was used to determine an array key for a group address. This method returns an array of bytes, which is transformed to a string when used as array key. `getNumber` returns an integer representation for the group address and feels more correct for a usage as an array key.
1 parent 3203da4 commit 0fa6b58

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/Connection.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function Connection(driver) {
4949
*/
5050
Connection.prototype._onWriteMessage = function(message) {
5151

52-
var rawAddress = message.getDestination().getRaw(),
52+
var rawAddress = message.getDestination().getNumber(),
5353
callbacks = this._listeners[rawAddress];
5454

5555
if (callbacks) {
@@ -115,7 +115,7 @@ Connection.prototype.send = function(msg, callback) {
115115
Connection.prototype.on = function (address, callback) {
116116
var driver = this._driver,
117117
listeners = this._listeners,
118-
rawAddress = address.getRaw();
118+
rawAddress = address.getNumber();
119119

120120
if (!driver.isConnected()) {
121121
driver.connect();
@@ -134,7 +134,7 @@ Connection.prototype.on = function (address, callback) {
134134
*/
135135
Connection.prototype.off = function(address, callback) {
136136
var listeners = this._listeners,
137-
rawAddress = address.getRaw();
137+
rawAddress = address.getNumber();
138138

139139
if (!callback) {
140140
listeners[rawAddress] = [];

test/ConnectionTest.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ describe('Connection', function() {
130130
var driver = sinon.createStubInstance(Driver),
131131
address = sinon.createStubInstance(GroupAddress),
132132
msg = sinon.createStubInstance(Message),
133-
rawAddress = [0x22, 0x9b],
133+
numAddress = 2563,
134134
callback = sinon.spy(),
135135
connection;
136136

@@ -139,7 +139,7 @@ describe('Connection', function() {
139139

140140
connection = new Connection(driver);
141141

142-
address.getRaw.returns(rawAddress);
142+
address.getNumber.returns(numAddress);
143143
msg.getDestination.returns(address);
144144
msg.getCommand.returns('write');
145145

@@ -155,7 +155,7 @@ describe('Connection', function() {
155155
var driver = sinon.createStubInstance(Driver),
156156
address = sinon.createStubInstance(GroupAddress),
157157
msg = sinon.createStubInstance(Message),
158-
rawAddress = [0x22, 0x9b],
158+
numAddress = 8859,
159159
callbackA = sinon.spy(),
160160
callbackB = sinon.spy(),
161161
connection;
@@ -166,7 +166,7 @@ describe('Connection', function() {
166166

167167
connection = new Connection(driver);
168168

169-
address.getRaw.returns(rawAddress);
169+
address.getNumber.returns(numAddress);
170170
msg.getDestination.returns(address);
171171

172172
connection.on(address, callbackA);
@@ -193,11 +193,11 @@ describe('Connection', function() {
193193

194194
this.createGroupAddress = function() {
195195
var address = sinon.createStubInstance(GroupAddress);
196-
address.getRaw.returns([0x22, addressCounter++]);
196+
address.getNumber.returns(addressCounter++);
197197
return address;
198-
}
198+
};
199199

200-
})
200+
});
201201

202202
it("removes all listeners for a given address", function() {
203203
var callbackA = sinon.spy(),
@@ -239,7 +239,7 @@ describe('Connection', function() {
239239

240240
expect(callbackA).not.to.to.be.called;
241241
expect(callbackB).to.to.be.called;
242-
})
242+
});
243243

244244
});
245245

0 commit comments

Comments
 (0)