OI4 / oi4-oec-service

An OI4-compliant base service covering most of the "mandatory" functionality by the development guideline
MIT License
2 stars 0 forks source link

Use arrow function to call a function from another class #83

Closed chrfranz closed 2 years ago

chrfranz commented 2 years ago

Introduced type-safe arguments for the functions passed to the MqttMessageProcessor constructor. This exposes that there is a problem in the MqttMessageProcessor.setConfig() method (missing subResource). Currently I have added a TODO there.

The functions sendResource and sendMetaData are now passed via arrow functions in the constructor of the MqttMessageProcessor. This fixes the exception that I got when calling the sendResource method from the MqttMessageProcessor:

async sendResource(resource, messageId, subResource, filter, page = 0, perPage = 0) {

    // throws exception: preparePayload type not found
    //
    // the reason is that the this-keyword points to MqttMessageProcessor and a 
    // method MqttMessageProcessor.preparePayload does not exist
    const validatedPayload = await this.preparePayload(resource, subResource, filter);
   ...
}

See also https://stackoverflow.com/questions/20279484/how-to-access-the-correct-this-inside-a-callback