Skip to content

Runtime API

This page summarizes the public runtime functions available in ZhinNX.

Routing

APIDescription
createApp(target)Mounts the app runtime.
page(path, render)Registers a page.
go(path)Navigates to another route.
notFound(render)Registers a fallback page.

Events

APIDescription
action(name, handler)Registers an event handler callable from templates.

Rendering

APIDescription
each(items, render)Maps arrays into HTML strings.
cx(...values)Joins class names conditionally.

State

APIDescription
state(name, initialValue)Creates named state.
get(path)Reads a state value.
set(path, value)Writes a state value.
update(path, callback)Updates a value using its previous value.
subscribe(name, handler)Subscribes to state changes.

Storage

APIDescription
save(key, value)Saves data to localStorage.
load(key, fallback)Loads data from localStorage.
remove(key)Removes saved data.

UI

APIDescription
toast(message)Shows a toast.
modal(options)Opens a modal.
sheet(options)Opens a bottom sheet.
confirm(options)Opens a confirm dialog and resolves true or false.
loading(message)Shows loading feedback and returns a stop function.

API

APIDescription
api.get(url, options)Sends GET request.
api.post(url, body, options)Sends POST request.
api.put(url, body, options)Sends PUT request.
api.delete(url, options)Sends DELETE request.

FastLoad

APIDescription
fastPage(path, config)Registers a progressive FastLoad page.
chunk(selector, render, options)Creates a render chunk.
lazyChunk(selector, importFn, options)Creates a dynamically imported chunk.
isFastPageActive()Returns true when the current route is a FastLoad page.

DOM patching

APIDescription
patch(selector, html)Replaces matching DOM content and re-binds ZhinNX events.
refresh(selector, html?)Patches when HTML is provided, or only re-binds events when omitted.

Released under the MIT License.