Skip to content

Commit d4788d3

Browse files
authored
Merge pull request #1937 from colinl/1892_prevent_value_clear_on_refresh
Don't save message in datastore unnecessarily
2 parents 0769710 + d7e64d4 commit d4788d3

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

nodes/config/ui_base.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ function hasProperty (obj, prop) {
2626
return Object.prototype.hasOwnProperty.call(obj, prop)
2727
}
2828

29+
/**
30+
* Test whether a message has any properties other than ui_update, class, visible, enabled and _msgid
31+
* Properties with the value undefined are ignored
32+
* @param {*} msg
33+
* @returns true if other properties found
34+
*/
35+
function hasExtraProps (message) {
36+
const allowed = ['_msgid', 'ui_update', 'class', 'visible', 'enabled']
37+
const keys = Object.keys(message).filter(key => message[key] !== undefined)
38+
39+
return keys.length > 0 && keys.some(key => !allowed.includes(key))
40+
}
41+
2942
module.exports = function (RED) {
3043
const express = require('express')
3144
const { Server } = require('socket.io')
@@ -1101,8 +1114,11 @@ module.exports = function (RED) {
11011114
msg = await appendTopic(RED, widgetConfig, wNode, msg)
11021115
}
11031116

1104-
// store the latest msg passed to node
1105-
datastore.save(n, widgetNode, msg)
1117+
// store the latest msg passed to the node unless the message only contains
1118+
// ui_update, visible, enabled or class properties, which are handled in the state store
1119+
if (hasExtraProps(msg)) {
1120+
datastore.save(n, widgetNode, msg)
1121+
}
11061122

11071123
if (hasProperty(widgetConfig, 'passthru')) {
11081124
if (widgetConfig.passthru) {

0 commit comments

Comments
 (0)