Repository: Avaiga/taipy
File: frontend/taipy-gui/base/src/app.ts (TypeScript)

Code before:
        this._onReload = handler;
    }

    get onWsMessage() {
        return this._onWsMessage;
    }
    set onWsMessage(handler: OnWsMessage | undefined) {
        if (handler !== undefined && handler?.length !== 3) {
            throw new Error("onWsMessage() requires three parameters");
        }
        this._onWsMessage = handler;
    }

    get onWsStatusUpdate() {
        return this._onWsStatusUpdate;
    }
    set onWsStatusUpdate(handler: OnWsStatusUpdate | undefined) {
        if (handler !== undefined && handler?.length !== 2) {
            throw new Error("onWsStatusUpdate() requires two parameters");
        }
        this._onWsStatusUpdate = handler;
    }

    useEvent(event: OnEvent | undefined, ...args: unknown[]) {
        if (!event) {
            return
        }
        if (event === this.onInit) {
            return this.onInit(this);
        }
        if (event === this.onChange) {
            return this.onChange(this, args[0] as string, args[1]);
        }
        if (event === this.onNotify) {
            return this.onNotify(this, args[0] as string, args[1] as string);
        }
        if (event === this.onReload) {
            return this.onReload(this, args[0] as ModuleData);
        }
        if (event === this.onWsMessage) {
            return this.onWsMessage(this, args[0] as string, args[1]);
        }
        if (event === this.onWsStatusUpdate) {
            return this.onWsStatusUpdate(this, args[0] as string[]);
        }
    }

    // Utility methods
    init() {
        this.clientId = "";
        this.context = "";

Review comment (suggestion):
I thought you would only defined the setter and let the on&lt;whatever> (ie onWsMessage here) be a real method with parameter that would check the existence of this._onWsMessage and call it

ie 
```
onWsMessage = (event, payload) => {
  this._onWsMessage && this._onWsMessage(event, payload);
}
```
I think we're loosing params checking with a single onUserEvent

Code after:
    set onNotify(handler: OnNotifyHandler | undefined) {
        if (handler !== undefined && handler.length !== 3) {
            throw new Error("onNotify() requires three parameters");
        }
        this._onNotify = handler;
    }

    onNotifyEvent(type: string, message: string) {
        this.onNotify && this.onNotify(this, type, message);
    }

    get onReload() {
        return this._onReload;
    }
    set onReload(handler: OnReloadHandler | undefined) {
        if (handler !== undefined && handler?.length !== 2) {
            throw new Error("onReload() requires two parameters");
        }
        this._onReload = handler;
    }

    onReloadEvent(removedChanges: ModuleData) {
        this.onReload && this.onReload(this, removedChanges);
    }

    get onWsMessage() {
        return this._onWsMessage;
    }
    set onWsMessage(handler: OnWsMessage | undefined) {
        if (handler !== undefined && handler?.length !== 3) {
            throw new Error("onWsMessage() requires three parameters");
        }
        this._onWsMessage = handler;
    }

    onWsMessageEvent(event: string, payload: unknown) {
        this.onWsMessage && this.onWsMessage(this, event, payload);
    }

    get onWsStatusUpdate() {
        return this._onWsStatusUpdate;
    }
    set onWsStatusUpdate(handler: OnWsStatusUpdate | undefined) {
        if (handler !== undefined && handler?.length !== 2) {
            throw new Error("onWsStatusUpdate() requires two parameters");
        }
        this._onWsStatusUpdate = handler;
    }

    onWsStatusUpdateEvent(messageQueue: string[]) {
        this.onWsStatusUpdate && this.onWsStatusUpdate(this, messageQueue);