sercrod

*apply / n-apply

Summary

*apply is the commit counterpart to *stage. On a staged host it copies the current staged data back into the host data object and triggers a redraw, so that edited values become the new committed state. The alias n-apply behaves identically. :contentReference[oaicite:0]{index=0}

Description

When a Sercrod host uses *stage, the runtime keeps a separate buffer object called the stage for rendering and user edits, while the original data object remains the committed source of truth. During update, the visible scope for the host is taken from the stage buffer when it exists, and falls back to the data object when it does not.

*apply is a simple event-style directive that finalises a staged edit session. When the element is clicked, the contents of the stage buffer are merged into the host data and the host is updated. Immediately after applying, Sercrod takes a deep snapshot of the committed data so that *restore can later rebuild the stage from that snapshot. :contentReference[oaicite:2]{index=2}

The attribute value of *apply or n-apply is not used. Presence of the attribute is all that matters; any value is ignored.

Basic example

A minimal save or cancel form with staging:

<serc-rod data="{ profile: { name: 'Alice' } }" *stage>
  <label>
    Name:
    <input type="text" *input="profile.name">
  </label>

  <p>Preview (staged): %profile.name%</p>

  <button type="button" *apply>Save</button>
  <button type="button" *restore>Cancel</button>
</serc-rod>

In this pattern:

Behavior

Evaluation timing

Execution model

Variable creation

Scope layering

Parent access

Use with conditionals and loops

Best practices

Examples

Dialog style form with staged editing and commit
<serc-rod
  data="{
    profile: { name: 'Alice', email: 'alice@example.com' },
    editing: false
  }"
  *stage
>
  <button type="button" @click="editing = true">Edit profile</button>

  <div *if="editing">
    <label>
      Name:
      <input type="text" *input="profile.name">
    </label>

    <label>
      Email:
      <input type="email" *input="profile.email">
    </label>

    <button type="button" *apply>Save changes</button>
    <button type="button" *restore @click="editing = false">Cancel</button>
  </div>

  <h2>Current profile</h2>
  <p>Name: %profile.name%</p>
  <p>Email: %profile.email%</p>
</serc-rod>

Key points:

Multiple apply buttons in different places

You can place several apply buttons in the same staged host to offer alternative commit affordances:

<serc-rod data="{ title: 'Draft', body: '' }" *stage>
  <header>
    <input type="text" *input="title">
    <button type="button" *apply>Save</button>
  </header>

  <main>
    <textarea *input="body"></textarea>
  </main>

  <footer>
    <button type="button" *restore>Discard changes</button>
    <button type="button" *apply>Save and stay</button>
  </footer>
</serc-rod>

All apply buttons commit the same staged buffer into the host data when clicked. Users can choose whichever button is more convenient in the layout, but the semantics are identical.

Notes