Merge branch 'master' into style-fixes

This commit is contained in:
Steven Orvell 2016-02-05 17:17:37 -08:00
commit e2accaf1ef
9 changed files with 123 additions and 35 deletions

View File

@ -351,12 +351,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
// (properties) are case sensitive. Gambit is to map dash-case to
// camel-case: `foo-bar` becomes `fooBar`.
// Attribute bindings are excepted.
var propertyName = Polymer.CaseMap.dashToCamelCase(name);
if (kind === 'property') {
name = Polymer.CaseMap.dashToCamelCase(name);
name = propertyName;
}
return {
kind: kind,
name: name,
propertyName: propertyName,
parts: parts,
literal: literal,
isCompound: parts.length !== 1
@ -372,7 +374,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
Polymer.Annotations.findAnnotatedNode(root, annote.parent);
// unwind the stack, returning the indexed node at each level
if (parent) {
// note: marginally faster than indexing via childNodes
// note: marginally faster than indexing via childNodes
// (http://jsperf.com/childnodes-lookup)
for (var n=parent.firstChild, i=0; n; n=n.nextSibling) {
if (annote.index === i++) {

View File

@ -12,32 +12,24 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
Polymer.CaseMap = {
_caseMap: {},
_rx: {
dashToCamel: /-[a-z]/g,
camelToDash: /([A-Z])/g
},
dashToCamelCase: function(dash) {
var mapped = Polymer.CaseMap._caseMap[dash];
if (mapped) {
return mapped;
}
// TODO(sjmiles): is rejection test actually helping perf?
if (dash.indexOf('-') < 0) {
return Polymer.CaseMap._caseMap[dash] = dash;
}
return Polymer.CaseMap._caseMap[dash] = dash.replace(/-([a-z])/g,
function(m) {
return m[1].toUpperCase();
}
return this._caseMap[dash] || (
this._caseMap[dash] = dash.indexOf('-') < 0 ? dash : dash.replace(this._rx.dashToCamel,
function(m) {
return m[1].toUpperCase();
}
)
);
},
camelToDashCase: function(camel) {
var mapped = Polymer.CaseMap._caseMap[camel];
if (mapped) {
return mapped;
}
return Polymer.CaseMap._caseMap[camel] = camel.replace(/([a-z][A-Z])/g,
function (g) {
return g[0] + '-' + g[1].toLowerCase()
}
return this._caseMap[camel] || (
this._caseMap[camel] = camel.replace(this._rx.camelToDash, '-$1').toLowerCase()
);
}

View File

@ -136,15 +136,18 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
for (var i=0, l=fx.length, x; (i<l) && (x=fx[i]); i++) {
// TODO(kschaaf): compound bindings (as well as computed effects)
// are excluded from top-down configure for now; to be revisited
if (x.kind === 'annotation' &&
x.effect.kind !== 'attribute' &&
!x.isCompound) {
if (x.kind === 'annotation' && !x.isCompound) {
var node = this._nodes[x.effect.index];
var name = x.effect.propertyName;
// seeding configuration only
if (node._configValue) {
if (node._propertyEffects && node._propertyEffects[name]) {
var value = (p === x.effect.value) ? config[p] :
this._get(x.effect.value, config);
node._configValue(x.effect.name, value);
if (x.effect.kind == 'attribute') {
value = node.deserialize(value,
node._propertyInfo[name].type);
}
node._configValue(name, value);
}
}
}

View File

@ -148,6 +148,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
kind: note.kind,
index: index,
name: note.name,
propertyName: note.propertyName,
value: part.value,
isCompound: note.isCompound,
compoundIndex: part.compoundIndex,

View File

@ -19,6 +19,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
'unit/base.html',
'unit/micro.html',
'unit/unresolved.html',
'unit/case-map.html',
'unit/attributes.html',
'unit/dom-module.html',
'unit/dom-module-inline.html',

View File

@ -283,11 +283,7 @@ suite('hostAttributes', function() {
// applied to property with effect
assert.strictEqual(compose.$.basic.prop, 'compose');
assert.equal(compose.$.basic.propChangedCount, 1);
// Note: Attribute binding does not participate in efficient configuration
// per #3288. As such, a property bound with an attribute binding will
// see its default value first, then be overwritten when the attribute
// binding runs and re-deserializes to the property, hence 2 observer calls
assert.equal(compose.$.basic.attr1ChangedCount, 2);
assert.equal(compose.$.basic.attr1ChangedCount, 1);
assert.equal(compose.prop2, 'hi');
});

60
test/unit/case-map.html Normal file
View File

@ -0,0 +1,60 @@
<!doctype html>
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="utf-8">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script>
<link rel="import" href="../../src/polymer-lib.html">
<link rel="import" href="../../src/lib/case-map.html">
</head>
<body>
<script>
suite('case-map', function() {
var caseMap;
setup(function() {
caseMap = Polymer.CaseMap;
});
test('camelToDashCase converts to dashes', function() {
assert.equal(caseMap.camelToDashCase('camelCase'), 'camel-case');
assert.equal(caseMap.camelToDashCase('camelCCase'), 'camel-c-case');
});
test('camelToDashCase caches conversions', function() {
caseMap._caseMap['camelCase'] = 'some-other-camel-case';
assert.equal(caseMap.camelToDashCase('camelCase'), 'some-other-camel-case');
var result = caseMap.camelToDashCase('camelCCase');
assert.equal(Polymer.CaseMap._caseMap['camelCCase'], result);
});
test('dashToCamelCase converts to camelCase', function() {
assert.equal(caseMap.dashToCamelCase('camel-case'), 'camelCase');
assert.equal(caseMap.dashToCamelCase('camel-c-case'), 'camelCCase');
});
test('dashToCamelCase caches conversions', function() {
caseMap._caseMap['camel-case'] = 'someOtherCamelCase';
assert.equal(caseMap.dashToCamelCase('camel-case'), 'someOtherCamelCase');
var result = caseMap.dashToCamelCase('camel-c-case');
assert.equal(Polymer.CaseMap._caseMap['camel-c-case'], result);
});
test('camelToDashCase and dashToCamelCase reverse the other function', function() {
var camelCase = caseMap.dashToCamelCase('camel-c-case');
assert.equal(caseMap.camelToDashCase(camelCase), 'camel-c-case');
});
});
</script>

View File

@ -119,7 +119,21 @@
},
stomp: {
value: 5
},
attrDash: {
observer: 'attrDashChanged',
value: 'default'
},
attrNumber: {
type: Number,
observer: 'attrNumberChanged',
value: 0
}
},
created: function() {
this.attrDashChanged = sinon.spy();
this.attrNumberChanged = sinon.spy();
}
});
@ -128,7 +142,7 @@
<dom-module id="x-configure-host">
<template>
<x-configure-child id="child" content="{{content}}" object="{{object.goo}}" attr$="{{attrValue}}"></x-configure-child>
<x-configure-child id="child" content="{{content}}" object="{{object.goo}}" attr$="{{attrValue}}" attr-dash$="{{attrValue}}" attr-number$="{{attrNumber}}"></x-configure-child>
</template>
<script>
Polymer({
@ -158,7 +172,10 @@
value: 5
},
attrValue: {
value: 'attrValue'
value: 'attrValue',
},
attrNumber: {
value: '42'
}
}

View File

@ -81,12 +81,28 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
assert.equal(e.readOnly, 'default');
});
test('properties for attribute bindings not configured', function() {
test('attribute bindings to properties without effects not configured', function() {
var e = document.querySelector('x-configure-host');
assert.equal(e.$.child.getAttribute('attr'), 'attrValue');
assert.equal(e.$.child.attr, undefined);
});
test('attribute bindings to properties with effects configured', function() {
var e = document.createElement('x-configure-host');
assert.equal(e.$.child.getAttribute('attr-dash'), 'attrValue');
assert.notProperty(e.$.child, 'attr-dash');
assert.equal(e.$.child.attrDash, 'attrValue');
assert.isTrue(e.$.child.attrDashChanged.calledOnce);
assert.equal(e.$.child.attrDashChanged.getCall(0).args[0], 'attrValue');
assert.equal(e.$.child.getAttribute('attr-number'), '42');
assert.notProperty(e.$.child, 'attr-number');
assert.strictEqual(e.$.child.attrNumber, 42);
assert.isTrue(e.$.child.attrNumberChanged.calledOnce);
assert.equal(e.$.child.attrNumberChanged.getCall(0).args[0], 42);
});
});
</script>