Learn / Wiring

A first assembly: two mirrors, one list

This example wires a URL filter mirror and a key-value draft mirror into one application using Bundle.parent and Page.assemble (assuming your app already defines Model, Message, initialModel, own, and view):

ts
import { Bundle } from 'foldkit-bundle'
import { Mirror } from 'foldkit-mirror'

const Filters = Mirror.url(App, { name: 'filters', fields: [App.model.filter] })
const Prefs = Mirror.kv(App, { key: 'todo/prefs', fields: [App.model.draft] })

const Page = Bundle.parent({ Model, Message })
const wiring = Page.assemble(Filters.wiring('UrlChanged'), Prefs.wiring())

const update = wiring.update(own)
const start = wiring.initial(initialModel)
const subscriptions = wiring.subscriptions()
const url = wiring.url(next => Message.UrlChanged({ url: next }))

Page.assemble checks the list right away for duplicate keys, double-claimed Message tags, and colliding resource names, throwing if two entries conflict. Both mirrors then route their messages before own runs, start includes the draft restore command, and subscriptions merges both mirrors' entries.

Pass the derived values to wiring.complete to verify at compile time that nothing in your runtime config was written by hand:

ts
const config = wiring.complete({ update, init: () => start, subscriptions, url, view })

complete returns its argument unchanged at runtime. If you swap subscriptions for a hand-written object, TypeScript reports an error on that property pointing to the missing assembly call. For a shorter setup when your own update already routes placements, wiring.runtime({ initial, update, view }) fills in init, subscriptions, and resources automatically.