Reference · Event bus
The widget communicates with the host via two public channels on window:
- CustomEvents emitted — the host subscribes.
- CustomEvents listened to — the host emits.
There is no public postMessage for external integrators.
Summary
| Type | Direction | Name | Payload |
|---|---|---|---|
| CustomEvent | widget → host | neuroon-theme-change | { theme: 'light' | 'dark', containerId?: string } |
| CustomEvent | host → widget | neuroon:cart-update | (no detail) |
neuroon-theme-change (widget → host)
Fired when the active theme changes, either because the system changed under theme="auto" or because the host called widget.setTheme(...).
type NeuroonThemeChangeDetail = {
theme: 'light' | 'dark'
containerId?: string // only present on automatic system-triggered changes
}
window.addEventListener('neuroon-theme-change', (e) => {
const {theme, containerId} = (e as CustomEvent<NeuroonThemeChangeDetail>).detail
document.documentElement.dataset.theme = theme
// If you have multiple widget instances, filter by containerId.
})
neuroon:cart-update (host → widget)
The host emits it after any cart mutation outside the widget (mini-cart, cart page, another plugin). The listener ignores event.detail — on receipt the widget calls config.cart.onGetCart() to read the cart from your host.
// The listener ignores event.detail. Dispatch with no payload.
window.dispatchEvent(new CustomEvent('neuroon:cart-update'))
Behavior:
- If widget-originated operations are in flight, the event is discarded (no overwriting of optimistic state).
- Debounced 300 ms.
- Calls
config.cart.onGetCart()and updates internal state.
The event name is configurable via
cart.externalUpdateEvent(default'neuroon:cart-update').
Reacting to searches, clicks or conversions
Subscribe to the DOM events listed above or consume the server-side tracking endpoint. For advanced flows, the onTokenExpiring / onTokenRefreshed callbacks in NeuroonWidgetConfig.callbacks let you orchestrate token rotation from the host.
Further reading
- Widget → Events — narrative version with examples.
- Widget → Cart integration.
- Widget → Theming.