Slots are named attachment points where presenters reveal their views. Declare a slot key on the presenter with @BrixSlot. Built-in slots like BrixSlots.BRIX_BODY_SLOT are registered automatically.
@BrixPresenter
@BrixSlot(BrixSlots.BRIX_BODY_SLOT)
@BrixRoute("dashboard")
@BrixComponent(presenter = DashboardPresenter.class)
public class DashboardComponent {}
Register custom slots before navigation or during presenter activation. Slots added inside a presenter should use registerSlot(...) so they clean up on deactivation.
Element contentHost = DomGlobal.document.getElementById("content");
Slot contentSlot = AcceptOneElementSlot.of("content-slot", contentHost);
Brix.get().slots().register(contentSlot);
@Override
protected void registerSlots() {
registerSlot(AppendElementSlot.of("notifications", notificationsContainer));
}
Annotate the presenter with @RegisterSlots to force the view to supply slot instances. The processor emits a *Slots interface; implement it in the view and return slot instances for each key.
@BrixPresenter
@BrixSlot("content")
@RegisterSlots({"content", "menu-bar"})
@BrixRoute("dashboard")
@BrixComponent(presenter = DashboardPresenter.class)
public class DashboardComponent {}
public interface DashboardView extends View, DashboardSlots {
void showCustomer(String name);
}
public class DashboardViewImpl implements DashboardView {
private final HTMLElement main = DomGlobal.document.getElementById("main");
private final HTMLElement menu = DomGlobal.document.getElementById("menu");
@Override
public Slot getContentSlot(String key) {
return AcceptOneElementSlot.of(key, main);
}
@Override
public Slot getMenuBarSlot(String key) {
return AppendElementSlot.of(key, menu);
}
}
Implement Slot (or extend helpers like AcceptOneElementSlot) to control how content attaches. Slots registered globally live until removed; slots registered through registerSlot are automatically unregistered on deactivation.