Skip to content

Commit aa26588

Browse files
committed
fix: spaces -> tabs
1 parent 3d76503 commit aa26588

File tree

5 files changed

+275
-276
lines changed

5 files changed

+275
-276
lines changed

.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#root = true
22

33
[*]
4-
indent_style = space
4+
indent_style = tab
55
end_of_line = lf
66
charset = utf-8
77
trim_trailing_whitespace = true
88
insert_final_newline = true
99
max_line_length = 100
10-
indent_size = 2
10+
indent_size = 4
1111

1212
[*.md]
1313
trim_trailing_whitespace = false

src/constants.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
export const constants = {
2-
requestType: {
3-
moduleRegistration: 'moduleRegistration',
4-
functionCall: 'functionCall',
5-
registerHook: 'registerHook',
6-
triggerHook: 'triggerHook',
7-
declareFunction: 'declareFunction',
8-
},
9-
responseType: {
10-
moduleRegistered: 'moduleRegistered',
11-
functionResponse: 'functionResponse',
12-
hookRegistered: 'hookRegistered',
13-
hookTriggered: 'hookTriggered',
14-
functionDeclared: 'functionDeclared'
15-
}
2+
requestType: {
3+
moduleRegistration: 'moduleRegistration',
4+
functionCall: 'functionCall',
5+
registerHook: 'registerHook',
6+
triggerHook: 'triggerHook',
7+
declareFunction: 'declareFunction',
8+
},
9+
responseType: {
10+
moduleRegistered: 'moduleRegistered',
11+
functionResponse: 'functionResponse',
12+
hookRegistered: 'hookRegistered',
13+
hookTriggered: 'hookTriggered',
14+
functionDeclared: 'functionDeclared'
15+
}
1616
};
1717

1818
export default constants;

src/gotham-node.ts

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,44 @@ import { Protocol, Dependency, FnArgs } from "./protocol/protocol";
22
import { GothamConnection, SocketConnection } from './protocol/GothamConnection';
33

44
export class GothamModule {
5-
protocol: Protocol
6-
constructor(connection: GothamConnection) {
7-
this.protocol = new Protocol(connection);
8-
}
5+
protocol: Protocol
6+
constructor(connection: GothamConnection) {
7+
this.protocol = new Protocol(connection);
8+
}
99

10-
async initialize(moduleId: string, version: string, deps: Dependency) {
11-
// Setup Connection only when initialize called?
12-
await this.protocol.connect();
13-
return await this.protocol.sendRequest(
14-
this.protocol.initialize(moduleId, version, deps),
15-
);
16-
}
10+
async initialize(moduleId: string, version: string, deps: Dependency) {
11+
// Setup Connection only when initialize called?
12+
await this.protocol.connect();
13+
return await this.protocol.sendRequest(
14+
this.protocol.initialize(moduleId, version, deps),
15+
);
16+
}
1717

18-
async declareFunction(fnName: string, fn: Function) {
19-
return await this.protocol.sendRequest(
20-
this.protocol.declareFunction(fnName, fn)
21-
);
22-
}
18+
async declareFunction(fnName: string, fn: Function) {
19+
return await this.protocol.sendRequest(
20+
this.protocol.declareFunction(fnName, fn)
21+
);
22+
}
2323

24-
async functionCall(fnNmame: string, args: FnArgs) {
25-
return await this.protocol.sendRequest(
26-
this.protocol.callFunction(fnNmame, args)
27-
);
28-
}
24+
async functionCall(fnNmame: string, args: FnArgs) {
25+
return await this.protocol.sendRequest(
26+
this.protocol.callFunction(fnNmame, args)
27+
);
28+
}
2929

30-
async registerHook(hook: string, cb: Function) {
31-
return await this.protocol.sendRequest(
32-
this.protocol.registerHook(hook, cb)
33-
);
34-
}
30+
async registerHook(hook: string, cb: Function) {
31+
return await this.protocol.sendRequest(
32+
this.protocol.registerHook(hook, cb)
33+
);
34+
}
3535

36-
async triggerHook(hook: string) {
37-
return await this.protocol.sendRequest(
38-
this.protocol.triggerHook(hook)
39-
);
40-
}
36+
async triggerHook(hook: string) {
37+
return await this.protocol.sendRequest(
38+
this.protocol.triggerHook(hook)
39+
);
40+
}
4141

42-
async close() {
43-
return await this.protocol.close();
44-
}
42+
async close() {
43+
return await this.protocol.close();
44+
}
4545
}

src/protocol/GothamConnection.ts

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,50 @@ import * as net from 'net';
22

33
type dataListenerFn = (data: any) => any;
44
export abstract class GothamConnection {
5-
dataListener: dataListenerFn = (data) => {};
6-
7-
abstract async setupConnection(): Promise<any>;
8-
abstract async closeConnection(): Promise<any>;
9-
abstract setupDataListener(dataListener: dataListenerFn): any;
10-
abstract async send(message: object): Promise<void>;
5+
dataListener: dataListenerFn = (data) => { };
6+
abstract async setupConnection(): Promise<any>;
7+
abstract async closeConnection(): Promise<any>;
8+
abstract setupDataListener(dataListener: dataListenerFn): any;
9+
abstract async send(message: object): Promise<void>;
1110
}
1211

1312

1413

1514
export class SocketConnection extends GothamConnection {
16-
client!: net.Socket;
17-
sockPath: string;
18-
constructor(sockPath: string) {
19-
super();
20-
this.sockPath = sockPath;
21-
}
22-
23-
async setupConnection() {
24-
return new Promise((resolve, reject) => {
25-
this.client = net.createConnection(this.sockPath);
26-
this.client.on('connect', () => {
27-
// console.log(`Connected to ${this.sockPath}!`);
28-
resolve();
29-
});
30-
});
31-
}
32-
33-
async closeConnection() {
34-
this.client.destroy();
35-
}
36-
37-
setupDataListener(dataListener: dataListenerFn) {
38-
this.dataListener = (data: Buffer) => {
39-
const parsed = JSON.parse(data.toString('utf-8'));
40-
// console.log("Socket Received Data:");
41-
// console.log(parsed);
42-
dataListener(parsed);
43-
};
44-
this.client.on('data', this.dataListener);
45-
}
46-
47-
async send(message: object) {
48-
// console.log("Socker Sending data:");
49-
// console.log(message);
50-
this.client.write(JSON.stringify(message) + '\n');
51-
}
15+
client!: net.Socket;
16+
sockPath: string;
17+
constructor(sockPath: string) {
18+
super();
19+
this.sockPath = sockPath;
20+
}
21+
22+
async setupConnection() {
23+
return new Promise((resolve, reject) => {
24+
this.client = net.createConnection(this.sockPath);
25+
this.client.on('connect', () => {
26+
// console.log(`Connected to ${this.sockPath}!`);
27+
resolve();
28+
});
29+
});
30+
}
31+
32+
async closeConnection() {
33+
this.client.destroy();
34+
}
35+
36+
setupDataListener(dataListener: dataListenerFn) {
37+
this.dataListener = (data: Buffer) => {
38+
const parsed = JSON.parse(data.toString('utf-8'));
39+
// console.log("Socket Received Data:");
40+
// console.log(parsed);
41+
dataListener(parsed);
42+
};
43+
this.client.on('data', this.dataListener);
44+
}
45+
46+
async send(message: object) {
47+
// console.log("Socker Sending data:");
48+
// console.log(message);
49+
this.client.write(JSON.stringify(message) + '\n');
50+
}
5251
}

0 commit comments

Comments
 (0)