-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Is any of these options are preferred. As I know shadow elements were released recently and introduced tag apply which is now more preferred than old tag include. Is this statement relevant for if too?
Hi There,
Yes, Shadow Element "if" is generally preferred over ZUML conditional evaluation "if" for a number of reasons. For example, if you use an test="@init(value)" or test="${value}", these expressions are not dynamic. Shadow element will instantiate and then delete itself since no updates are possible on that expression, which can end up saving memory and performances.
if you use an expression with dynamic updates (MVVM databinding), then Shadow Element "if" is still a better choice, since it's optimized for this usage.
And lastly, the ZUML conditional evaluation "if" will still create children components in memory at server side, but not send them to the client. Shadow element "if" will instantiate content only if the condition is met. If the content of the "if" statement has some large objects, or some computation time, this can reduce the page's memory / cpu load.
TL:DR unless you have a very specific reason to choose another option, shadow element in a better option
https://www.zkoss.org/wiki/ZUML_Reference/ZUML/Attributes/if
a small correction on the above
And lastly, the ZUML conditional evaluation "if" will still create children components in memory at server side, but not send them to the client. Shadow element "if" will instantiate content only if the condition is met. If the content of the "if" statement has some large objects, or some computation time, this can reduce the page's memory / cpu load.
The ZUML if will be evaluated ONCE at page parsing, therefore it will NOT create elements in memory if the condition resolves to false. Once the page has been evaluated, the ZUML if will have no further behavior and cannot be dynamically updated without reparsing the whole components tree. In contrast, the shadow element IF have 2 possible behaviors. If the condition is dynamic (using @load, @ref, etc), then the shadow element IF will maintain a node in memory. If the condition resolves to false, then only that tracking node is present. If the condition resolves to true, the shadow element IF will instantiate its content. If the condition is not dynamic (using ${} or @init), then the shadow element IF will resolve (either add content or not depending on the condition value) then delete itself from memory.
Asked: 2021-01-21 01:42:53 +0800
Seen: 15 times
Last updated: Jan 29 '21