Skip to content

Commit b0a3656

Browse files
committed
fix: Use Arrow functions to preserve 'this' from parent scope when passing functions as args
1 parent 9b3198f commit b0a3656

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/connection/socket-connection.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export default class SocketConnection extends BaseConnection {
1313
setupConnection(): Promise<void> {
1414
return new Promise(resolve => {
1515
this.client = net.createConnection(this.sockPath);
16-
this.client.on('data', this.onData);
16+
this.client.on('data', (data) => {
17+
this.onData(data);
18+
});
1719
this.client.on('connect', () => {
1820
resolve();
1921
});

src/gotham-node.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default class GothamModule {
2222
constructor(connection: BaseConnection, protocol: BaseProtocol) {
2323
this.protocol = protocol;
2424
this.connection = connection;
25-
this.connection.setOnDataListener(this.onDataHandler);
25+
// this.connection.setOnDataListener(this.onDataHandler);
2626
}
2727

2828
public static default(socketPath: string): GothamModule {
@@ -36,7 +36,9 @@ export default class GothamModule {
3636
) {
3737
// Setup Connection only when initialize called?
3838
await this.connection.setupConnection();
39-
this.connection.setOnDataListener(this.onDataHandler);
39+
this.connection.setOnDataListener((data) => {
40+
this.onDataHandler(data);
41+
});
4042
return this.sendRequest(
4143
this.protocol.initialize(
4244
moduleId,

0 commit comments

Comments
 (0)