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

Commit 98fa13c

Browse files
committed
fix(dependencies) move bind polyfill into test script
Instead of using lodash.bind in the main code, just override function.prototype.bind during the browser test code
1 parent 68a3949 commit 98fa13c

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

browser/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
var JsonRpcWs = require('../browser');
88
var browserClient = JsonRpcWs.createClient();
99

10+
Function.prototype.bind = require('function-bind');
11+
1012
browserClient.expose('info', function info (params, reply) {
1113

1214
reply(null, 'browser');

lib/connection.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ var uuid = require('uuid').v4;
22
var logger = require('debug')('json-rpc-ws');
33
var Errors = require('./errors');
44
var Assert = require('assert');
5-
var Bind = require('lodash.bind');
65

76
/**
87
* Quarantined JSON.parse try/catch block in its own function
@@ -65,9 +64,9 @@ var Connection = function Connection (socket, parent) {
6564
this.parent = parent;
6665
this.responseHandlers = {};
6766
if (this.parent.browser) {
68-
this.socket.onmessage = Bind(this.message, this);
69-
this.socket.onclose = Bind(socketClosed, this);
70-
this.socket.onerror = Bind(socketError, this);
67+
this.socket.onmessage = this.message.bind(this)
68+
this.socket.onclose = socketClosed.bind(this);
69+
this.socket.onerror = socketError.bind(this);
7170
} else {
7271
this.socket.on('message', this.message.bind(this));
7372
this.socket.once('close', this.close.bind(this));
@@ -130,9 +129,6 @@ Connection.prototype.processPayload = function processPayload (payload) {
130129
logger('handler got callback %j, %j', err, reply);
131130
return this.sendResult(id, err, reply);
132131
};
133-
if (this.parent.browser) {
134-
return handler.call(this, params, Bind(handlerCallback, this));
135-
}
136132
return handler.call(this, params, handlerCallback.bind(this));
137133
}
138134
// needs a result or error at this point

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"license": "MIT",
2727
"dependencies": {
2828
"debug": "^2.2.0",
29-
"lodash.bind": "^4.0.0",
3029
"uuid": "^2.0.1",
3130
"ws": "^1.0.1"
3231
},
@@ -46,6 +45,7 @@
4645
"code": "^2.0.1",
4746
"eslint": "^1.1.0",
4847
"eslint-plugin-hapi": "^4.0.0",
48+
"function-bind": "^1.0.2",
4949
"git-validate": "^2.0.3",
5050
"jsdoc": "^3.3.2",
5151
"lab": "^8.0.0",

0 commit comments

Comments
 (0)