Skip to content

Commit

Permalink
Account for upgrade path meaning no defaults set for new properties
Browse files Browse the repository at this point in the history
  • Loading branch information
joepavitt committed Dec 22, 2023
1 parent f3998be commit fb9b115
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions nodes/config/ui_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit fb9b115

Please sign in to comment.