sercrod

Lifecycle Directives

Lifecycle directives control how data flows over time in a Sercrod host: staged edits, saving and loading, HTTP requests, file transfer, and real-time connections.

This page groups lifecycle-related directives by purpose. For the host update lifecycle and render order, see Runtime Behavior.

For JavaScript integration after startup, each host exposes host.ready and dispatches sercrod-ready once after its first completed update() cycle. This is host state, not a directive and not a data field.

Staging Edits

Staging directives let a user edit a temporary branch and then explicitly commit or discard those changes.

<serc-rod
    id="profile-app"
    data='{"profile":{"name":"Taro","email":"taro@example.com"}}'
>
    <form *stage>
        <label>
            Name:
            <input type="text" :value="profile.name">
        </label>

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

        <button type="button" *apply>Save</button>
        <button type="button" *restore>Reset</button>
    </form>

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

Use staging when a user should be able to edit a complex form and then explicitly commit or discard changes.

Saving And Loading

*save.file, *load.file, *save.session, *load.session, *save.store, and *load.store coordinate host data with local persistence.

The runtime dispatches sercrod-loaded and sercrod-saved hooks for successful operations.

<serc-rod data='{"todos":[]}'>
    <ul>
        <li *for="item of todos">%item.label%</li>
    </ul>

    <button type="button" *load.file>Load</button>
    <button type="button" *save.file>Save</button>
    <button type="button" *save.store="'todos'" *keys="todos">Save store</button>
    <button type="button" *load.store="'todos'" *keys="todos">Load store</button>
</serc-rod>

Use save/load when state should be exported, restored, or kept locally in the browser by explicit user action.

HTTP Lifecycle

HTTP directives coordinate requests and how responses enter host data.

For request timing and response shape contracts, see Network Contracts.

File Transfer

*upload and *download provide file transfer behavior.

The runtime exposes progress and completion through custom events:

Upload results are mirrored to $response and may be placed through *response or its *into alias. *download does not write result data into the host; it emits download events.

Real-Time Lifecycle

WebSocket directives connect a host to a WebSocket server.

WebSocket state is reflected through data fields such as $ws_ready, $ws_last, $ws_messages, $ws_error, and close information.

See WebSocket.

Choosing Lifecycle Directives