From fb9b115dcf2b7871c315ca75dfc6fd0770157661 Mon Sep 17 00:00:00 2001 From: Joe Pavitt Date: Fri, 22 Dec 2023 20:50:14 +0000 Subject: [PATCH] Account for upgrade path meaning no defaults set for new properties --- nodes/config/ui_base.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/nodes/config/ui_base.js b/nodes/config/ui_base.js index ed6778ec4..bcfbf8ee0 100644 --- a/nodes/config/ui_base.js +++ b/nodes/config/ui_base.js @@ -45,9 +45,19 @@ module.exports = function (RED) { function init (node, config) { node.uiShared = uiShared // ensure we have a uiShared object on the node (for testing mainly) + if (!config.acceptsClientConfig) { + // for those upgrading, we need this for backwards compatibility + config.acceptsClientConfig = ['ui-control', 'ui-notification'] + } + + if (!('includeClientData' in config)) { + // for those upgrading, we need this for backwards compatibility + config.includeClientData = true + } + // expose these properties at runtime - node.acceptsClientConfig = config.acceptsClientConfig || [] // which node types can be scoped to a specific client - node.includeClientData = config.includeClientData || false // whether to include client data in msg payloads + node.acceptsClientConfig = config.acceptsClientConfig // which node types can be scoped to a specific client + node.includeClientData = config.includeClientData // whether to include client data in msg payloads // eventually check if we have routes used, so we can support multiple base UIs if (!uiShared.app) { @@ -275,7 +285,7 @@ module.exports = function (RED) { */ function emit (event, msg, wNode) { Object.values(uiShared.connections).forEach(conn => { - const nodeAllowsConstraints = n.acceptsClientConfig.includes(wNode.type) + const nodeAllowsConstraints = n.acceptsClientConfig?.includes(wNode.type) if ((nodeAllowsConstraints && isValidConnection(conn, msg)) || !nodeAllowsConstraints) { conn.emit(event, msg) }