Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Cache window.ShadowDOMPolyfill value in closures
Browse files Browse the repository at this point in the history
This avoids unnecessary references properties on window, which are
slow to look up.
  • Loading branch information
ajklein committed Jul 30, 2014
1 parent 3acc3c6 commit 1770481
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/declaration/prototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
var isBase = scope.isBase;
var extend = scope.extend;

var hasShadowDOMPolyfill = window.ShadowDOMPolyfill;

// prototype api

var prototype = {
Expand Down Expand Up @@ -101,7 +103,7 @@
// this.$.image.src = this.resolvePath('images/foo.png')
this.addResolvePathApi();
// under ShadowDOMPolyfill, transforms to approximate missing CSS features
if (window.ShadowDOMPolyfill) {
if (hasShadowDOMPolyfill) {
Platform.ShadowCSS.shimStyling(this.templateContent(), name, extendee);
}
// allow custom element access to the declarative context
Expand Down
4 changes: 3 additions & 1 deletion src/declaration/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
var api = scope.api.instance.styles;
var STYLE_SCOPE_ATTRIBUTE = api.STYLE_SCOPE_ATTRIBUTE;

var hasShadowDOMPolyfill = window.ShadowDOMPolyfill;

// magic words

var STYLE_SELECTOR = 'style';
Expand Down Expand Up @@ -187,7 +189,7 @@
if (scope === document) {
scope = document.head;
}
if (window.ShadowDOMPolyfill) {
if (hasShadowDOMPolyfill) {
scope = document.head;
}
// TODO(sorvell): necessary for IE
Expand Down
7 changes: 4 additions & 3 deletions src/instance/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
// imports

var log = window.logFlags || {};

var hasShadowDOMPolyfill = window.ShadowDOMPolyfill;

// magic words

var STYLE_SCOPE_ATTRIBUTE = 'element';
Expand Down Expand Up @@ -60,7 +61,7 @@
if (!scope) {
return;
}
if (window.ShadowDOMPolyfill) {
if (hasShadowDOMPolyfill) {
cssText = shimCssText(cssText, scope.host);
}
var style = this.element.cssTextToScopeStyle(cssText,
Expand All @@ -82,7 +83,7 @@
return cache[name];
},
styleCacheForScope: function(scope) {
if (window.ShadowDOMPolyfill) {
if (hasShadowDOMPolyfill) {
var scopeName = scope.host ? scope.host.localName : scope.localName;
return polyfillScopeStyleCache[scopeName] || (polyfillScopeStyleCache[scopeName] = {});
} else {
Expand Down

0 comments on commit 1770481

Please sign in to comment.