Idan Amit | 6187c94 | 2018-04-15 19:19:08 +0300 | [diff] [blame] | 1 | import {BasePubSub} from "./base-pubsub"; |
| 2 | |
| 3 | declare const window: Window; |
| 4 | |
| 5 | export class PluginPubSub extends BasePubSub { |
| 6 | |
| 7 | constructor(pluginId: string, parentUrl: string, eventsToWait?: Array<string>) { |
| 8 | super(pluginId); |
| 9 | this.register('sdc-hub', window.parent, parentUrl); |
| 10 | this.subscribe(eventsToWait); |
| 11 | } |
| 12 | |
| 13 | public subscribe(eventsToWait?: Array<string>) { |
| 14 | const registerData = { |
| 15 | pluginId: this.clientId, |
| 16 | eventsToWait: eventsToWait || [] |
| 17 | }; |
| 18 | |
| 19 | this.notify('PLUGIN_REGISTER', registerData); |
| 20 | } |
| 21 | |
| 22 | public unsubscribe() { |
| 23 | const unregisterData = { |
| 24 | pluginId: this.clientId |
| 25 | }; |
| 26 | |
| 27 | this.notify('PLUGIN_UNREGISTER', unregisterData); |
| 28 | } |
| 29 | } |