From da15ff09fe670fb675ef86c3ff8c3834240432ef Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Fri, 20 Nov 2015 14:52:13 -0800 Subject: [PATCH] Minor factoring; ensure base properties set on instance. --- polymer.html | 4 ++ src/lib/base.html | 1 + src/lib/dom-api-shady.html | 110 +++++++++--------------------------- src/lib/dom-tree-api.html | 64 ++++++++++++++++++++- src/mini/ready.html | 3 + src/mini/shady.html | 18 +++++- src/standard/configure.html | 1 + src/standard/gestures.html | 5 ++ src/standard/x-styling.html | 5 ++ 9 files changed, 124 insertions(+), 87 deletions(-) diff --git a/polymer.html b/polymer.html index 342da18383..910447997e 100644 --- a/polymer.html +++ b/polymer.html @@ -57,12 +57,16 @@ }, _initFeatures: function() { + // setup gestures + this._setupGestures(); // manage configuration this._setupConfigure(); // setup style properties this._setupStyleProperties(); // setup debouncers this._setupDebouncers(); + // setup shady + this._setupShady(); this._registerHost(); if (this._template) { // manage local dom diff --git a/src/lib/base.html b/src/lib/base.html index 10f6b4d491..920b71d559 100644 --- a/src/lib/base.html +++ b/src/lib/base.html @@ -33,6 +33,7 @@ createdCallback: function() { Polymer.telemetry.instanceCount++; + this.isAttached = false; this.root = this; this._doBehavior('created'); // abstract this._initFeatures(); // abstract diff --git a/src/lib/dom-api-shady.html b/src/lib/dom-api-shady.html index 2e76eb5889..584d5bc6cc 100644 --- a/src/lib/dom-api-shady.html +++ b/src/lib/dom-api-shady.html @@ -15,6 +15,7 @@ var Settings = Polymer.Settings; var DomApi = Polymer.DomApi; + var dom = DomApi.factory; var TreeApi = Polymer.TreeApi; var getInnerHTML = Polymer.domInnerHTML.getInnerHTML; var CONTENT = DomApi.CONTENT; @@ -69,7 +70,7 @@ throw Error('The ref_node to be inserted before is not a child ' + 'of this node'); } - this._addLogicalInfo(node, this.node, ref_node); + TreeApi.Logical.recordInsertBefore(node, this.node, ref_node); } this._addNodeToHost(node); // if not distributing and not adding to host, do a fast path addition @@ -101,7 +102,7 @@ This method also performs dom composition. */ removeChild: function(node) { - if (DomApi.factory(node).parentNode !== this.node) { + if (dom(node).parentNode !== this.node) { console.warn('The node to be removed is not a child of this node', node); } @@ -201,9 +202,9 @@ var added; if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE && !node.__noContent) { - var c$ = DomApi.factory(node).querySelectorAll(CONTENT); + var c$ = dom(node).querySelectorAll(CONTENT); for (var i=0, n, np, na; (i's and their parents have logical dom info. for (var i=0, c; i < i$.length; i++) { c = i$[i]; TreeApi.Logical.saveChildNodes(c); - TreeApi.Logical.saveChildNodes(DomApi.factory(c).parentNode); + TreeApi.Logical.saveChildNodes(dom(c).parentNode); } }, @@ -248,9 +249,12 @@ _removeNodeFromParent: function(node) { // note: we may need to notify and not have logical info so fallback // to composed parentNode. + var parent = node.__parentNode || node.parentNode; + //var parent = dom(node).parentNode; + // TODO(sorvell): hasDomApi doesn't make sense now if (parent && DomApi.hasApi(parent)) { - DomApi.factory(parent).notifyObserver(); + dom(parent).notifyObserver(); } this._removeNodeFromHost(node, true); }, @@ -262,17 +266,18 @@ // to require distribution... both cases are handled here. var hostNeedsDist; var root; + // important that we want to do this only if the node has a logical parent var parent = node.__parentNode; if (parent) { // distribute node's parent iff needed - DomApi.factory(node)._distributeParent(); + dom(node)._distributeParent(); root = this._ownerShadyRootForNode(node); // remove node from root and distribute it iff needed if (root) { root.host._elementRemove(node); hostNeedsDist = this._removeDistributedChildren(root, node); } - this._removeLogicalInfo(node, parent); + TreeApi.Logical.recordRemoveChild(node, parent); } this._removeOwnerShadyRoot(node); if (root && hostNeedsDist) { @@ -290,7 +295,7 @@ for (var i=0; i ref_node - node.__previousSibling = ref_node ? ref_node.__previousSibling : - container.__lastChild; - if (node.__previousSibling) { - node.__previousSibling.__nextSibling = node; - } - node.__nextSibling = ref_node; - if (ref_node) { - ref_node.__previousSibling = node; - } - // update node <-> container - node.__parentNode = container; - if (ref_node && ref_node === container.__firstChild) { - container.__firstChild = node; - } else { - container.__lastChild = node; - if (!container.__firstChild) { - container.__firstChild = node; - } - } - // remove caching of childNodes - container.__childNodes = null; - }, - - // NOTE: in general, we expect contents of the lists here to be small-ish - // and therefore indexOf to be nbd. Other optimizations can be made - // for larger lists (linked list) - _removeLogicalInfo: function(node, container) { - if (node === container.__firstChild) { - container.__firstChild = node.__nextSibling; - } - if (node === container.__lastChild) { - container.__lastChild = node.__previousSibling; - } - var p = node.__previousSibling; - var n = node.__nextSibling; - if (p) { - p.__nextSibling = n; - } - if (n) { - n.__previousSibling = p; - } - node.__parentNode = node.__previousSibling = node.__nextSibling = null; - // remove caching of childNodes - container.__childNodes = null; - }, - _removeOwnerShadyRoot: function(node) { // optimization: only reset the tree if node is actually in a root if (this._hasCachedOwnerRoot(node)) { - var c$ = DomApi.factory(node).childNodes; + var c$ = dom(node).childNodes; for (var i=0, l=c$.length, n; (i ref_node + node.__previousSibling = ref_node ? ref_node.__previousSibling : + container.__lastChild; + if (node.__previousSibling) { + node.__previousSibling.__nextSibling = node; + } + node.__nextSibling = ref_node; + if (ref_node) { + ref_node.__previousSibling = node; + } + // update node <-> container + node.__parentNode = container; + if (ref_node && ref_node === container.__firstChild) { + container.__firstChild = node; + } else { + container.__lastChild = node; + if (!container.__firstChild) { + container.__firstChild = node; + } + } + // remove caching of childNodes + container.__childNodes = null; + }, + + recordRemoveChild: function(node, container) { + if (node === container.__firstChild) { + container.__firstChild = node.__nextSibling; + } + if (node === container.__lastChild) { + container.__lastChild = node.__previousSibling; + } + var p = node.__previousSibling; + var n = node.__nextSibling; + if (p) { + p.__nextSibling = n; + } + if (n) { + n.__previousSibling = p; + } + node.__parentNode = node.__previousSibling = node.__nextSibling = null; + // remove caching of childNodes + container.__childNodes = null; + }, } diff --git a/src/mini/ready.html b/src/mini/ready.html index 2807a5a8e0..13b1ebaa2f 100644 --- a/src/mini/ready.html +++ b/src/mini/ready.html @@ -69,6 +69,8 @@ if (host && host._clients) { host._clients.push(this); } + this._clients = null; + this._clientsReadied = false; }, // establish this element as the current hosting element (allows @@ -86,6 +88,7 @@ }, _tryReady: function() { + this._readied = false; if (this._canReady()) { this._ready(); } diff --git a/src/mini/shady.html b/src/mini/shady.html index b38d8ad9fb..4e7883ca0c 100644 --- a/src/mini/shady.html +++ b/src/mini/shady.html @@ -34,6 +34,22 @@ this._useContent = this._useContent || Boolean(this._template); }, + _setupShady: function() { + // object shaping... + this.shadyRoot = null; + if (!this.__domApi) { + this.__domApi = null; + } + if (!this._ownerShadyRoot) { + this._ownerShadyRoot = undefined; + } + // TODO(sorvell): these could be on the domApi object? + // there are a bunch of `__` properties that get put on the node + // from logicalizing. These could be on `__domApi`. Initializing + // them here is problematic because they may have been set prior + // to upgrading. + }, + // called as part of content initialization, prior to template stamping _poolContent: function() { if (this._useContent) { @@ -277,7 +293,7 @@ this._updateChildNodes(this, this._composeNode(this)); var p$ = this.shadyRoot._insertionPoints; for (var i=0, l=p$.length, p, parent; (i