File tree Expand file tree Collapse file tree 2 files changed +31
-7
lines changed Expand file tree Collapse file tree 2 files changed +31
-7
lines changed Original file line number Diff line number Diff line change 1
- import { Protocol , Dependency } from "./protocol/protocol" ;
1
+ import { Protocol , Dependency , FnArgs } from "./protocol/protocol" ;
2
2
3
- class Gotham {
3
+ export class Gotham {
4
4
moduleId : string ;
5
5
protocol : Protocol
6
6
constructor ( ) {
@@ -11,4 +11,28 @@ class Gotham {
11
11
this . protocol . initialize ( moduleId , version , deps ) ,
12
12
) ;
13
13
}
14
+
15
+ async declareFunction ( fnName : string , fn : Function ) {
16
+ return await this . protocol . sendRequest (
17
+ this . protocol . declareFunction ( fnName , fn )
18
+ ) ;
19
+ }
20
+
21
+ async functionCall ( fnNmame : string , args : FnArgs ) {
22
+ return await this . protocol . sendRequest (
23
+ this . protocol . functionCall ( fnNmame , args )
24
+ ) ;
25
+ }
26
+
27
+ async registerHook ( hook : string , cb : Function ) {
28
+ return await this . protocol . sendRequest (
29
+ this . protocol . registerHook ( hook , cb )
30
+ ) ;
31
+ }
32
+
33
+ async triggerHook ( hook : string ) {
34
+ return await this . protocol . sendRequest (
35
+ this . protocol . triggerHook ( hook )
36
+ ) ;
37
+ }
14
38
}
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ export interface Dependency {
6
6
[ type : string ] : string ;
7
7
}
8
8
9
- interface FnArgs {
9
+ export interface FnArgs {
10
10
[ type : string ] : any ;
11
11
}
12
12
@@ -115,7 +115,7 @@ export class Protocol {
115
115
}
116
116
}
117
117
118
- registerHook ( moduleId : string , hook : string , cb : Function ) : RegisterHookRequest {
118
+ registerHook ( hook : string , cb : Function ) : RegisterHookRequest {
119
119
if ( this . hookListeners [ hook ] ) {
120
120
this . hookListeners [ hook ] = [ cb ] ;
121
121
} else {
@@ -124,7 +124,7 @@ export class Protocol {
124
124
return {
125
125
requestId : this . generateRequestId ( ) ,
126
126
type : 'registerHook' ,
127
- hook : `${ moduleId } -${ hook } ` ,
127
+ hook : `${ this . moduleId } -${ hook } ` ,
128
128
}
129
129
}
130
130
@@ -162,9 +162,9 @@ export class Protocol {
162
162
}
163
163
}
164
164
165
- functionCall ( functionName : string , ... args : FnArgs [ ] ) {
165
+ functionCall ( functionName : string , args : FnArgs ) {
166
166
if ( this . functions [ functionName ] ) {
167
- this . functions [ functionName ] ( ) ;
167
+ this . functions [ functionName ] ( ... args ) ;
168
168
}
169
169
}
170
170
You can’t perform that action at this time.
0 commit comments