RMT Reference: State, Selectors and Data
This page describes data sources, state and declarative derivations.
Syntax
| Operator | Form | Allowed contexts | Parameters | Function | Diagnostics | Related operators |
|---|
type | state app.count type number | state, input | type name | Declares the expected value type. | Missing types produce syntax diagnostics. | state, input |
initial | initial true or initial { text "Ready" } | state | literal or initial block | Sets the initial value. | State blocks allow only initial values. | preserve |
preserve | state app.status type object preserve | state, surface | flag without value | Preserves state or surface state across lifecycle boundaries. | Wrong contexts produce context diagnostics. | destroy releases |
from | from state app.status | selector, datasource, operations, payload | source kind and reference | Binds a declarative source. | Source kind must be allowed. | endpoint, selector, payload |
endpoint | from endpoint "/api/items" | datasource, operations | string or identifier | Binds host endpoint data. | Invalid source kinds are reported. | method, contract |
sse | stream feed from sse app.feed | stream | stream identifier | Binds Server-Sent Events to streaming. | stream requires a source. | stream |
worker | prewarm index from worker search.prepare | operations, datasource | worker identifier | Describes worker-based preparation. | Source kind must be static. | prewarm |
fixture | fallback fixture app.sample | datasource, operations | fixture identifier | Binds test or fallback data. | Unknown references are reported semantically. | fallback |
resource | from resource app.file | operations, resource | resource identifier | Uses an owner-scoped resource as source. | Missing resources produce semantic diagnostics. | resource, dispose |
where | where item.active == true | selector | declarative expression | Filters selector results. | Function calls are not allowed. | find, sort by |
find | find item.id == input.id | selector | declarative expression | Selects one record. | Invalid expressions are parser diagnostics. | where |
sort by | sort by item.createdAt desc | selector | path, direction | Sorts selector results stably. | Sort clause must be complete. | output |
output | output MessageList | selector | type name | Names the output contract. | Missing type produces syntax diagnostics. | selector |
method | method GET | datasource | HTTP method or identifier | Documents the host method. | Only valid in datasource blocks. | endpoint |
contract | contract "xtend.schema.v1" | datasource | static string | Binds a data or endpoint schema. | Wrong context is reported. | result |
result | result list | datasource | result shape | Describes the expected result shape. | Datasource clause only. | fallback |
fallback | fallback fixture app.empty | datasource, remote surface | kind and reference | Declares a safe replacement path. | Missing reference is reported. | fixture, fallback surface |
Allowed contexts
State clauses belong in state, selector clauses in selector, datasource clauses in datasource. Source kinds appear after from or fallback.
Parameters
Identifiers reference records; strings describe external paths or contracts; directions such as asc and desc remain static.
Description
RMT separates stored state, derived view models and host data sources. This lets the compiler understand dependencies without evaluating host JavaScript.
Examples
template reference.data {
state app.filter type object preserve {
initial {
text "open"
}
}
datasource tickets from endpoint "/api/tickets" {
method GET
contract "xtend.ticket-list.v1"
result list
fallback fixture tickets.empty
}
selector openTickets from datasource tickets {
where ticket.status == "open"
find ticket.id == app.filter.text
sort by ticket.createdAt desc
output TicketList
}
portal app.root root "#app" layer surface
surface list kind region component x-summary {
portal app.root
lane visible weight 70 {
hydrate ticket.list from selector openTickets
}
}
}
Diagnostics
The parser reports wrong clauses in each block. The semantic graph reports unknown state, selector, datasource, fixture or resource references.
state, selector, datasource, action, hydrate, stream, when.
The RMT reference index links state, selector, and data records to their lifecycle rules. Related article