Skip to content

Commit

Permalink
live extensions are always async
Browse files Browse the repository at this point in the history
  • Loading branch information
chemerisuk committed Jan 24, 2015
1 parent 282f796 commit 1326cd9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/document/extend.js
Expand Up @@ -79,12 +79,14 @@ DOM.register({
var ext = ExtensionHandler(selector, condition, definition, mappings.length);

mappings.push(ext);

// initialize extension manually to make sure that all elements
// have appropriate methods before they are used in other DOM.extend.
// Also fixes legacy IEs when the HTC behavior is already attached
_.each.call(node.ownerDocument.querySelectorAll(selector), ext);
// MUST be after querySelectorAll because of legacy IEs quirks
this.importStyles(selector, cssText);
// live extensions are always async - append CSS asynchronously
WINDOW.setTimeout(() => {
// initialize extension manually to make sure that all elements
// have appropriate methods before they are used in other DOM.extend.
// Also fixes legacy IEs when the HTC behavior is already attached
_.each.call(node.ownerDocument.querySelectorAll(selector), ext);
// MUST be after querySelectorAll because of legacy IEs quirks
this.importStyles(selector, cssText);
}, 0);
}
});
2 changes: 1 addition & 1 deletion task/compile.js
Expand Up @@ -42,7 +42,7 @@ module.exports = function(dest, pkg) {
var ast = container.convert();
var code = recast.print(ast[0]).code;
// improve internal type names
code = code.replace(/types\$\$(\$?\w+)/g, "$1");
code = code.replace(/(?:errors|types)\$\$(\$?\w+)/g, "$1");
// remove generated prefix from constants
code = code.replace(/const\$\$/g, "");
// fix for browserify that prohibits global this
Expand Down
10 changes: 10 additions & 0 deletions test/spec/dom/extend.spec.js
Expand Up @@ -264,6 +264,16 @@ describe("extend", function() {
}, 50);
});

it("is always async", function() {
var spy = jasmine.createSpy("ctr");

jasmine.sandbox.set("<a class=" + randomClass + "></a>");

DOM.extend("." + randomClass, spy);

expect(spy).not.toHaveBeenCalled();
});

// it("allows extending the $Element prototype", function() {
// DOM.extend("*", {
// test: function() { return 555 }
Expand Down

0 comments on commit 1326cd9

Please sign in to comment.