Destructive Scopes
A scope can be marked as destructive using a :destructive
tag after its declaration. Some examples:
if:destructive()
else:destructive
else if:destructive
match:destructive() { .. }
case:destructive "condition" { .. }
default:destructive { .. }
To understand destructive
you first need to understand what a scope
is in Evolve.
A destructive scope is effectively just a block of statements inside of render
block.
We have 2 types of 'context' in Evolve: one that works exactly like C# and one that is a 'render' context that includes the additional evolve only things like state, enable slot etc.
This Evolve context also lets you create UI elements like Something(attr:xyz, style = [@whatever], someParam = someExpression())
The other side of the coin is the C# context which is active inside a run block,
or any delegate, or any method body, or any expression context.
Some scopes are implicitly destructive, such as those generated by a repeat
. In the
case of repeat
, if the input size shrinks from one frame to another then the extra
items that were inside the repeat last frame will be destroyed. If a repeat is disabled due
to its parent scope being disabled, its child scopes will be disabled as normal and not be destroyed.
Destroying a View
will destroy all of its descendent scopes and their associated elements.
template Example(required bool showGroup1) render {
// because this scope is marked as destructive, if there is a frame in which
// this branch is not entered, its descendents will all be destroyed instead of
// being disabled as they normally would be. When the branch is later re-entered
// the elements we be re-created again.
if:destructive(showGroup1) {
Text("Element 1");
Text("Element 2");
}
}