Closed devmare closed 4 years ago
Good idea. This global state becomes Javascript variables, and periods could be converted to objects, but they can clash. For example:
person.tom = true
person.tom.weight = 182
If we converted periods to objects it wouldn't work for person.tom
above. Also, since this state is represented in Javascript, do you think it's better to try to allow for special characters or to deny their usage?
One way to do it is to error if someone tries to enter a special character. Another would be to replace all special characters with _
. Another option is to escape the special character. Which would you prefer?
I would deny special chars which can cause problems.
According to JS coding standards following rules apply for variable naming: Names can contain letters, digits, underscores, and dollar signs Names must begin with a letter Names can also begin with $ and _ Names are case sensitive Reserved words (like JavaScript keywords) cannot be used as names
But you can keep this simpler if you like.
Don't replace special chars automatically. It is better to error this that it has to be changed by the user.
Would you try to support .
as objects with the associated complexity, or would you add .
to the list of special characters not supported?
I would not support this as this is also not supported by naming convention.
Useful website for validation https://mothereff.in/js-variables
I'll probably use an npm module like is-valid-var-name, and let someone else keep up as JS changes
Thanks for the feedback. Hope you're getting good use out of this node-red-contrib!
Good idea to use the validation module. Your module is really useful. Thank you.
State name validation added and published in 1.4.0. Thanks for your input!
SET STATE NODE person.tom DEBUG OUTPUT global.state.person.tom -> undefined
Support usage of special chars or white list allowed ones