GitHub

Events

Arbiter is the event system of the browser part. Modules subscribe to an event without knowing about each other, and any response can inform it: one call from PHP, and every widget that listens reacts.
  • subscribe(event, callback)

    In a module: returns a subscription with remove().

  • inform(event, data)

    Calls every subscriber of the event with the data.

  • informState(event, data)

    Like inform, and a later subscriber is called with the last data right away.

  • clearState(event)

    Forgets the last data of the event.

Controller.php
// PHP: one call informs every module that listens
return (new AsyncResponse())
    ->call('bigpipe-util/dist/core/Arbiter', 'informState', [
        'ORDER/PLACED',
        ['id' => 1004, 'product' => 'Mouse', 'count' => 4],
    ])
    ->send();

// JavaScript: in any module
new Arbiter().subscribe('ORDER/PLACED', order => {
    badge.textContent = order.count;
});
Try it
Carttutorial/OrderBadge

0 orders · $0.00

Activitytutorial/OrderLog
  • No orders yet.

A widget added later shows up here.

One event, independent widgets

Place an order: the response informs ORDER/PLACED, and the badge and the log update on their own. Add a widget after some orders: it subscribes, and gets the last order at once.