Hi @JustinG ,
I am working on a widget where I need to pre-define constants and pre-initialize variables.
Unforunately I cannot re-use a constant in the next constant when they are declared within the same context:
No, that’s true. The properties of the oh-context are not included in the evaluation contexts of other properties of the same oh-context. For example, I suspect you also couldn’t access the constants in a function defined in that same context.
I don’t think you really need to stack these. You’re barely saving any computation at all by trying to avoid reusing the JSON parse (unless this list is 1000’s of elements long). So I would just define each of those constants from basic parts instead of trying to nest them:
Cool. Thanks.
Another solution I have been looking for for 2 hours without success:
I am using a variable in several components of my custom widget. The variable gets its value from action variable buttons.
As the variable is undefined until I press a button I tried to pre-initialize the variable in an oh-context component. This is working fine in general, but the press of one of the above buttons also does a refresh which then resets the variable.
Do you have an idea?
This depends on what you mean by “refresh”. If the button press causes the actual page to reload, then there’s nothing you can do about that. The context variable will always be the default value when the page loads, that’s it’s entire point.
If your button action just causes a redraw of some of the widgets in the page (e.g., by use of the key property on some component), then you can just try to refactor your widget so that the context is above that point in the component tree. The redraw of child components should not result in the context being reloaded.