From 392a7655c46e0e5c24c7364570a52f7994c9e8ac Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 28 Sep 2020 02:57:30 +0200 Subject: [PATCH] Use property for calculating handler name Replace usage of .constructor.name with a separate property to avoid issue with JavaScript terser mangling the class name during minification for the web build. --- packages/lib/link/messages.js | 4 +++- packages/lib/plugin.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/lib/link/messages.js b/packages/lib/link/messages.js index fe16e7e4..9329b232 100644 --- a/packages/lib/link/messages.js +++ b/packages/lib/link/messages.js @@ -66,6 +66,7 @@ class Request extends Message { this.links = links; this.permission = permission || null; this.forwardTo = forwardTo; + this.handlerSuffix = "RequestHandler"; this.requestType = type + "_request"; this.responseType = type + "_response"; @@ -681,6 +682,7 @@ class Event extends Message { this.links = links; this.forwardTo = forwardTo; this.broadcastTo = broadcastTo; + this.handlerSuffix = "EventHandler"; if (forwardTo === "instance") { eventProperties = { @@ -956,7 +958,7 @@ messages.playerEvent = new Event({ */ function attachAllMessages(link) { for (let [name, message] of Object.entries(messages)) { - message.attach(link, link[name + message.constructor.name + "Handler"]); + message.attach(link, link[name + message.handlerSuffix]); } } diff --git a/packages/lib/plugin.js b/packages/lib/plugin.js index 58f7a657..659a5ee0 100644 --- a/packages/lib/plugin.js +++ b/packages/lib/plugin.js @@ -433,7 +433,7 @@ function attachPluginMessages(link, pluginInfo, plugin) { throw new Error(`Type of ${name} message must start with "${pluginInfo.name}:"`); } - let handler = name + messageFormat.constructor.name + "Handler"; + let handler = name + messageFormat.handlerSuffix; if (plugin === null || !plugin[handler]) { messageFormat.attach(link);