Skip to main content

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
  • switch:destructive() { .. }
  • case:destructive "condition" { .. }
  • default:destructive { .. }

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");
}
}