sercrod

*break

Summary

*break is a control directive used inside *switch blocks. It stops the *switch fallthrough after the current branch has been rendered. The alias n-break behaves the same.

In addition, *case.break is a shorthand that combines *case and *break on a single element:

Basic example

A typical *switch with a breaking case:

<serc-rod id="app" data='{"status":"ready"}'>
  <div *switch="status">
    <p *case="'idle'">Idle…</p>

    <!-- Match "ready" and then stop evaluating later branches -->
    <p *case.break="'ready'">Ready</p>

    <!-- Never rendered, because the previous branch breaks -->
    <p *case="'ready'">Also ready (not reached)</p>

    <!-- Never reached in this example -->
    <p *default>Unknown status</p>
  </div>
</serc-rod>

Conceptually:

Behavior

*break and *case.break are interpreted only in the context of *switch:

Important limitations:

Aliases:

Evaluation timing

*break participates in the evaluation of *switch as follows:

Notes:

Execution model

Conceptually, for a *switch host:

  1. Evaluate the *switch expression and store it as $switch for children.

  2. Collect the direct child elements.

  3. Iterate over those children in DOM order.

    • Determine whether each child is:
      • A *case or n-case branch.
      • A *case.break or n-case.break branch.
      • A *default or n-default branch.
      • Something else (ignored by the switch controller).
  4. Until the first matching branch is found, nothing is rendered.

  5. Once a matching branch (or *default) is found, enter "fallthrough" mode:

    • For each branch in fallthrough mode:
      • Clone the original node.
      • Strip control attributes (*case, *default, *case.break, *break, and their n- aliases).
      • Render the clone with the child scope (which includes $switch).
      • Inspect the original node for breaking attributes:
        • *break, n-break, *case.break, or n-case.break.
      • If any breaking attribute is present, stop the loop.
  6. Other non-branch child nodes (such as comments or text) are ignored by the switch controller.

There is no separate execution path for *break outside of *switch; other directives do not consult it.

Variable creation

*break does not create any variables:

Similarly, *case.break uses the same expression as *case:

Scope layering

In a *switch block:

Parent access

*break does not alter the way parents are accessed:

Use with conditionals and loops

Within *switch bodies:

Example pattern with an inner *if:

<div *switch="status">
  <p *case.break="'ready'">
    <span *if="$root.showLabel">Ready</span>
  </p>
  <p *default>Other status</p>
</div>

Interaction with *for and *each:

Best practices

Examples

Unconditional break with *break:

<serc-rod id="app" data='{"status":"processing"}'>
  <div *switch="status">
    <p *case="'processing'" *break>Processing…</p>
    <p *case="'processing'">Also processing (not reached)</p>
    <p *default>Fallback (not reached)</p>
  </div>
</serc-rod>

Mixed fallthrough with one breaking branch:

<serc-rod id="app" data='{"status":"multi"}'>
  <div *switch="status">
    <p *case="'multi'">First line</p>
    <p *case="'multi'">Second line</p>
    <p *case.break="'multi'">Third line, then break</p>
    <p *case="'multi'">Fourth line (not reached)</p>
    <p *default>Default (not reached)</p>
  </div>
</serc-rod>

Notes