In the past, whenever I needed to update the UI state, after a change in some @Entity, I relied on EventBus using ComponentEvent
e.g. Whenever the user information was changed in the ProfileView, the MainView would get notified and the avatar, display name etc would get updated
//Base custom event
@Getter
public abstract class MyEvent extends ComponentEvent<Component> {
public enum Type {
CREATE, UPDATE, DELETE
}
private final Type type;
public MyEvent(Component source, Type type) {
super(source, true);
this.type = type;
}
}
//Custom event
@Getter
public class UserEvent extends MyEvent {
private final User user;
public UserEvent(Component source, User user, Type type) {
super(source, type);
this.user = user;
}
}
//MainView
@Override
protected void onAttach(AttachEvent attachEvent) {
super.onAttach(attachEvent);
this.userRegistration = ComponentUtil.addListener(UI.getCurrent(), UserEvent.class, event -> {
//User updated
if (MyEvent.Type.UPDATE.equals(event.getType())) {
this.currentUser = event.getUser();
this.avatar.setName(this.currentUser.getDisplayName());
this.menuDisplayName.setText(this.currentUser.getDisplayName());
this.instituteNameTitle.setText(currentUser.getInstitute().getDisplayName());
}
});
}
@Override
protected void onDetach(DetachEvent detachEvent) {
super.onDetach(detachEvent);
this.userRegistration.remove();
}
Now, from what I understand, Signals is the recommended way moving forward.
What advantages/extra features does Signals offer, over ComponentEvent?
Thank you