@aappddeevv/dynamics-client-ui
Version:
## What is it? A library to help you create great dynamics applications.
35 lines • 1.17 kB
JavaScript
;
/**
* Simple Dynamics event bus. Designed to be used for simple needs
* and attached to a window that sub-iframes can access easily so their
* WebResources can listen for events from across a Dynamics form
* e.g. a grid select needs.
*/
Object.defineProperty(exports, "__esModule", { value: true });
/** Small pubsub, synchronous dispatch. */
class EventBus {
constructor() {
this.subscribers = [];
}
unsubscribe(key) {
this.subscribers = this.subscribers.filter(s => s !== key);
}
/** Subscriber is just a thunk. Thunk returned unsubscribes. */
subscribe(subscriber) {
if (subscriber)
this.subscribers.push(subscriber);
return (() => this.unsubscribe(subscriber));
}
/** Dispatch an event. All subscribers get all events like redux. */
dispatch(event) {
this.subscribers.forEach(sub => {
if (sub)
sub(event);
});
}
}
exports.EventBus = EventBus;
exports.default = EventBus;
// where are we getting loaded? it's a subframe I know that...
//console.log("frameElement", window.frameElement)
//# sourceMappingURL=EventBus.js.map