Adding support for mustache-like substitution in Change node msg/flow types #43
Replies: 6 comments 5 replies
-
I think this is a huge improvement when you are actually developing code inside the node. My opinion is that we should keep it explicit, so the |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I've been poking around at this and I have a slightly different proposal - not to use mustache-syntax at all. Taking my original example: If you were writing the equivalent in JavaScript, you'd write I think that is more familiar and intuitive to a new user - no need to learn about the The code that parses property expressions is already strict and would flag up The one downside of not using Going back to the original example, if the keys were instead So, to summarise, the new proposal is to support |
Beta Was this translation helpful? Give feedback.
-
Better to be explicit I think - so The fact it isn't mustache syntax means no worries of inconsistencies with other places mustache is used (eg Http request) |
Beta Was this translation helpful? Give feedback.
-
It occurs to me, the What it cannot do is handle I am tempted, for an initial pass of this, to limit it only supporting |
Beta Was this translation helpful? Give feedback.
-
PR that adds support for nested |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
See #43 (comment) for an updated proposal
Proposal: add support for mustache syntax in themsg
/flow
/global
TypedInput.The Change node is the main node we provide for setting node properties. It is easy to use when setting a well-defined message or context property. The problem comes when you need to dynamically determine the property to set.
For example, you are receiving temperatures from a number of sensors. Each message has
msg.topic
set to the room the sensor is in andmsg.payload
is the value. You want to store the current temperature of each room in context underflow.rooms
- for exampleflow.rooms.kitchen
andflow.rooms.garage
.To do this with the Change node today requires the use of JSONata. For example:
flow.rooms
to the Expression$merge([$flowContext('rooms'),{$.topic:$.payload}])
More likely, users will fall back to a Function node - something it would be nice to avoid.
It would be much more user friendly to be able to do:
flow.rooms.{{msg.topic}}
tomsg.payload
We do often get users asking for help because they have tried to do something like that. If we build mustache-like support into the TypedInput then all nodes that use it will benefit.
I think this would be an important usability improvement.
One open question is whether the syntax would be
{{msg.topic}}
or just{{topic}}
. The HTTP Request node's support for mustache does not require themsg.
prefix - but it cannot be used to reference context values.I think we would be flexible. Given the value
{{AAA.BBB}}
:AAA
ismsg
, the lookupmsg.BBB
AAA
isflow
- check ifmsg.flow
exists. If it does, lookupmsg.flow.BBB
. Otherwise useflow.BBB
AAA
isglobal
- check ifmsg.global
exists. If it does, lookupmsg.global.BBB
. Otherwise useglobal.BBB
msg.AAA.BBB
I say 'mustache-like' syntax, as we're only talking about
{{ }}
- not the other mustache syntax.Beta Was this translation helpful? Give feedback.
All reactions