Javascript simplification

In the flowfuse dashboard code in nodes/widgets/ui-text.js I see the code

            // Process the value using TypedInput configuration
            const processValue = async () => {
                const value = msg.payload // default to payload if evaluation fails

                if (config.valueType && config.value) {
                    const results = await asyncEvaluateNodeProperty(RED, config.value, config.valueType, node, msg)
                    msg.payload = results
                } else {
                    msg.payload = value
                }
            }

            try {
                await processValue()
            } catch (err) {
                node.warn('Error evaluating value property: ' + err.message)
                // msg.payload remains unchanged on error
            }

Am I right in thinking that processValue() can simplified to

            // Process the value using TypedInput configuration
            const processValue = async () => {
                // defaults to leaving existing payload untouched if evaluation fails
                if (config.valueType && config.value) {
                    msg.payload = await asyncEvaluateNodeProperty(RED, config.value, config.valueType, node, msg)
                }
            }

Or is there some subtlety that I am missing?

I think you're right. Can't see any gotchas hidden in there.

1 Like

OK, thanks. I will create a PR. It is only a small thing, but it is good to reduce the amount of code rather than continually increasing it. Slightly offsetting the rule that the amount of code in a system innexorably grows to use up all the available resources.

1 Like