sercrod

*eager

Summary

*eager is an optional modifier for *input / n-input that makes Sercrod re-render the host “eagerly” on every input-like event for text fields and textareas.

*eager only has effect on elements that also carry *input or n-input and are treated as text-like controls by Sercrod.

Basic example

Enable eager updates on a text input:

<serc-rod id="profile" data='{"user":{"name":""}}'>
  <form>
    <label>
      Name:
      <input type="text" *input="user.name" *eager>
    </label>

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

Behavior:

Behavior

Scope of *eager:

Targeted controls:

Effects of *eager:

In other words:

Activation and value semantics

*eager and n-eager are treated as boolean or conditionally-boolean attributes with a small amount of convenience logic.

Recognized forms:

Practical interpretation:

Interaction with *input / n-input

*eager has no meaning by itself. It only matters in combination with *input or n-input:

Data writes:

Summary:

Interaction with *lazy

There are two separate uses of *lazy in Sercrod:

  1. Host-level *lazy on <serc-rod>:

    • Affects how often the host re-renders in response to generic updates and events.
  2. Input-level *lazy on controls that also have *input / n-input:

    • Affects how change-driven controls (checkbox, radio, select, other) update the host after writes.

*eager interacts only with the first group (text-like *input bindings) and does not override the second:

Rule of thumb:

Interaction with *stage

*eager respects *stage:

This allows you to combine:

Evaluation timing

The value of *eager is determined when Sercrod binds the element:

Consequences:

If you need to switch between eager and non-eager modes at runtime:

Execution model

For a text-like input with *input and optional *eager, the flow is:

  1. Binding setup (render time):

    • Sercrod reads the *input / n-input expression and figures out a target data object.
    • It evaluates *eager / n-eager once to compute isEager.
    • It sets the initial control value based on the current data.
    • It attaches event listeners (input and/or change) that capture isEager.
  2. On each input event (text inputs and textareas):

    • Sercrod transforms the raw value using any installed input filters.
    • It writes the value to the bound data path with assign_expr.
    • If the host is not staged:
      • If isEager is true:
        • It calls update() on the host.
      • Otherwise:
        • It only propagates updates to child Sercrod instances (_updateChildren(...)).
  3. On change events (checkbox/radio/select/others):

    • Sercrod computes and writes the new value, similar to text inputs.
    • isEager is ignored; the actual update policy is controlled by *lazy.

In all cases, *eager does not change what is written, only when and how broadly the host re-renders.

Best practices

Examples

Live search box:

<serc-rod id="search" data='{"query":"","results":[]}'>
  <div>
    <input
      type="search"
      placeholder="Type to search"
      *input="query"
      *eager>
  </div>

  <ul *each="item of results">
    <li *print="item.label"></li>
  </ul>
</serc-rod>

Conditional eager mode:

<serc-rod id="settings" data='{
  "user": { "name": "" },
  "ui":   { "eagerPreview": true }
}'>
  <label>
    <input type="checkbox" *input="ui.eagerPreview">
    Enable eager preview
  </label>

  <label>
    Name:
    <input
      type="text"
      *input="user.name"
      *eager="ui.eagerPreview">
  </label>

  <p>Preview: <span *print="user.name"></span></p>
</serc-rod>

Notes