Fixes and improvements related to components

This commit is contained in:
Mo Bitar
2020-04-15 19:17:08 -05:00
parent 1280c2ec52
commit 407e3ea0d8
21 changed files with 276 additions and 270 deletions

View File

@@ -1,10 +1,10 @@
import { WebApplication } from '@/ui_models/application';
import { SNComponent } from 'snjs';
import { SNComponent, LiveItem } from 'snjs';
import { WebDirective } from './../../types';
import template from '%/directives/component-modal.pug';
type ComponentModalScope = {
component: SNComponent
export type ComponentModalScope = {
componentUuid: string
callback: () => void
onDismiss: (component: SNComponent) => void
application: WebApplication
@@ -12,16 +12,34 @@ type ComponentModalScope = {
export class ComponentModalCtrl implements ComponentModalScope {
$element: JQLite
component!: SNComponent
componentUuid!: string
callback!: () => void
onDismiss!: (component: SNComponent) => void
application!: WebApplication
liveComponent!: LiveItem<SNComponent>
component!: SNComponent
/* @ngInject */
constructor($element: JQLite) {
this.$element = $element;
}
$onInit() {
this.liveComponent = new LiveItem(
this.componentUuid,
this.application,
(component) => {
this.component = component;
}
);
this.application.componentGroup.activateComponent(this.component);
}
$onDestroy() {
this.application.componentGroup.deactivateComponent(this.component);
this.liveComponent.deinit();
}
dismiss() {
this.onDismiss && this.onDismiss(this.component);
this.callback && this.callback();
@@ -41,7 +59,7 @@ export class ComponentModal extends WebDirective {
this.controllerAs = 'ctrl';
this.bindToController = true;
this.scope = {
component: '=',
componentUuid: '=',
callback: '=',
onDismiss: '&',
application: '='