Page State And Inputs
- Initialize state with a concrete type that Page Script can keep stable.
- Use top-level block-form need for required inputs, optional defaults, and callbacks.
- Route parameters arrive as bare names from the filesystem route contract.
Concrete Initial State
Page state lives across interactions, so its type must stay stable. Top-level state must use a literal initializer or ?; compute values with function calls inside a function or effect. Empty collections need an explicit element type because [] and {} contain no element evidence.
1Expense[] expenses = []2string query = ""3number draft_amount = 04string? draft_note = ?5bool loading = false- Keep number inputs in
numberstate when the editor exposes a number contract. - Use optional state only when absence is meaningful.
- Input bindings target simple state names rather than deep entity-field assignments.
- Project entities and named types are already available to Page Script; do not duplicate their definitions.
Value Inputs With need
1need {2 room_id: string3 heading: string = "Room expenses"4 selected_expense: Expense?5}A field without a default is required from the route or caller. A field with = value has a Page Script input default. Optional type and default are separate ideas: Expense? permits absence, while = ... supplies a value when the caller omits the input.
Callback Inputs
A reusable library component can require callbacks from its owner. Callback input parameters are written name-first inside Page Script need. Ordinary function declarations remain type-first.
1need {2 room_id: string3 onSaved(expense: Expense)4 onCancel(): bool5}Dynamic Route Inputs
A dynamic page path supplies its bracket segment as a bare input name. For a page stored at pages/expenses/[id].page.nenu, use id. Do not invent a route object.
1need {2 id: string3}The Platform User Type
A page or component may accept a User value when its real caller contract supplies one. Treat it as an existing platform type. This guide does not declare User, assume its fields, or make it part of the room application schema.
1need {2 current_member: User3}Common Mistakes
| Wrong | Correct |
|---|---|
Infer expenses = [] | Expense[] expenses = [] |
| Backend fetch syntax in Page Script need | need { room_id: string } |
onSaved(Expense expense) in need | onSaved(expense: Expense) |
fn handleSaved(expense: Expense) | fn handleSaved(Expense expense) |
| Declare the platform User type locally | Consume the provided User type. |
