nenu-lang / page-script
Stable

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 ownsBackend runnable owns
Page-local stateDurable entity reads
Input and callback contractsSaves, transactions, and deletes
Event handlersCache and backend logging
Load and change effectsDomain failures through throw
Imported API callsRequest-to-Response implementation
Navigation, modals, and toastsScheduled and event-listener work

The Supported Language Surface

SupportedNot supported in Page Script
Typed and inferred local declarationsEntity and default definitions
Functions and browser-safe expressionsBackend entity-fetching need
if, loop, with, withoutsave and delete
Non-destructuring matchcache, log, and throw
return, continue, breakContainer fallback declarations
Top-level reference alias declarationsalias inside handlers or effects
use api and use libraryJavaScript async, await, promises, or raw fetch
on load and on changeNested effects or backend runtime statements
goto, modal, and toastDirect public api(...) calls

A Small Room Page

pages/room.page.nenu — Page Script
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 api gives the backend route a callable local alias.
  • need says the page must receive room_id.
  • expenses and loading are page state.
  • refreshExpenses is ordinary reusable behavior.
  • on load runs 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 expenses or loading.
  • 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

WrongCorrect
Fetch Expense[](...) directly on the pageImport and call an API alias.
save(expense) in a click handlerCall a mutation API.
Use JavaScript let or an arrow functionUse Nenu declarations and fn.
Treat Page Script need as storageTreat it as a page/component input contract.

Continue Learning