0

is there difference between if attribute and shadow element if

asked 2021-01-21 01:42:53 +0800

gvguad gravatar image gvguad
7 2

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?

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2021-01-21 10:25:19 +0800

MDuchemin gravatar image MDuchemin
1856 1 5
ZK Team

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

link publish delete flag offensive edit
0

answered 2021-01-29 14:50:19 +0800

MDuchemin gravatar image MDuchemin
1856 1 5
ZK Team

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.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2021-01-21 01:42:53 +0800

Seen: 14 times

Last updated: Jan 29

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More