Skip to content
This repository has been archived by the owner on Sep 20, 2019. It is now read-only.

Cooperate with ShadyCSS to appropriately scope changes to class/className #54

Merged
merged 4 commits into from
Nov 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 30 additions & 34 deletions shadydom.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shadydom.min.js.map

Large diffs are not rendered by default.

50 changes: 17 additions & 33 deletions src/element-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let mixinImpl = {
let ownerRoot = this.ownerShadyRootForNode(container);
if (ownerRoot) {
// optimization: special insertion point tracking
if (node.__noInsertionPoint) {
if (node.__noInsertionPoint && ownerRoot._clean) {
ownerRoot._skipUpdateInsertionPoints = true;
}
// note: we always need to see if an insertion point is added
Expand All @@ -33,7 +33,6 @@ let mixinImpl = {
if (ipAdded) {
ownerRoot._skipUpdateInsertionPoints = false;
}
this._addedNode(node, ownerRoot);
}
if (tree.Logical.hasChildNodes(container)) {
tree.Logical.recordInsertBefore(node, container, ref_node);
Expand Down Expand Up @@ -66,9 +65,6 @@ let mixinImpl = {
}
}
this._removeOwnerShadyRoot(node);
if (ownerRoot) {
this._removedNode(node, ownerRoot);
}
return distributed;
},

Expand Down Expand Up @@ -200,23 +196,6 @@ let mixinImpl = {
node.shadyRoot.hasInsertionPoint();
},

// TODO(sorvell): needed for style scoping, use MO?
_addedNode() {},
_removedNode() {},
/*
_addedNode(node, root) {
// if (ShadyDOM.addedNode) {
// ShadyDOM.addedNode(node, root);
// }
},

_removedNode(node, root) {
if (ShadyDOM.removedNode) {
ShadyDOM.removedNode(node, root);
}
},
*/

_removeDistributedChildren(root, container) {
let hostNeedsDist;
let ip$ = root._insertionPoints;
Expand Down Expand Up @@ -286,10 +265,11 @@ let mixinImpl = {
},

maybeDistributeAttributeChange(node, name) {
let distribute = (node.localName === 'slot' && name === 'name');
if (distribute) {
let root = this.getRootNode(node);
if (root.update) {
if (name === 'slot') {
this.maybeDistributeParent(node);
} else if (node.localName === 'slot' && name === 'name') {
let root = this.ownerShadyRootForNode(node);
if (root) {
root.update();
}
}
Expand Down Expand Up @@ -371,6 +351,14 @@ let nativeImportNode = Document.prototype.importNode;
let nativeSetAttribute = Element.prototype.setAttribute;
let nativeRemoveAttribute = Element.prototype.removeAttribute;

export let setAttribute = function(attr, value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not take the node as the first argument?
setAttribute(node, attr, value) would remove the indirection used later.

if (window.ShadyCSS && attr === 'class') {
window.ShadyCSS.setElementClass(this, value);
} else {
nativeSetAttribute.call(this, attr, value);
}
}

let NodeMixin = {};

Object.defineProperties(NodeMixin, {
Expand Down Expand Up @@ -656,17 +644,13 @@ let ElementMixin = {


setAttribute(name, value) {
nativeSetAttribute.call(this, name, value);
if (!mixinImpl.maybeDistributeParent(this)) {
mixinImpl.maybeDistributeAttributeChange(this, name);
}
setAttribute.call(this, name, value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be setAttribute(this, name, value)

mixinImpl.maybeDistributeAttributeChange(this, name);
},

removeAttribute(name) {
nativeRemoveAttribute.call(this, name);
if (!mixinImpl.maybeDistributeParent(this)) {
mixinImpl.maybeDistributeAttributeChange(this, name);
}
mixinImpl.maybeDistributeAttributeChange(this, name);
}

};
Expand Down
16 changes: 14 additions & 2 deletions src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
import * as utils from './utils'
import {ShadyRoot, flush, enqueue} from './shady'
import * as patch from './patch'
import {getRootNode, filterMutations, observeChildren, unobserveChildren}
from './element-mixin'
import {getRootNode, filterMutations, observeChildren, unobserveChildren,
setAttribute} from './element-mixin'
import * as events from './event-mixin'
import {tree, getNativeProperty} from './tree'

Expand Down Expand Up @@ -101,6 +101,18 @@ if (utils.settings.inUse) {
configurable: true
});

Element.prototype.setAttribute = setAttribute;

Object.defineProperty(Element.prototype, 'className', {
get() {
return this.getAttribute('class');
},
set(value) {
this.setAttribute('class', value);
},
configurable: true
});

// TODO(sorvell): super experimental auto patching of document fragment
// via appendChild. This either needs to be expanded or contracted.
// DocumentFragment.prototype.appendChild = function(node) {
Expand Down