Skip to content

Latest commit

 

History

History
47 lines (36 loc) · 1.09 KB

README.md

File metadata and controls

47 lines (36 loc) · 1.09 KB

<prism-event-bus>

Published on webcomponents.org

<prism-event-bus> is a Polymer 2 element provides compact event bus that simplifies communication between elements.

Usage

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`
    }
}));

Licence

MIT Licence