Changing the method name from "triggerMessage" to "displayActionMessage".

Generally speaking, I like to call the message at the bottom an "action message".
And things can "trigger" it, but in the case of a method that actually proactively displays the message, I find "displayActionMessage" to be a better name.

Also, removing package-lock files and improving code style
This commit is contained in:
David Négrier
2021-08-04 19:31:17 +02:00
parent 82832b7055
commit d1e5d57459
12 changed files with 81 additions and 9020 deletions
+50
View File
@@ -0,0 +1,50 @@
import {
MessageReferenceEvent,
removeActionMessage,
triggerActionMessage,
TriggerActionMessageEvent,
} from "../../Events/ui/TriggerActionMessageEvent";
import { queryWorkadventure } from "../IframeApiContribution";
function uuidv4() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0,
v = c === "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
export let triggerMessageInstance: ActionMessage | undefined = undefined;
export class ActionMessage {
uuid: string;
constructor(private message: string, private callback: () => void) {
this.uuid = uuidv4();
if (triggerMessageInstance) {
triggerMessageInstance.remove();
}
triggerMessageInstance = this;
this.create();
}
async create() {
await queryWorkadventure({
type: triggerActionMessage,
data: {
message: this.message,
uuid: this.uuid,
} as TriggerActionMessageEvent,
});
this.callback();
}
async remove() {
await queryWorkadventure({
type: removeActionMessage,
data: {
uuid: this.uuid,
} as MessageReferenceEvent,
});
triggerMessageInstance = undefined;
}
}