← Application composition

App.compose

luastra/app
App.compose(optionsValue: ComposeOptions<T, S>): Instance<T, S>

Builds the single application object consumed by every Luastra host from a small root contract and optional reusable features. It routes namespaced events and owned asynchronous completions while preserving one ordinary render, handle, resolve, and snapshot surface.

Before you use it

Add luastra/app to this module's dependencies in luastra.json, then import it with require("luastra/app"). Return exactly one App.compose instance from the entry module. Feature IDs must be disjoint lowercase paths, and a feature must claim each asynchronous request ID before its completion can be routed.

How it fits

App.compose validates the complete feature registry once and returns the ordinary host-facing app object. Events route by target namespace; claimed completions route by request ownership and generation; lifecycle dispose invalidates every outstanding claim.

When to use it

Use App.compose in the entry module when an application contains reusable feature controllers or simply needs one transparent place to expose render and snapshot. Keep feature IDs disjoint, claim request IDs immediately, and return the composed instance directly.

Parameters

ParameterType / valuesDescription
optionsValueComposeOptions<TChecked optionsValue argument accepted by App.compose.
S>anyChecked S> argument accepted by App.compose.

Returns

Instance<T, S> — the exact Instance<T, S> value declared by the SDK contract.

What happens next

One frozen application instance exposing render, handle, resolve, snapshot, and inspect without adding a second host lifecycle.

Failures and fixes

Duplicate or overlapping feature IDs, invalid event bounds, duplicate request ownership, and malformed compose options fail immediately. Late, cancelled, unknown, or post-dispose completions are suppressed or delegated only through the explicitly configured root path.

Availability

Public-source alpha composition API in 0.5.0-alpha; host-independent except for the capabilities used by composed features.

Focused example

local App = require("luastra/app")
local UI = require("luastra/ui")

local count = 0

return App.compose {
    render = function()
        return UI.Screen {
            id = "app",
            UI.Text {
                id = "counter/value",
                text = tostring(count),
            },
        }
    end,
    handle = function(action: string)
        if action == "counter.increment" then count += 1 end
    end,
    snapshot = function()
        return { count = count }
    end,
}

Complete inventory

View all pages in Application composition
← Previous: App.Instance