Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
devmare opened this issue Mar 6, 2020 · 11 comments
Closed

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

devmare opened this issue Mar 6, 2020 · 11 comments

Comments

@devmare
Copy link

devmare commented Mar 6, 2020

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

Support usage of special chars or white list allowed ones

@lorenwest
Copy link
Owner

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
Copy link
Owner

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
Copy link
Author

devmare commented Mar 6, 2020

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
Copy link
Author

devmare commented Mar 6, 2020

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

@lorenwest
Copy link
Owner

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

@devmare
Copy link
Author

devmare commented Mar 6, 2020

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

@devmare
Copy link
Author

devmare commented Mar 6, 2020

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

@lorenwest
Copy link
Owner

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

@lorenwest
Copy link
Owner

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

@devmare
Copy link
Author

devmare commented Mar 6, 2020

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

@lorenwest
Copy link
Owner

lorenwest commented Mar 9, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants