[Representation] Show element synchronously

...to avoid exceptions when trying to invoke representers
before an mct-representation has been added back into the
DOM.
This commit is contained in:
Victor Woeltjen
2015-10-28 15:32:50 -07:00
parent bcc42d705e
commit 5677548298

View File

@@ -73,10 +73,15 @@ define(
} }
} }
function replaceElement(template) { function addElement() {
activeElement.replaceWith(element); if (activeElement !== element) {
activeElement = element; activeElement.replaceWith(element);
activeElement.empty(); activeElement = element;
activeElement.empty();
}
}
function populateElement(template) {
template(scope, function (innerClone) { template(scope, function (innerClone) {
element.append(innerClone); element.append(innerClone);
}); });
@@ -84,7 +89,7 @@ define(
function applyTemplate(template) { function applyTemplate(template) {
if (template) { if (template) {
replaceElement(template); populateElement(template);
} else { } else {
removeElement(); removeElement();
} }
@@ -93,6 +98,7 @@ define(
function changeTemplate(templateUrl) { function changeTemplate(templateUrl) {
if (templateUrl !== activeTemplateUrl) { if (templateUrl !== activeTemplateUrl) {
if (templateUrl) { if (templateUrl) {
addElement();
self.load(templateUrl).then(applyTemplate); self.load(templateUrl).then(applyTemplate);
} else { } else {
removeElement(); removeElement();