Skip to content

Commit

Permalink
not caching GLOBAL
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipskevin committed Jan 12, 2018
1 parent 95da544 commit 58fe035
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions can-view-callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ var requestedAttributes = {};

var tags = {};

var GLOBAL = getGlobal();
var supportsCustomElements = "customElements" in GLOBAL;
var viewmodelSymbol = canSymbol.for("can.viewModel");

// WeakSet containing elements that have been mounted already
Expand Down Expand Up @@ -65,13 +63,13 @@ var enableMutationObserver = function() {
};

var obs = new MutationObserver(mutationHandler);
obs.observe(GLOBAL.document.documentElement, { childList: true, subtree: true });
obs.observe(getGlobal().document.documentElement, { childList: true, subtree: true });

mutationObserverEnabled = true;
};

var mountExistingElements = function(tagName) {
var nodes = GLOBAL.document.getElementsByTagName(tagName);
var nodes = getGlobal().document.getElementsByTagName(tagName);

for (var i=0, node; (node = nodes[i]) !== undefined; i++) {
mountNodeAndChildrenIfNecessary(node);
Expand Down Expand Up @@ -127,6 +125,8 @@ var defaultCallback = function () {};

var tag = function (tagName, tagHandler) {
if(tagHandler) {
var GLOBAL = getGlobal();

//!steal-remove-start
if (typeof tags[tagName.toLowerCase()] !== 'undefined') {
dev.warn("Custom tag: " + tagName.toLowerCase() + " is already defined");
Expand All @@ -137,6 +137,7 @@ var tag = function (tagName, tagHandler) {
return;
}
//!steal-remove-end

// if we have html5shiv ... re-generate
if (GLOBAL.html5) {
GLOBAL.html5.elements += " " + tagName;
Expand All @@ -147,7 +148,7 @@ var tag = function (tagName, tagHandler) {

// automatically mount elements that have tagHandlers
// If browser supports customElements, register the tag as a custom element
if (supportsCustomElements) {
if ("customElements" in GLOBAL) {
var CustomElement = function() {
return Reflect.construct(HTMLElement, [], CustomElement);
};
Expand Down Expand Up @@ -215,6 +216,7 @@ var callbacks = {

//!steal-remove-start
if (!tagCallback) {
var GLOBAL = getGlobal();
var ceConstructor = GLOBAL.document.createElement(tagName).constructor;
// If not registered as a custom element, the browser will use default constructors
if (ceConstructor === GLOBAL.HTMLElement || ceConstructor === GLOBAL.HTMLUnknownElement) {
Expand Down

0 comments on commit 58fe035

Please sign in to comment.