sercrod

*lazy

Summary

*lazy is a small flag directive that makes Sercrod less aggressive about full re-renders.

It has two main roles:

The alias n-lazy behaves the same as *lazy.

Basic example

Delayed host re-render for a form input:

<serc-rod id="app" *lazy data='{"form":{"name":""}}'>
  <h2>Profile</h2>

  <label>
    Name:
    <input type="text" *input="form.name">
  </label>

  <p>Preview: <strong *print="form.name"></strong></p>
</serc-rod>

In this example:

Behavior

*lazy does not create variables; it only changes how and when Sercrod decides to re-render.

There are two independent behaviors:

  1. Host-level *lazy (on <serc-rod> or another Sercrod-based host)

Effectively, host-level *lazy says:

  1. Input-level *lazy (on elements with *input / n-input)

So on a control that uses *input:

Evaluation timing

Execution model

  1. Host-level flow (simplified):
  1. Input-level flow for text-like <input>:
  1. Input-level flow for change (checkbox / radio / select / others):

At all times:

Variable creation

*lazy does not create or modify any variables:

Scope layering

*lazy does not change scope layering:

The only interaction with scope is when *lazy on an input uses an expression, for example:

<input *input="form.name" *lazy="form.mode === 'slow'">

In this case:

Parent access

*lazy does not change how parent data are accessed:

You can freely use $parent or $root inside expressions for *lazy when used on inputs, but they are not required.

Use with conditionals and loops

*lazy is not a structural directive, so it does not compete with *if, *for, or *each for control of the DOM.

Best practices

Additional examples

Host-level *lazy on a widget:

<serc-rod id="counter" *lazy data='{"count":0}'>
  <button @click="count++">Increment</button>
  <p>Count is <span *print="count"></span></p>
</serc-rod>

Behavior:

Conditional lazy input:

<serc-rod id="form-app" data='{
  "form": { "name": "", "mode": "slow" }
}'>
  <label>
    Name:
    <input type="text"
           *input="form.name"
           *lazy="form.mode === 'slow'">
  </label>

  <p>Mode: <span *print="form.mode"></span></p>
</serc-rod>

Behavior:

Lazy checkbox:

<serc-rod id="flags" data='{"flags":{"debug":false}}'>
  <label>
    <input type="checkbox"
           *input="flags.debug"
           *lazy>
    Debug mode
  </label>

  <section *if="flags.debug">
    <h2>Debug panel</h2>
    <p>Extra diagnostics are now visible.</p>
  </section>
</serc-rod>

Behavior:

Notes