summaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2
diff options
context:
space:
mode:
authorIdan Amit <ia096e@intl.att.com>2018-04-15 19:19:08 +0300
committerIdan Amit <ia096e@intl.att.com>2018-04-15 19:19:08 +0300
commit6187c942bedebeb2f452ed0856652f90cd5c5772 (patch)
tree9c3463873e34d9097f2119b9ed35900f6ecab733 /catalog-ui/src/app/ng2
parent821b76c6b81ebf96e8fd8340ac5f6ed79f8ed22a (diff)
New observable notify design in pubsub
Implemented the new subscription mechanism for the pub sub notify function Change-Id: I5e6484adf1a0413d48b54b55048cda1a59b387ee Issue-ID: SDC-1178 Signed-off-by: Idan Amit <ia096e@intl.att.com>
Diffstat (limited to 'catalog-ui/src/app/ng2')
-rw-r--r--catalog-ui/src/app/ng2/components/ui/plugin/plugin-frame.component.ts13
-rw-r--r--catalog-ui/src/app/ng2/services/event-bus.service.ts17
2 files changed, 23 insertions, 7 deletions
diff --git a/catalog-ui/src/app/ng2/components/ui/plugin/plugin-frame.component.ts b/catalog-ui/src/app/ng2/components/ui/plugin/plugin-frame.component.ts
index 2ba784727f..4759721034 100644
--- a/catalog-ui/src/app/ng2/components/ui/plugin/plugin-frame.component.ts
+++ b/catalog-ui/src/app/ng2/components/ui/plugin/plugin-frame.component.ts
@@ -43,13 +43,16 @@ export class PluginFrameComponent implements OnInit {
this.pluginUrl += this.urlSearchParams.toString();
}
- this.eventBusService.on((eventData) => {
+ let readyEvent = (eventData) => {
if (eventData.originId === this.plugin.pluginId) {
if (eventData.type == "READY") {
this.onLoadingDone.emit();
+ this.eventBusService.off(readyEvent)
}
}
- });
+ };
+
+ this.eventBusService.on(readyEvent);
// Listening to the stateChangeStart event in order to notify the plugin about it being closed
// before moving to a new state
@@ -58,11 +61,11 @@ export class PluginFrameComponent implements OnInit {
if (!this.isClosed) {
event.preventDefault();
- this.eventBusService.notify("WINDOW_OUT");
+ this.eventBusService.notify("WINDOW_OUT").subscribe(() => {
+ this.isClosed = true;
- this.isClosed = true;
+ this.eventBusService.unregister(this.plugin.pluginId);
- setTimeout(() => {
this.$state.go(toState.name, toParams);
});
}
diff --git a/catalog-ui/src/app/ng2/services/event-bus.service.ts b/catalog-ui/src/app/ng2/services/event-bus.service.ts
index 7730a77f41..438437d193 100644
--- a/catalog-ui/src/app/ng2/services/event-bus.service.ts
+++ b/catalog-ui/src/app/ng2/services/event-bus.service.ts
@@ -11,6 +11,18 @@ export class EventBusService extends BasePubSub {
protected handlePluginRegistration(eventData: IPubSubEvent, event: any) {
if (eventData.type === 'PLUGIN_REGISTER') {
this.register(eventData.data.pluginId, event.source, event.origin);
+
+ let newEventsList = [];
+
+ if (this.eventsToWait.has(eventData.data.pluginId)) {
+ newEventsList = _.union(this.eventsToWait.get(eventData.data.pluginId), eventData.data.eventsToWait);
+ }
+ else {
+ newEventsList = eventData.data.eventsToWait;
+ }
+
+ this.eventsToWait.set(eventData.data.pluginId, newEventsList);
+
} else if (eventData.type === 'PLUGIN_UNREGISTER') {
this.unregister(eventData.data.pluginId);
}
@@ -21,8 +33,9 @@ export class EventBusService extends BasePubSub {
pluginId: pluginId
};
- this.notify('PLUGIN_CLOSE', unregisterData);
- super.unregister(pluginId);
+ this.notify('PLUGIN_CLOSE', unregisterData).subscribe(() => {
+ super.unregister(pluginId);
+ });
}
protected onMessage(event: any) {