Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit d5406aa

Browse files
committed
chore(ngSocket): apply consistent naming to native event handlers
1 parent 439e30b commit d5406aa

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/ngSocket.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,8 @@ angular.module('ngSocket', []).
1414
this.sendQueue = [];
1515
this.onMessageCallbacks = [];
1616

17-
this.socket.onopen = function () {
18-
this.onOpened.apply(this, arguments);
19-
}.bind(this);
20-
21-
this.socket.onmessage = function () {
22-
this._onmessage.apply(this, arguments);
23-
}.bind(this);
17+
this.socket.onopen = this._onOpenHandler.bind(this);
18+
this.socket.onmessage = this._onMessageHandler.bind(this);
2419
};
2520

2621
NGWebSocket.prototype.fireQueue = function () {
@@ -50,7 +45,7 @@ angular.module('ngSocket', []).
5045
this.onMessageCallbacks.push({fn: callback, pattern: pattern});
5146
};
5247

53-
NGWebSocket.prototype._onmessage = function (message) {
48+
NGWebSocket.prototype._onMessageHandler = function (message) {
5449
var pattern;
5550
for (var i = 0; i < this.onMessageCallbacks.length; i++) {
5651
pattern = this.onMessageCallbacks[i].pattern;
@@ -69,7 +64,7 @@ angular.module('ngSocket', []).
6964
}
7065
};
7166

72-
NGWebSocket.prototype.onOpened = function () {
67+
NGWebSocket.prototype._onOpenHandler = function () {
7368
$rootScope.$apply(function () {
7469
this.deferred.resolve();
7570
this.fireQueue.call(this);

test/ngSocket.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ describe('ngSocket', function () {
134134
var mock = {spyable: function () {}}
135135
var spy = spyOn(mock, 'spyable');
136136
ws.onMessage(mock.spyable, 'foo');
137-
ws._onmessage({data: 'bar'});
137+
ws._onMessageHandler({data: 'bar'});
138138
expect(spy).not.toHaveBeenCalled();
139-
ws._onmessage({data: 'foo'});
139+
ws._onMessageHandler({data: 'foo'});
140140
expect(spy).toHaveBeenCalled();
141141
});
142142

@@ -150,9 +150,9 @@ describe('ngSocket', function () {
150150
var mock = {spyable: function () {}}
151151
var spy = spyOn(mock, 'spyable');
152152
ws.onMessage(mock.spyable, /baz[0-9]{2}/);
153-
ws._onmessage({data: 'bar'});
153+
ws._onMessageHandler({data: 'bar'});
154154
expect(spy).not.toHaveBeenCalled();
155-
ws._onmessage({data: 'baz21'});
155+
ws._onMessageHandler({data: 'baz21'});
156156
expect(spy).toHaveBeenCalled();
157157
});
158158

@@ -163,7 +163,7 @@ describe('ngSocket', function () {
163163
});
164164

165165

166-
describe('.onOpened()', function () {
166+
describe('._onOpenHandler()', function () {
167167
it('should resolve and apply', function () {
168168
var resolved = false;
169169
var ws = ngWebSocket('ws://foo');
@@ -172,15 +172,15 @@ describe('ngSocket', function () {
172172
});
173173

174174
expect(resolved).toBe(false);
175-
ws.onOpened.call(ws);
175+
ws._onOpenHandler.call(ws);
176176
expect(resolved).toBe(true);
177177
});
178178

179179

180180
it('should call fireQueue to flush any queued send() calls', function () {
181181
var ws = ngWebSocket('ws://foo');
182182
var spy = spyOn(ws, 'fireQueue');
183-
ws.onOpened.call(ws);
183+
ws._onOpenHandler.call(ws);
184184
expect(spy).toHaveBeenCalled();
185185
});
186186
});

0 commit comments

Comments
 (0)