<prism-event-bus>
is a Polymer 2 element provides compact event bus that simplifies communication between elements.
Register element
// Register element with all event types
PrismEventBus.register(this);
// Register element with scoped types
PrismEventBus.register(this, ['talk', 'walk']);
// Unregister element if destroied or something
PrismEventBus.unregister(this);
// Remove registered event type
PrismEventBus.unregister(this, ['walk']);
Then post event anywhere
// Post immediately
PrismEventBus.post(new CustomEvent('talk', {
bubbles: false,
composed: true,
detail: {
text: `Hello, World`
}
}));
// Or post if element will be registered later
PrismEventBus.postDelayed(new CustomEvent('talk', {
bubbles: false,
composed: true,
detail: {
text: `Hello, World`
}
}));
MIT Licence