attachEvent function in lifecycle component event is a BAD IDEA (for beginners)

According to documentation:
https://webix.gitbook.io/webix-jet/part-ii-webix-jet-in-details/view-communication#attaching-an-event-listener

there is a suggestion to attach the event listener in the component as follows ( bad pattern)

// views/form.js
import {JetView} from "webix-jet";

export default class FormView extends JetView{
    init(){
        this.app.attachEvent("save:form", function(){
            this.show("aftersave");
        });
    }
}

Never use “app.attachEvent” in the lifecycle event component unless you want to manually detach events
Here’s why:
https://snippet.webix.com/e46olhjn

see console after app.refresh() => script error

If you use plugins which they use app.refresh() (i.e. Locale, Theme) or call it manually, subsequent event handling will be additive.

Do this instead:

// views/form.js
import {JetView} from "webix-jet";

export default class FormView extends JetView{
    init(){
        this.on(this.app, "save:form", function(){
            this.show("aftersave");
        });
    }
}

It would be nice to correct this in the documentation.

Hi,

yes, you are right, this.on is the preferred way, attachEvent was listed as the other, less loved one, with a remark that the listener will live till the end of app. However, the example was lacking detachEvent in the destructor to further emphasize this point. After thinking a bit about it all, we decided to remove the 2nd way altogether, so now the docs says only about this.on.