|
@@ -12,7 +12,15 @@ export type OnInitHandler = (taipyApp: TaipyApp) => void;
|
|
|
export type OnChangeHandler = (taipyApp: TaipyApp, encodedName: string, value: unknown) => void;
|
|
|
export type OnNotifyHandler = (taipyApp: TaipyApp, type: string, message: string) => void;
|
|
|
export type OnReloadHandler = (taipyApp: TaipyApp, removedChanges: ModuleData) => void;
|
|
|
+export type OnWsMessage = (taipyApp: TaipyApp, event: string, payload: unknown) => void;
|
|
|
export type OnWsStatusUpdate = (taipyApp: TaipyApp, messageQueue: string[]) => void;
|
|
|
+export type OnEvent =
|
|
|
+ | OnInitHandler
|
|
|
+ | OnChangeHandler
|
|
|
+ | OnNotifyHandler
|
|
|
+ | OnReloadHandler
|
|
|
+ | OnWsMessage
|
|
|
+ | OnWsStatusUpdate;
|
|
|
type Route = [string, string];
|
|
|
|
|
|
export class TaipyApp {
|
|
@@ -21,6 +29,7 @@ export class TaipyApp {
|
|
|
_onChange: OnChangeHandler | undefined;
|
|
|
_onNotify: OnNotifyHandler | undefined;
|
|
|
_onReload: OnReloadHandler | undefined;
|
|
|
+ _onWsMessage: OnWsMessage | undefined;
|
|
|
_onWsStatusUpdate: OnWsStatusUpdate | undefined;
|
|
|
_ackList: string[];
|
|
|
variableData: DataManager | undefined;
|
|
@@ -69,6 +78,10 @@ export class TaipyApp {
|
|
|
this._onInit = handler;
|
|
|
}
|
|
|
|
|
|
+ onInitEvent() {
|
|
|
+ this.onInit && this.onInit(this);
|
|
|
+ }
|
|
|
+
|
|
|
get onChange() {
|
|
|
return this._onChange;
|
|
|
}
|
|
@@ -80,6 +93,10 @@ export class TaipyApp {
|
|
|
this._onChange = handler;
|
|
|
}
|
|
|
|
|
|
+ onChangeEvent(encodedName: string, value: unknown) {
|
|
|
+ this.onChange && this.onChange(this, encodedName, value);
|
|
|
+ }
|
|
|
+
|
|
|
get onNotify() {
|
|
|
return this._onNotify;
|
|
|
}
|
|
@@ -91,6 +108,10 @@ export class TaipyApp {
|
|
|
this._onNotify = handler;
|
|
|
}
|
|
|
|
|
|
+ onNotifyEvent(type: string, message: string) {
|
|
|
+ this.onNotify && this.onNotify(this, type, message);
|
|
|
+ }
|
|
|
+
|
|
|
get onReload() {
|
|
|
return this._onReload;
|
|
|
}
|
|
@@ -101,6 +122,24 @@ export class TaipyApp {
|
|
|
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;
|
|
|
}
|
|
@@ -111,6 +150,10 @@ export class TaipyApp {
|
|
|
this._onWsStatusUpdate = handler;
|
|
|
}
|
|
|
|
|
|
+ onWsStatusUpdateEvent(messageQueue: string[]) {
|
|
|
+ this.onWsStatusUpdate && this.onWsStatusUpdate(this, messageQueue);
|
|
|
+ }
|
|
|
+
|
|
|
// Utility methods
|
|
|
init() {
|
|
|
this.clientId = "";
|
|
@@ -134,7 +177,7 @@ export class TaipyApp {
|
|
|
const ackId = sendWsMessage(this.socket, type, id, payload, this.clientId, context);
|
|
|
if (ackId) {
|
|
|
this._ackList.push(ackId);
|
|
|
- this.onWsStatusUpdate && this.onWsStatusUpdate(this, this._ackList);
|
|
|
+ this.onWsStatusUpdateEvent(this._ackList);
|
|
|
}
|
|
|
}
|
|
|
|