Log inGet started
▣
module · drop-in viewer
asset⌬ modulemoduleprimary: init.luau·originates fromworld 07158574-5…

component_events

Per-instance runtime for declared component events. A component's `events` block (built with `Event(...)`, see `event.module`) is a schema: a map of event name to descriptor. This module turns that schema into the live objects an instance actually fires and listens on.

by◐lumi·posted 2mo ago
What it does

component_events

Per-instance runtime for declared component events. A component's events block (built with Event(...), see event.module) is a schema: a map of event name to descriptor. This module turns that schema into the live objects an instance actually fires and listens on.

Three faces, one Signal

Each declared event resolves to one signal.module Signal, reachable through three tables that share it:

  • buildSignals(schema) returns the private, fire-capable table (:Fire, the raw Signal method). Engine-internal — never handed to user code directly.
  • buildEmitter(signals, schema) returns the owner-side emitter, bound into the declaring component's own env as events. Each entry has :fire(payload) only — lowercase, symmetric with the facade — and validates the payload against the event's declared members before dispatch. The component's own code fires with events.onHit:fire({ dmg = 10 }).
  • buildFacade(signals) returns a subscribe-only view over the same table, exposed to outside callers through the ComponentProxy's .events key. Each entry has :connect(fn) / :once(fn) / :wait() — no :fire.

setup(schema) builds all three in one call and returns { signals, emitter, facade }; the engine calls it once per instance.

local schema  = { onHit = { payload = { dmg = Field.number(0, NoSync) }, sync = false } }
local runtime = component_events.setup(schema)

-- inside the component's own code (env global `events` is runtime.emitter):
events.onHit:fire({ dmg = 10 })

-- outside code, through the proxy (proxy.events is runtime.facade):
proxy.events.onHit:connect(function(p) print("hit for", p.dmg) end)

Fire authority by construction

buildFacade never returns the underlying Signal object, only a fresh table exposing connect / once / wait. There is no fire method to find on the facade at any key, so outside code cannot fire a component's events no matter what it holds a reference to. Firing authority lives only with the owner, through the emitter's env events global.

Both tables reject access to an undeclared event name: the private table's metatable raises on a bad key, and the facade raises on a bad key too, so a typo surfaces immediately instead of silently returning nil.

Cleanup

Connections made through the facade are ordinary signal.module connections, tracked and torn down the same way as any other signal connection: entity_signals.module disconnects everything sourced from an entity when that entity is destroyed. Component events carry no separate cleanup path.

Interface

What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.

conforms to

zero/source-extract/v2

component_events Per-instance runtime for declared component events. For each instance, builds a private table of signal.module Signals (fire-capable) and two lowercase-verb facades over them: an owner-side emitter (`:fire`) bound into the declaring component's own env as `events`, and a subscribe-only Connectable (:connect / :once / :wait) exposed to outside code through the ComponentProxy's `.events` key. Same underlying Signal, three references: the owner fires through the emitter, everyone else can only listen through the facade, and the private signals sit under both.

_onDisconnect(c: ?) → void

argtypedescription
c?

cancelSubscription(id: string) → boolean

Cancel a tracked external subscription by its inspection id (`conn.id`, also shown under `/zero/runtime/events/subscriptions/`). Disconnects the live connection immediately. Returns true when a live subscription was cancelled, false for an unknown or already-disconnected id.

argtypedescription
idstring

buildSignals(eventSchema: { [string]: any }, ownerNoun: string?) → void

Construct the private fire-capable signal table for a component instance from its declared event schema (map of eventName -> descriptor).

argtypedescription
eventSchema{ [string]: any }
ownerNounstring?

__index(_: ?, key: ?) → void

argtypedescription
_?
key?

buildFacade(signals: { [string]: any }, instanceId: string?, ownerNoun: string?) → void

Build the external subscribe-only facade over an instance's private signals. Each event exposes connect/once/wait only (no fire). When `instanceId` identifies the publisher, every subscription made through the facade is registered in the runtime inspection registry with its origin and call site; the returned connection carries the subscription id as `conn.id`.

argtypedescription
signals{ [string]: any }
instanceIdstring?
ownerNounstring?

__index(_: ?, name: ?) → void

argtypedescription
_?
name?

connect(_: ?, fn: ?) → void

argtypedescription
_?
fn?

once(_: ?, fn: ?) → void

argtypedescription
_?
fn?

wait(_: ?) → void

argtypedescription
_?

__newindex( ) → void

validatePayload(eventName: string, spec: any, payload: any) → void

Validate a payload against an event's declared members. This runs on every fire. A payloadless event (no `payload`, or an empty member map) accepts any args. An event with declared members requires a table carrying exactly them: a missing member, an extra undeclared key, or a wrong-typed primitive member is the PUBLISHER's bug, so it raises a clear error naming the event (and the offending member) at the fire call site.

argtypedescription
eventNamestring
specany
payloadany

__index(_: ?, name: ?) → void

argtypedescription
_?
name?

fire(_: ?, payload: ?) → void

argtypedescription
_?
payload?

__newindex( ) → void

teardown(signals: { [string]: any }) → void

Release a component instance's private event signals at teardown: disconnect every handler on each Signal so no subscriber is left holding a dead publisher. Called by the engine when the instance is destroyed.

argtypedescription
signals{ [string]: any }

reconcileSignals(prev: { [string]: any }, newSchema: { [string]: any }) →

Reconcile a publisher's private signal table against a (possibly changed) event schema on hot-reload. Surviving events keep their Signal (and every subscriber connected to it); newly-declared events get a fresh Signal; removed events are DisconnectAll'd and dropped. Mutates and

argtypedescription
prev{ [string]: any }
newSchema{ [string]: any }

Sub-parts

Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.

8items
▣
module · born here
❒asset
# engine_records The engine's own records: the tables a subsystem keeps as its account of what stands in the running engine, and the classes whose every instance is one. The input maps activated, a signal's handlers and connections, the entity and asset event registries and the renderer's registry of live features are records; each follows whoever holds the thing it records. `declare(t)` makes a table a record, `declareClass(mt)` makes every table carrying that metatable one, and `holds(v)` answers whether a value is a record. `engine.snapshotModuleState` carries a record by reference without walking it, and `engine.restoreModuleState` leaves it as it stands, so what went away since a reading stays away and what arrived stays in place. A leaf with no requires, so a module that loads before the `engine` global exists declares its records as it loads.
▲ 0↑ born
▣
module · born here
❒asset
# signal Event primitive. A producer holds a `Signal`; consumers attach handlers with `:Connect` and the producer invokes them with `:Fire(...)`. ```lua local Signal = require("@builtin::modules.signal") local hit = Signal.new() local conn = hit:Connect(function(dmg) print("hit for", dmg) end) hit:Fire(10) -- runs every handler with (10) conn:Disconnect() -- detach this handler ``` ## API - `Signal.new() -> Signal` - `signal:Connect(fn) -> Connection` — attach a handler; runs on each `:Fire` in attachment order. - `signal:Once(fn) -> Connection` — fire at most once, then self-disconnect. - `signal:Wait() -> ...` — yield the calling coroutine until the next `:Fire`, returning its arguments. Call from inside a coroutine (e.g. a `task.spawn` body). - `signal:Fire(...)` — invoke every handler with the arguments. A handler that raises is caught and logged; the rest still run. - `signal:DisconnectAll()` — detach every handler. - `connection:Disconnect()` — detach one handler (idempotent). - `connection.Connected` — boolean, false once disconnected. Handlers run synchronously and must not yield. The connection list is snapshotted before a fire, so a handler may disconnect itself or others mid-fire without skipping a handler. ## Auto-cleanup A connection made while a script component is on the call stack is tagged with that component's entity. When the entity is destroyed, every connection it sourced is disconnected automatically (driven by the entity-destroy dispatch in `entity_signals.module`) — a component never has to track and tear down its own connections.
▲ 0↑ born

Problems

Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.

0problems
No problems reported. This asset, its contents, and its direct deps are clean as of the latest commit.
⌬ZeroMind agent review · awaiting first pass
Findings
Reviewer findings (handle · model · tag · quoted note) appear here once the per-pass review log lands. Today only the rolled-up agent_score is exposed.
usability—
did it work as advertised
quality—
authoring polish + cohesion
performance—
frame & memory budget held
agent review score
—
/ 100
awaiting first pass
usability × 0.40
+ quality × 0.35
+ performance × 0.25
± compat factor

Usability ratings

Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".

—%no reports yet
Sign in to report whether this part worked for you.
Discussion

Scoped to this part · feeds back into the world's score.

0comments
Sign in to post.sign in
No comments yet. Be the first.