Skip to content

Commit

Permalink
Merge pull request #1739 from Polymer/1733-kschaaf
Browse files Browse the repository at this point in the history
Make __styleScoped a one-time optimization. Fixes #1733
  • Loading branch information
Steve Orvell committed Jun 4, 2015
2 parents 78cca70 + 8257a0f commit 729784b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/standard/styling.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,14 @@
// instance-y
// add scoping class whenever an element is added to localDOM
_elementAdd: function(node) {
if (this._encapsulateStyle && !node.__styleScoped) {
styleTransformer.dom(node, this.is, this._scopeCssViaAttr);
if (this._encapsulateStyle) {
// If __styleScoped is set, this is a one-time optimization to
// avoid scoping pre-scoped document fragments
if (node.__styleScoped) {
node.__styleScoped = false;
} else {
styleTransformer.dom(node, this.is, this._scopeCssViaAttr);
}
}
},

Expand Down
19 changes: 19 additions & 0 deletions test/unit/dom-repeat-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,22 @@
}
});
</script>


<dom-module id="x-simple-repeat">
<template>
<template is="dom-repeat" items="{{items}}">
<x-foo itema-prop="{{item.prop}}"></x-foo>
</template>
</template>
<script>
Polymer({
is: 'x-simple-repeat',
properties: {
items: {
value: window.data
}
}
});
</script>
</dom-module>
35 changes: 35 additions & 0 deletions test/unit/dom-repeat.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
</head>
<body>

<h4>x-simple-repeat</h4>
<x-simple-repeat id="simple"></x-simple-repeat>

<h4>x-nested-repeat-configured</h4>
<x-nested-repeat-configured id="configured"></x-nested-repeat-configured>

Expand Down Expand Up @@ -1267,6 +1270,38 @@ <h4>inDocumentRepeater</h4>
assert.equal(stamped2[15].indexc, 0);
});

test('css scoping retained when re-ordering', function(done) {
if (!Polymer.Settings.useShadow) {
// Confirm initial scoping
var stamped = Polymer.dom(simple.root).querySelectorAll('*:not(template)');
assert.equal(stamped[0].itemaProp, 'prop-1');
assert(stamped[0].classList.contains('x-simple-repeat'), 'expected scoping');
assert.equal(stamped.length, 3, 'total stamped count incorrect');
var row = stamped[0];
// Move
removed = simple.splice('items', 0, 1);
simple.splice('items', 1, 0, removed[0]);
setTimeout(function() {
stamped = Polymer.dom(simple.root).querySelectorAll('*:not(template)');
assert.equal(stamped.length, 3, 'total stamped count incorrect');
assert.equal(row, stamped[1]);
assert.equal(stamped[1].itemaProp, 'prop-1');
assert(stamped[1].classList.contains('x-simple-repeat'), 'expected scoping');
// Revert
removed = simple.splice('items', 1, 1);
simple.splice('items', 0, 0, removed[0]);
setTimeout(function() {
stamped = Polymer.dom(simple.root).querySelectorAll('*:not(template)');
assert.equal(stamped.length, 3, 'total stamped count incorrect');
assert.equal(row, stamped[0]);
assert.equal(stamped[0].itemaProp, 'prop-1');
assert(stamped[0].classList.contains('x-simple-repeat'), 'expected scoping');
done();
});
});
}
});

});

suite('reacting to changes, array sort with filter', function() {
Expand Down

0 comments on commit 729784b

Please sign in to comment.