address feedback

This commit is contained in:
Daniel Freedman
2017-01-17 16:27:24 -08:00
parent 80d3fca5fb
commit af1afd75f2
4 changed files with 42 additions and 24 deletions
+2 -5
View File
@@ -125,9 +125,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
if (config) {
this._finalizeConfig(config);
}
let template = this.template;
if (template) {
this._finalizeTemplate(template.cloneNode(true));
if (this.template) {
this._finalizeTemplate(this.template.cloneNode(true));
}
}
}
@@ -152,8 +151,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
static get template() {
if (!this.hasOwnProperty(goog.reflect.objectProperty('_template', this))) {
// TODO(sorvell): support more ways to acquire template.
// this requires `is` on constructor...
this._template = this._getTemplate() ||
// note: implemented so a subclass can retrieve the super
// template; call the super impl this way so that `this` points
+1 -1
View File
@@ -695,7 +695,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* notification is generated**.
*
* @method arrayDelete
* @param {string | Array<number|string>} arrayOrPath Path to array from which to remove the item
* @param {string | !Array<number|string>} arrayOrPath Path to array from which to remove the item
* (or the array itself).
* @param {*} item Item to remove.
* @return {Array} Array containing item removed.
+12 -8
View File
@@ -1385,7 +1385,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* `path` can be a path string or array of path parts as accepted by the
* public API.
*
* @param {string | Array<number|string>} path Path to set
* @param {string | !Array<number|string>} path Path to set
* @param {*} value Value to set
* @param {boolean=} fromPath If the value being set was from a path; in
* this case the value was shared, so no dirty check is performed.
@@ -1413,14 +1413,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
// already dirty checked at the point of entry and the underlying
// object has already been updated
let old = Polymer.Path.get(this, path);
path = Polymer.Path.set(this, path, value);
path = /** @type {string} */(Polymer.Path.set(this, path, value));
// Use property-accessor's simpler dirty check
if (!super._shouldPropertyChange(path, value, old)) {
return undefined;
}
}
if (hasEffect) {
return path;
return /** @type {string} */(path);
} else {
return undefined;
}
@@ -1497,6 +1497,10 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* (`value === old`) or based on type.
*
* @override
* @param {string} property
* @param {*} value
* @param {*} old
* @return {boolean}
*/
_shouldPropertyChange(property, value, old) {
if (typeof value == 'object') {
@@ -1699,8 +1703,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* are routed to the other.
*
* @method linkPaths
* @param {string | Array<string|number>} to Target path to link.
* @param {string | Array<string|number>} from Source path to link.
* @param {string | !Array<string|number>} to Target path to link.
* @param {string | !Array<string|number>} from Source path to link.
* @public
*/
linkPaths(to, from) {
@@ -1717,7 +1721,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* linking the paths.
*
* @method unlinkPaths
* @param {string | Array<string|number>} path Target path to unlink.
* @param {string | !Array<string|number>} path Target path to unlink.
* @public
*/
unlinkPaths(path) {
@@ -1770,7 +1774,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* paths).
*
* @method get
* @param {(string|Array<(string|number)>)} path Path to the value
* @param {(string|!Array<(string|number)>)} path Path to the value
* to read. The path may be specified as a string (e.g. `foo.bar.baz`)
* or an array of path parts (e.g. `['foo.bar', 'baz']`). Note that
* bracketed expressions are not supported; string-based path parts
@@ -1795,7 +1799,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* dereferencing undefined paths).
*
* @method set
* @param {(string|Array<(string|number)>)} path Path to the value
* @param {(string|!Array<(string|number)>)} path Path to the value
* to write. The path may be specified as a string (e.g. `'foo.bar.baz'`)
* or an array of path parts (e.g. `['foo.bar', 'baz']`). Note that
* bracketed expressions are not supported; string-based path parts
+27 -10
View File
@@ -56,12 +56,11 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
},
/**
* Converts array-based paths to flattened path, optionally split into array
* @param {string | Array<string>} path
* @param {boolean=} split
* @return {string | Array<string>}
* Converts array-based paths to flattened path
* @param {string | !Array<string|number>} path
* @return {string}
*/
normalize: function(path, split) {
normalize: function(path) {
if (Array.isArray(path)) {
var parts = [];
for (var i=0; i<path.length; i++) {
@@ -70,21 +69,33 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
parts.push(args[j]);
}
}
return split ? parts : parts.join('.');
return parts.join('.');
} else {
return split ? path.toString().split('.') : path;
return path;
}
},
/**
* Split a path into an array
* @param {string | !Array<string|number>} path
* @return {!Array<string>}
*/
split: function(path) {
if (Array.isArray(path)) {
return this.normalize(path).split('.');
}
return path.toString().split('.');
},
/**
* @param {Object} root
* @param {string | Array<string|number>} path
* @param {string | !Array<string|number>} path
* @param {Object=} info
* @return {*}
*/
get: function(root, path, info) {
var prop = root;
var parts = this.normalize(path, true);
var parts = this.split(path);
// Loop over path parts[0..n-1] and dereference
for (var i=0; i<parts.length; i++) {
if (!prop) {
@@ -99,9 +110,15 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
return prop;
},
/**
* @param {Object} root
* @param {string | !Array<string|number>} path
* @param {*} value
* @return {string | undefined}
*/
set: function(root, path, value) {
var prop = root;
var parts = this.normalize(path, true);
var parts = this.split(path);
var last = parts[parts.length-1];
if (parts.length > 1) {
// Loop over path parts[0..n-2] and dereference