on 2022 Aug 11 4:56 PM
Hi all,
I have a ngui plugin that works for SCCO FP12 at the moment. In the plugin I have a javascript class for manage the events with the event bus and the GUI. The plugin has a lot of funcionality and this javascript class is getting longer and longer. I want to modularised the code and create others javascript classes in order to separate the functionalities, but, ¿how can I call or reference the other javascript clases from the 'main' javascript class?
Example:
This is part of the 'main' javascript class...
Plugin.MyPlugin = class MyPlugin {
constructor(pluginService, eventBus) {
this.pluginService = pluginService;
this.eventBus = eventBus;
this.init();
}
init() {
if (this.eventBus != null) {
//Add a subscriber to the eventBus
this.eventBus.subscribe({
handleEvent: (event) => {
console.log(event);
switch(event.getType()){
case 'CHANGE_PAYMENT_METHOD':
const payload = event.getPayload();
if(payload['method'] == 'CARD') {
this.getVoucherNum();
}
break;
case 'PAYMENT_ADD':
this.eventBus.push('STATE_CHANGE', 'SALE');
break;
//more than 40 cases more...
}
}
});
}
}
... and I want to create another javascript class to manage events for certain functionality:
Plugin.MyPlugin2 = class MyPlugin2 {
constructor(pluginService, eventBus) {
this.pluginService = pluginService;
this.eventBus = eventBus;
this.init();
}
init() {
if (this.eventBus != null) {
//Add a subscriber to the eventBus
this.eventBus.subscribe({
handleEvent: (event) => {
console.log(event);
//handle events
}
});
}
}
¿How can I reference or call MyPlugin2 from MyPlugin in order to send the events there and so, have the code separated?
Thanks a lot.
Request clarification before answering.
I got the solution.
Just create a separated file for the NGUI and in the jsInject method in the plugin add the reference to this file.
@JSInject(targetScreen = "NGUI")
public InputStream[] jsInject() {
InputStream handler1 = this.getClass().getResourceAsStream("/resources/ngui/ngui_handler1.js");
InputStream handler2 = this.getClass().getResourceAsStream("/resources/ngui/ngui_handler2.js");
return new InputStream[] { handler1 , handler2 };<br>
}<br>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.