From c5fcc5a5580436e478a2d28e8b493016e5485120 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 28 Oct 2015 15:57:47 -0700 Subject: [PATCH] [Representation] Handle edge cases Handle edge cases (e.g. directive priorities, race conditions) to ensure that mct-representation and mct-include display correctly when added to or removed from the DOM. --- platform/representation/src/MCTInclude.js | 3 +++ platform/representation/src/MCTRepresentation.js | 3 +++ platform/representation/src/TemplateLinker.js | 10 ++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/platform/representation/src/MCTInclude.js b/platform/representation/src/MCTInclude.js index e00ef8599d..d56d2f0e69 100644 --- a/platform/representation/src/MCTInclude.js +++ b/platform/representation/src/MCTInclude.js @@ -84,6 +84,9 @@ define( // Use the included controller to populate scope link: link, + // May hide the element, so let other directives act first + priority: -1000, + // Two-way bind key, ngModel, and parameters scope: { key: "=", ngModel: "=", parameters: "=" } }; diff --git a/platform/representation/src/MCTRepresentation.js b/platform/representation/src/MCTRepresentation.js index 3c09edbfc4..4704c0265e 100644 --- a/platform/representation/src/MCTRepresentation.js +++ b/platform/representation/src/MCTRepresentation.js @@ -236,6 +236,9 @@ define( // Handle Angular's linking step link: link, + // May hide the element, so let other directives act first + priority: -1000, + // Two-way bind key and parameters, get the represented domain // object as "mct-object" scope: { diff --git a/platform/representation/src/TemplateLinker.js b/platform/representation/src/TemplateLinker.js index fd5ba57a3c..29df511427 100644 --- a/platform/representation/src/TemplateLinker.js +++ b/platform/representation/src/TemplateLinker.js @@ -83,11 +83,12 @@ define( function populateElement(template) { template(scope, function (innerClone) { + element.empty(); element.append(innerClone); }); } - function applyTemplate(template) { + function applyTemplate(template, templateUrl) { if (template) { populateElement(template); } else { @@ -99,7 +100,12 @@ define( if (templateUrl !== activeTemplateUrl) { if (templateUrl) { addElement(); - self.load(templateUrl).then(applyTemplate); + self.load(templateUrl).then(function (template) { + // Avoid race conditions + if (templateUrl === activeTemplateUrl) { + applyTemplate(template); + } + }); } else { removeElement(); }