1. Domino Brix
  2. Events & context

Events

Brix includes a lightweight event bus. Extend BrixEvent for custom payloads, fire events globally, and handle them with @ListenFor on presenters.

			public class UserLoggedIn extends BrixEvent {
  private final String userId;
  public UserLoggedIn(String userId) { this.userId = userId; }
  public String getUserId() { return userId; }
}

events().fireEvent(new UserLoggedIn("42"));
events().fireEvent(this, new UserLoggedIn("42")); // sets source

		
			@BrixPresenter
public class NavPresenter extends Presenter<NavView> {
  @ListenFor(UserLoggedIn.class)
  void handleLogin(UserLoggedIn event) {
    if (event.getSource().orElse(null) == this) return;
    view.showUser(event.getUserId());
  }
}

		

Listening

Presenters are registered as listeners on activation and removed on deactivation. Any component can register manually via Brix.get().events().register(...) and keep the returned RegistrationRecord to remove it.

Context

Use HasContext<T> to broadcast store-like state changes with an operation flag. IsContext carries data, operation (CREATED, UPDATED, DELETED), and source.

			public class ProfileStore implements HasContext<ProfileStore> {
  private IsContext<ProfileStore> context;
  private final Set<ContextListener<ProfileStore>> listeners = new HashSet<>();

  public void createProfile(Profile profile) { update(IsContext.created(this, profile)); }
  public void updateProfile(Profile profile) { update(IsContext.updated(this, profile)); }
  public void deleteProfile(Profile profile) { update(IsContext.deleted(this, profile)); }

  @Override public void setContext(IsContext<ProfileStore> context) { this.context = context; }
  @Override public IsContext<ProfileStore> getContext() { return context; }
  @Override public Set<ContextListener<ProfileStore>> getContextListeners() { return listeners; }
}

		

Listening to context updates

Register context listeners to react to create/update/delete signals. Registration immediately replays the current context when present.

			profileStore.registerContextListener(ctx -> {
  ctx.getOperation().when(Operation.CREATED, () -> view.showNew(ctx.getData()));
  ctx.getOperation().when(Operation.UPDATED, () -> view.refresh(ctx.getData()));
  ctx.getOperation().when(Operation.DELETED, () -> view.clear());
});

		

Lifecycle tips

  • Use events().fireEvent(source, event) to set the source for filtering.
  • Remove manual listeners on teardown to avoid leaks.
  • Combine context with events for cross-module communication without tight coupling.

We are a group of passionate people who love what we do

Donate & Support Us