Skip to content

Commit

Permalink
Don't disable listening for new elements during widget creation lifec…
Browse files Browse the repository at this point in the history
…ycle.

Fixes ibm-js#443.
  • Loading branch information
wkeese committed Apr 13, 2016
1 parent 67ae90d commit e163cea
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions register.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,10 @@ define([

// If the document has already been parsed then do a supplementary sweep for this new custom element.
if (initialParseComplete && !has("document-register-element")) {
unobserve(); // pause listening for added/deleted nodes
var node, idx = 0, nodes = doc.querySelectorAll(selector);
while ((node = nodes[idx++])) {
upgrade(node, true);
}
observe(); // resume listening for added/deleted nodes
}

return tagConstructor;
Expand Down Expand Up @@ -487,7 +485,6 @@ define([
*/
function processMutations(mutations) {
if (!has("document-register-element") && selectors.length) {
unobserve(); // pause listening for added/deleted nodes
var parseDescendants = has("MutationObserver") || has("DOMNodeInserted") === "root";
mutations.forEach(function (mutation) {
var added, idx1 = 0;
Expand Down Expand Up @@ -519,7 +516,6 @@ define([
}
}
});
observe(); // resume listening for added/deleted nodes
}
}

Expand All @@ -531,12 +527,11 @@ define([
function deliver() {
if (!has("document-register-element")) {
if (!initialParseComplete) {
observe(); // start listening for new nodes added to the document
parse();
initialParseComplete = true;
observe();
} else {
processMutations(observer.takeRecords());
}
processMutations(observer.takeRecords());
}
}

Expand Down Expand Up @@ -600,5 +595,20 @@ define([
*/
register.superCall = dcl.superCall;

/**
* Function to manually resume listening for custom elements added to the DOM.
* Not normally called directly.
* Called after `unobserve()`.
* @function module:delite/register.observe
*/
register.observe = observe;

/**
* Function to manually pause listening for custom elements added to the DOM.
* Not normally called directly.
* @function module:delite/register.unobserve
*/
register.unobserve = unobserve;

return register;
});

0 comments on commit e163cea

Please sign in to comment.