Component Lifecycle Callbacks
@Tag("div")
public class ShoppingCartSummaryLabel extends Component {
private final Consumer<EventObject> eventHandler = this::onCartSummaryUpdate;
@Override
protected void onAttach(AttachEvent attachEvent) {
ShopEventBus eventBus = attachEvent.getSession().getAttribute(ShopEventBus.class);
}
@Override
protected void onDetach(DetachEvent detachEvent) {
ShopEventBus eventBus = detachEvent.getSession().getAttribute(ShopEventBus.class);
// after detaching don't need any updates
eventBus.unregister(eventHandler);
}
// update cart summary ...
}
}
void register(Consumer<EventObject> eventHandler);
void unregister(Consumer<EventObject> eventHandler);
}