Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI Base: Account for upgrade path meaning no defaults set for new properties #453

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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