This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-ui.git


The following commit(s) were added to refs/heads/master by this push:
     new b26fc41c guard against unnecessary watchers and null dsl refs after GC
b26fc41c is described below

commit b26fc41cb443010b208a2b8685f071da69248395
Author: Alex Heneveld <[email protected]>
AuthorDate: Wed Dec 7 11:04:21 2022 +0000

    guard against unnecessary watchers and null dsl refs after GC
---
 .../app/components/dsl-viewer/dsl-viewer.js                |  5 +++--
 .../app/components/util/model/dsl.model.js                 | 14 ++++++++++----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git 
a/ui-modules/blueprint-composer/app/components/dsl-viewer/dsl-viewer.js 
b/ui-modules/blueprint-composer/app/components/dsl-viewer/dsl-viewer.js
index 75343e3b..8a90ba55 100644
--- a/ui-modules/blueprint-composer/app/components/dsl-viewer/dsl-viewer.js
+++ b/ui-modules/blueprint-composer/app/components/dsl-viewer/dsl-viewer.js
@@ -55,7 +55,7 @@ export function dslViewerDirective($log) {
         };
         
         function updateModeAndIcon(dsl) {
-            var fam = dsl.kind && dsl.kind.family;
+            var fam = dsl.kindFamily;
             if (fam === FAMILY.FUNCTION) {
                 switch (dsl.kind) {
                     case KIND.METHOD: {
@@ -108,7 +108,8 @@ export function dslViewerDirective($log) {
                 return null;
             }
         }
-        
+
+        updateModeAndIcon(scope.dsl);  // do this now so watcher doesn't 
unnecessarily change things
         scope.$watch('dsl', () => {
             updateModeAndIcon(scope.dsl);
         }, true);
diff --git 
a/ui-modules/blueprint-composer/app/components/util/model/dsl.model.js 
b/ui-modules/blueprint-composer/app/components/util/model/dsl.model.js
index 3adef23f..75b7bee9 100644
--- a/ui-modules/blueprint-composer/app/components/util/model/dsl.model.js
+++ b/ui-modules/blueprint-composer/app/components/util/model/dsl.model.js
@@ -223,6 +223,12 @@ export class Dsl {
         return KINDS.get(this);
     }
 
+    get kindFamily() {
+        // guard against kind being null due to GC (eg in errors)
+        let k = KINDS.get(this);
+        return k && k.family;
+    }
+
     /**
      * Set kind
      * @param kind
@@ -275,7 +281,7 @@ export class Dsl {
      */
     param(param) {
         if (param instanceof Dsl) {
-            if (this.kind.family !== FAMILY.FUNCTION) {
+            if (this.kindFamily !== FAMILY.FUNCTION) {
                 throw new DslError('Cannot push param to non-function... Dsl 
kind is: ' + this.kind.name);
             }
             PARAMS.get(this).push(param);
@@ -375,7 +381,7 @@ export class Dsl {
      */
     chain(method) {
         if (method instanceof Dsl) {
-            if (method.kind.family !== FAMILY.FUNCTION) {
+            if (method.kindFamily !== FAMILY.FUNCTION) {
                 throw new DslError('Cannot push method ... method must be a 
function');
             }
             let last = this.getLastMethod();
@@ -438,7 +444,7 @@ export class Dsl {
     toString() {
         let current = this;
         let yaml = current.generate();
-        switch (current.kind.family) {
+        switch (current.kindFamily) {
             case FAMILY.FUNCTION:
                 yaml = FUNCTION_PREFIX + yaml;
                 // fallthrough to next case
@@ -483,7 +489,7 @@ export class Dsl {
      * @return {string}
      */
     generate() {
-        if (this.kind.family === FAMILY.FUNCTION) {
+        if (this.kindFamily === FAMILY.FUNCTION) {
             return this.name + '(' + this.generateParams() + ')';
         }
         else if (this.kind === KIND.ENTITY) {

Reply via email to