ioBroker / ioBroker.example

Template adapter for ioBroker
44 stars 73 forks source link

Es6 Template and Translation Gulp Task #26

Closed jogibear9988 closed 5 years ago

AlCalzone commented 5 years ago

Superseded by #32 and #33 - should be closed @Apollon77

jogibear9988 commented 5 years ago

do we have a ES6 template in generator? as long as we don‘t have i would leave it open

AlCalzone commented 5 years ago

Yup: https://github.com/ioBroker/create-adapter/blob/master/CHANGELOG.md#180-2019-01-24 and https://github.com/ioBroker/ioBroker.template/blob/master/JavaScript/main.js

AlCalzone commented 5 years ago

@jogibear9988 I have a small update for the constructor. Since you pioneered the ES6 classes, could you please test if the following works as the adapter constructor? You might need to rename the methods to _ready and so on.

    constructor(options) {
        Object.assign(options, {
            name: 'test-adapter',
        });
        super(options);
        // After the super call, overwrite the methods on the options object
        Object.assign(options, {
            ready: this.onReady.bind(this),
            objectChange: this.onObjectChange.bind(this),
            stateChange: this.onStateChange.bind(this),
            // message: this.onMessage.bind(this),
            unload: this.onUnload.bind(this),
        });
    }

I wanted to avoid using events, so we can (for example) make use of this PR https://github.com/ioBroker/ioBroker.js-controller/pull/316 which allows the unload method to just be an async method instead of having to call the callback.

AlCalzone commented 5 years ago

This is obsolete now.