Page Script
- Page Script is Nenu’s browser-safe execution profile for a page or library component.
- It keeps local state and UI behavior close to the visual page while durable work stays behind APIs.
- Some full-language constructs are intentionally unavailable in the browser profile.
What Page Script Owns
Page Script is embedded before the visual content of a page or reusable library component. It owns the typed values and behavior that the visual editor binds to: loading data through APIs, filtering a displayed expense list, opening a form, and navigating to an expense detail page.
| Page Script owns | Backend runnable owns |
|---|---|
| Page-local state | Durable entity reads |
| Input and callback contracts | Saves, transactions, and deletes |
| Event handlers | Cache and backend logging |
| Load and change effects | Domain failures through throw |
| Imported API calls | Request-to-Response implementation |
| Navigation, modals, and toasts | Scheduled and event-listener work |
The Supported Language Surface
| Supported | Not supported in Page Script |
|---|---|
| Typed and inferred local declarations | Entity and default definitions |
| Functions and browser-safe expressions | Backend entity-fetching need |
if, loop, with, without | save and delete |
Non-destructuring match | cache, log, and throw |
return, continue, break | Container fallback declarations |
Top-level reference alias declarations | alias inside handlers or effects |
use api and use library | JavaScript async, await, promises, or raw fetch |
on load and on change | Nested effects or backend runtime statements |
goto, modal, and toast | Direct public api(...) calls |
A Small Room Page
1use api/expenses/list as ListExpensesApi23need {4 room_id: string5}67Expense[] expenses = []8bool loading = false910fn refreshExpenses() {11 loading = true12 result = ListExpensesApi({ room_id })13 expenses = result.expenses14 loading = false15}1617on load() {18 refreshExpenses()19}use apigives the backend route a callable local alias.needsays the page must receiveroom_id.expensesandloadingare page state.refreshExpensesis ordinary reusable behavior.on loadruns the initial page effect.
How Visual Elements Use It
The visual page binds element values to state and binds events to top-level handler names. Repeated visual content can supply its current row to a compatible typed handler. Page Script remains source code; element layout and event wiring remain App Marché visual configuration.
- Expose the state the visual element needs, such as
expensesorloading. - Expose a top-level function for each interaction, such as
openExpense. - Bind the bare handler name rather than a JavaScript arrow or call expression.
- Keep the durable mutation in an API and update page state from its typed response.
Common Mistakes
| Wrong | Correct |
|---|---|
Fetch Expense[](...) directly on the page | Import and call an API alias. |
save(expense) in a click handler | Call a mutation API. |
Use JavaScript let or an arrow function | Use Nenu declarations and fn. |
Treat Page Script need as storage | Treat it as a page/component input contract. |
