lorenwest / node-red-contrib-state

Node-RED shared logical state with persistence, notification, and history
MIT License
7 stars 6 forks source link

Usage of period for state name causes problem with global.state #1

Closed devmare closed 4 years ago

devmare commented 4 years ago

SET STATE NODE person.tom DEBUG OUTPUT global.state.person.tom -> undefined

Support usage of special chars or white list allowed ones

lorenwest commented 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?

lorenwest commented 4 years ago

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?

devmare commented 4 years ago

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.

devmare commented 4 years ago

Don't replace special chars automatically. It is better to error this that it has to be changed by the user.

lorenwest commented 4 years ago

Would you try to support . as objects with the associated complexity, or would you add . to the list of special characters not supported?

devmare commented 4 years ago

I would not support this as this is also not supported by naming convention.

devmare commented 4 years ago

Useful website for validation https://mothereff.in/js-variables

lorenwest commented 4 years ago

I'll probably use an npm module like is-valid-var-name, and let someone else keep up as JS changes

lorenwest commented 4 years ago

Thanks for the feedback. Hope you're getting good use out of this node-red-contrib!

devmare commented 4 years ago

Good idea to use the validation module. Your module is really useful. Thank you.

lorenwest commented 4 years ago

State name validation added and published in 1.4.0. Thanks for your input!