Merge pull request #243 from bryvin/master

Added component activation/register observers
This commit is contained in:
Mo Bitar
2018-10-08 12:11:47 -05:00
committed by GitHub
2 changed files with 25 additions and 1 deletions

View File

@@ -808,6 +808,8 @@ class ComponentManager {
} }
}); });
this.postActiveThemeToComponent(component); this.postActiveThemeToComponent(component);
this.desktopManager.notifyComponentActivation(component);
} }
/* Performs func in timeout, but syncronously, if used `await waitTimeout` */ /* Performs func in timeout, but syncronously, if used `await waitTimeout` */

View File

@@ -10,6 +10,7 @@ class DesktopManager {
this.$rootScope = $rootScope; this.$rootScope = $rootScope;
this.timeout = $timeout; this.timeout = $timeout;
this.updateObservers = []; this.updateObservers = [];
this.componentActivationObservers = [];
this.isDesktop = isDesktopApplication(); this.isDesktop = isDesktopApplication();
@@ -106,7 +107,28 @@ class DesktopManager {
for(var observer of this.updateObservers) { for(var observer of this.updateObservers) {
observer.callback(component); observer.callback(component);
} }
}) });
}
desktop_registerComponentActivationObserver(callback) {
var observer = {id: Math.random, callback: callback};
this.componentActivationObservers.push(observer);
return observer;
}
desktop_deregisterComponentActivationObserver(observer) {
_.pull(this.componentActivationObservers, observer);
}
/* Notify observers that a component has been registered/activated */
async notifyComponentActivation(component) {
var serializedComponent = await this.convertComponentForTransmission(component);
this.timeout(() => {
for(var observer of this.componentActivationObservers) {
observer.callback(serializedComponent);
}
});
} }
/* Used to resolve "sn://" */ /* Used to resolve "sn://" */