Hi,
is there a TW5 core-way (i know i colud write a simple widget by my own) to unset (erase) certain variables (like starting with “xyz.”) for the/a widget-subtree?
Thanks,
Mirko
Hi,
is there a TW5 core-way (i know i colud write a simple widget by my own) to unset (erase) certain variables (like starting with “xyz.”) for the/a widget-subtree?
Thanks,
Mirko
What do you mean by “unset”. Do you want to set the value to empty string like xyz="". Then yes. You can do exactly that. The core should handle this. I did use n/a as a placeholder for the “empty” string, so the differences of TW widget scope can be seen in the screenshot.
\procedure xyz() test
outer xyz -> <<xyz>>
<$let xyz="n/a">
inner xyz -> <<xyz>>
</$let>
outer xyz -> <<xyz>>
If you want to “erase” the variable xyz from the internal memory structure, to “break” the scope, there is no core function to do that.
Hope that makes sense.
Mario
Hi Mario,
yes, erase is the plan and everything you said makes sense.
Thanks for clarification/stating that there is no core-func for that.
Cheers,
Mirko
Hi,
to finish this - for the interested: widget-variables are protected against delete calls but one can set the variable completely to null (e.g. this.variables[var2del] = null; from within your widget) and the test-func [[my-var]is[variable]] fails as expected/hoped. Dirty workaround i know, but i works due to the fantastic failsave behavior of TW5
.
Best,
Mirko
Yes. That’s a bit “dirty”. I am not really sure, what your usecase is.
this.variables[var2del] = null; does not “remove” the variable from the “parent” widget chain (scope). It sets the variable var2del to null. So physically the variable still exists. It’s a bit of a coincidence that [[var2del]is[variable]] returns no variable.
While we try to avoid changes to core function signatures, if the core code is improved. There is no real guarantee, that your code will work forever.
Is there some code, we can inspect, to see, if it would be possible to give more guarantees from the core side of things?
By the way. IMO such “low level” discussions should better happen with a GitHub issue. Where you should describe your usecase.
-Mario