Skip to content

Commit

Permalink
Merge branch 'master' into eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreedm committed Feb 8, 2016
2 parents acdfc1e + 5215695 commit 10d2004
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 34 deletions.
4 changes: 3 additions & 1 deletion src/lib/annotations/annotations.html
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,14 @@
// (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
Expand Down
32 changes: 12 additions & 20 deletions src/lib/case-map.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,24 @@
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()
);
}

Expand Down
13 changes: 8 additions & 5 deletions src/standard/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,18 @@
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);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/standard/effectBuilder.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
kind: note.kind,
index: index,
name: note.name,
propertyName: note.propertyName,
value: part.value,
isCompound: note.isCompound,
compoundIndex: part.compoundIndex,
Expand Down
1 change: 1 addition & 0 deletions test/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'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',
Expand Down
6 changes: 1 addition & 5 deletions test/unit/attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,7 @@
// 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');
});

Expand Down
60 changes: 60 additions & 0 deletions test/unit/case-map.html
Original file line number Diff line number Diff line change
@@ -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>
21 changes: 19 additions & 2 deletions test/unit/configure-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

});
Expand All @@ -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({
Expand Down Expand Up @@ -158,7 +172,10 @@
value: 5
},
attrValue: {
value: 'attrValue'
value: 'attrValue',
},
attrNumber: {
value: '42'
}
}

Expand Down
18 changes: 17 additions & 1 deletion test/unit/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,28 @@
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>
Expand Down

0 comments on commit 10d2004

Please sign in to comment.