Skip to content
docsv0.31.1

DispatchEffect

A cross-component dispatch effect: a component's `handle()` DECLARES that a browser event is delivered to ANOTHER component, which reacts client-side — no re-render, no imperative JS (greenhouse decisions/0189). Where {@see RenderEffect} re-paints the target, this one SIGNALS it: the client dispatches a `milpa:<event>` CustomEvent (with the payload as its `detail`) on the target component's root. The target listens with `x-on:milpa:<event>` (Alpine) or a plain listener and updates itself. Use it when the other component should react (open, highlight, refetch) without the server re-rendering it.

DispatchEffect::__construct()

public function __construct(string $to, string $event, array $payload = []):

Parameters

Parameters of __construct()
NameTypeDescription
$tostringthe componentId of the component to notify
$eventstringthe event name (delivered as `milpa:<event>`)
$payloadarray<string, mixed>the event detail

DispatchEffect::toArray()

public function toArray(): array

The effect as the array that travels in {@see \Milpa\Live\ValueObjects\InteractionResult::$effects}.