From aaf2d5e95a1587d5fb671a09e4016913352c095e Mon Sep 17 00:00:00 2001 From: "Scott J. Miles" Date: Mon, 9 Feb 2015 18:07:42 -0800 Subject: [PATCH 1/7] make _notifyPath dash-case root property name when firing EVENT_PATH_CHANGED event --- src/features/standard/notify-path.html | 93 ++++++++++++++++---------- 1 file changed, 57 insertions(+), 36 deletions(-) diff --git a/src/features/standard/notify-path.html b/src/features/standard/notify-path.html index 3ec2a67188..7db27ae226 100644 --- a/src/features/standard/notify-path.html +++ b/src/features/standard/notify-path.html @@ -58,7 +58,7 @@ * @class data feature: path notification */ -using('Base', function(Base) { +using(['Base', 'Annotations'], function(Base, Annotations) { Base.addFeature({ /** @@ -105,7 +105,7 @@ } // TODO(kschaaf): want dirty-check here? // if (prop[last] !== value) { - prop[last] = value; + prop[last] = value; this.notifyPath(path, value); // } } else { @@ -139,64 +139,85 @@ // effectors as new paths are notified for performance, since it involves // a fair amount of runtime lookup _pathEffector: function(path, value) { + // get root property var model = modelForPath(path); + // search property effects of the root property for 'annotation' effects var fx$ = this._propertyEffects[model]; - fx$.forEach(function(x) { - if (x.kind === 'annotation') { - var effect = x.effect; - var n = this._nodeForBinding(effect); + fx$.forEach(function(fx) { + if (fx.kind === 'annotation') { + // locate the bound node + var n = this._nodeForBinding(fx.effect); if (n) { - if (effect.value === path || effect.value.indexOf(path + '.') === 0) { - var v = (effect.value === path) ? value : this.getPathValue(effect.value); - v = effect.negate ? !v : v; - if (effect.kind == 'attribute') { - this.serializeValueToAttribute(v, effect.name, n); - } else { // property || text - n[effect.name || 'textContent'] = v; - } - // path == item.stuff.count - // value == item.stuff - // name == zizz - // calls effect n.notifyPath for zizz.count - } else if ((path.indexOf(effect.value + '.') === 0) && n.notifyPath) { - var p = this._fixPath(effect.name , effect.value, path); - n.notifyPath(p, value, true); - } + // perform the effect + this._performAnnotationPathEffect(n, path, value, fx.effect); } } }, this); + // iterate and perform _pathEffects matching path if (this._pathEffects) { - this._pathEffects.forEach(function(x) { - if (x.path == path || (x.match && path.indexOf(x.path) === 0)) { - var fn = this[x.method]; - if (fn) { - // TODO(kschaaf): sending null for old; no good way to get it? - fn.call(this, value, null, path); - } - } + this._pathEffects.forEach(function(fx) { + this._performPathEffect(path, value, fx); }, this); } }, + _nodeForBinding: function(info) { + return info.id ? this.$[info.id] : this._nodes[info.index]; + }, + + _performAnnotationPathEffect: function(node, path, value, effect) { + if (effect.value === path || effect.value.indexOf(path + '.') === 0) { + var v = (effect.value === path) ? + value : this.getPathValue(effect.value); + v = effect.negate ? !v : v; + if (effect.kind == 'attribute') { + this.serializeValueToAttribute(v, effect.name, node); + } else { // property || text + node[effect.name || 'textContent'] = v; + } + } else + // path == item.stuff.count + // value == item.stuff + // name == zizz + // calls effect node.notifyPath for zizz.count + if ((path.indexOf(effect.value + '.') === 0) && node.notifyPath) { + var p = this._fixPath(effect.name , effect.value, path); + node.notifyPath(p, value, true); + } + }, + + _performPathEffect: function(path, value, fx) { + if (fx.path == path || (fx.match && path.indexOf(fx.path) === 0)) { + var fn = this[fx.method]; + if (fn) { + // TODO(kschaaf): sending null for old; no good way to get it? + fn.call(this, value, null, path); + } + } + }, + _fixPath: function(property, root, path) { return property + path.slice(root.length); }, _notifyPath: function(path, value) { - var event = modelForPath(path) + EVENT_PATH_CHANGED; - this.fire(event, { path: path, value: value }, null, false); - }, - - _nodeForBinding: function(info) { - return info.id ? this.$[info.id] : this._nodes[info.index]; + var rootName = modelForPath(path); + var dashCaseName = Annotations.camelToDashCase(rootName); + var eventName = dashCaseName + EVENT_PATH_CHANGED; + this.fire(eventName, { + path: path, + value: value + }, null, false); } }); + // TODO(sjmiles): needs a home function modelForPath(path) { return path.split('.').shift(); } + // TODO(sjmiles): should be imported from elsewhere var EVENT_CHANGED = '-changed'; var EVENT_PATH_CHANGED = '-path' + EVENT_CHANGED; From a9d714a3294414b49e978634db6ad7577428c134 Mon Sep 17 00:00:00 2001 From: "Scott J. Miles" Date: Mon, 9 Feb 2015 18:11:45 -0800 Subject: [PATCH 2/7] add dash-case/camelCase transform functions, convert annotated attribute names from dash to camel --- src/lib/annotations/annotations.html | 56 ++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/src/lib/annotations/annotations.html b/src/lib/annotations/annotations.html index 5b38f6c7b4..4744ff1f6a 100644 --- a/src/lib/annotations/annotations.html +++ b/src/lib/annotations/annotations.html @@ -71,6 +71,8 @@ // preprocess-time + // construct and return a list of annotation records + // by scanning `template`'s content parseAnnotations: function(template) { var list = []; var content = template._content || template.content; @@ -78,12 +80,16 @@ return list; }, + // add annotations gleaned from subtree at `node` to `list` _parseNodeAnnotations: function(node, list) { return node.nodeType === Node.TEXT_NODE ? this._parseTextNodeAnnotation(node, list) : + // TODO(sjmiles): are there other nodes we may encounter + // that are not TEXT_NODE but also not ELEMENT? this._parseElementAnnotations(node, list); }, + // add annotations gleaned from TextNode `node` to `list` _parseTextNodeAnnotation: function(node, list) { var v = node.textContent, escape = v.slice(0, 2); if (escape === '{{' || escape === '[[') { @@ -102,14 +108,17 @@ } }, - _parseElementAnnotations: function(node, list) { + // add annotations gleaned from Element `node` to `list` + _parseElementAnnotations: function(element, list) { var annote = { bindings: [], events: [] }; - this._parseChildNodesAnnotations(node, annote, list); - if (node.attributes) { - this._parseNodeAttributeAnnotations(node, annote, list); + this._parseChildNodesAnnotations(element, annote, list); + // TODO(sjmiles): is this for non-ELEMENT nodes? If so, we should + // change the contract of this method, or filter these out above. + if (element.attributes) { + this._parseNodeAttributeAnnotations(element, annote, list); } if (annote.bindings.length || annote.events.length || annote.id) { list.push(annote); @@ -117,6 +126,8 @@ return annote; }, + // add annotations gleaned from children of `root` to `list`, `root`'s + // `annote` is supplied as it is the annote.parent of added annotations _parseChildNodesAnnotations: function(root, annote, list) { if (root.firstChild) { for (var i=0, node=root.firstChild; node; node=node.nextSibling, i++){ @@ -146,6 +157,9 @@ } }, + // add annotation data from attributes to the `annotation` for node `node` + // TODO(sjmiles): the distinction between an `annotation` and + // `annotation data` is not as clear as it could be _parseNodeAttributeAnnotations: function(node, annotation) { for (var i=0, a; (a=node.attributes[i]); i++) { var n = a.name, v = a.value; @@ -173,6 +187,7 @@ } }, + // construct annotation data from a generic attribute, or undefined _parseNodeAttributeAnnotation: function(node, n, v) { var mode = '', escape = v.slice(0, 2), name = n; if (escape === '{{' || escape === '[[') { @@ -186,15 +201,22 @@ not = true; } // Attribute or property - var attr = false; + var kind = 'property'; if (n[n.length-1] == '$') { name = n.slice(0, -1); - attr = true; + kind = 'attribute'; } // Remove annotation node.removeAttribute(n); + // Case hackery: attributes are lower-case, but bind targets + // (properties) are case sensitive. Gambit is to map dash-case to + // camel-case: `foo-bar` becomes `fooBar`. + // Attribute bindings are excepted. + if (kind === 'property') { + name = Annotations.dashToCamelCase(name); + } return { - kind: attr ? 'attribute' : 'property', + kind: kind, mode: mode, name: name, value: v, @@ -203,6 +225,26 @@ } }, + dashToCamelCase: function(dash) { + // TODO(sjmiles): is rejection test actually helping perf? + if (dash.indexOf('-') < 0) { + return dash; + } + return dash.replace(/-([a-z])/g, + function(m) { + return m[1].toUpperCase(); + } + ); + }, + + camelToDashCase: function(camel) { + return camel.replace(/([a-z][A-Z])/g, + function (g) { + return g[0] + '-' + g[1].toLowerCase() + } + ); + }, + // instance-time _localSubTree: function(node, host) { From 5e6e675060c116e71f0374340e5f770bb5342e82 Mon Sep 17 00:00:00 2001 From: "Scott J. Miles" Date: Mon, 9 Feb 2015 18:12:43 -0800 Subject: [PATCH 3/7] make bind-effects dash-case aware --- src/lib/bind/bind-effects.html | 53 ++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/src/lib/bind/bind-effects.html b/src/lib/bind/bind-effects.html index af853ecb5e..c037ea2230 100644 --- a/src/lib/bind/bind-effects.html +++ b/src/lib/bind/bind-effects.html @@ -9,7 +9,7 @@ --> diff --git a/test/unit/notify-path.html b/test/unit/notify-path.html index 4f805c7a25..d616106e7a 100644 --- a/test/unit/notify-path.html +++ b/test/unit/notify-path.html @@ -56,14 +56,14 @@ assert.equal(changed[5], true); assert.equal(changed[6], true); assert.equal(changed[7], true); - assert.equal(el.$.basic.notifyingvalue, 42); + assert.equal(el.$.basic.notifyingValue, 42); assert.equal(el.$.compose.obj, nested.obj); - assert.equal(el.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic2.notifyingvalue, 42); + assert.equal(el.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.compose.$.basic2.notifyingValue, 42); assert.equal(el.$.forward.obj, nested.obj); assert.equal(el.$.forward.$.compose.obj, nested.obj); - assert.equal(el.$.forward.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic2.notifyingvalue, 42); + assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42); assert.equal(el.$.basic.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42'); @@ -86,7 +86,7 @@ el.$.compose.objValueChanged = function() { changed[4] = true; }; el.$.forward.objSubpathChanged = function() { changed[5] = true; }; el.$.forward.objValueChanged = function() { changed[6] = true; }; - el.$.basic.notifyingvalue = 42; + el.$.basic.notifyingValue = 42; assert.equal(changed[0], true); assert.equal(changed[1], true); assert.equal(changed[2], true); @@ -94,11 +94,11 @@ assert.equal(changed[4], true); assert.equal(changed[5], true); assert.equal(changed[6], true); - assert.equal(el.$.basic.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic2.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic2.notifyingvalue, 42); + assert.equal(el.$.basic.notifyingValue, 42); + assert.equal(el.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.compose.$.basic2.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42); assert.equal(el.$.basic.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42'); @@ -121,7 +121,7 @@ el.$.compose.objValueChanged = function() { changed[4] = true; }; el.$.forward.objSubpathChanged = function() { changed[5] = true; }; el.$.forward.objValueChanged = function() { changed[6] = true; }; - el.$.compose.$.basic1.notifyingvalue = 42; + el.$.compose.$.basic1.notifyingValue = 42; assert.equal(changed[0], true); assert.equal(changed[1], true); assert.equal(changed[2], true); @@ -129,11 +129,11 @@ assert.equal(changed[4], true); assert.equal(changed[5], true); assert.equal(changed[6], true); - assert.equal(el.$.basic.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic2.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic2.notifyingvalue, 42); + assert.equal(el.$.basic.notifyingValue, 42); + assert.equal(el.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.compose.$.basic2.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42); assert.equal(el.$.basic.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42'); @@ -156,7 +156,7 @@ el.$.compose.objValueChanged = function() { changed[4] = true; }; el.$.forward.objSubpathChanged = function() { changed[5] = true; }; el.$.forward.objValueChanged = function() { changed[6] = true; }; - el.$.forward.$.compose.$.basic1.notifyingvalue = 42; + el.$.forward.$.compose.$.basic1.notifyingValue = 42; assert.equal(changed[0], true); assert.equal(changed[1], true); assert.equal(changed[2], true); @@ -164,11 +164,11 @@ assert.equal(changed[4], true); assert.equal(changed[5], true); assert.equal(changed[6], true); - assert.equal(el.$.basic.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic2.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic2.notifyingvalue, 42); + assert.equal(el.$.basic.notifyingValue, 42); + assert.equal(el.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.compose.$.basic2.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42); assert.equal(el.$.basic.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42'); @@ -199,11 +199,11 @@ assert.equal(changed[4], true); assert.equal(changed[5], true); assert.equal(changed[6], true); - assert.equal(el.$.basic.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic2.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic2.notifyingvalue, 42); + assert.equal(el.$.basic.notifyingValue, 42); + assert.equal(el.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.compose.$.basic2.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42); assert.equal(el.$.basic.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42'); @@ -234,11 +234,11 @@ assert.equal(changed[4], true); assert.equal(changed[5], true); assert.equal(changed[6], true); - assert.equal(el.$.basic.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic2.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic2.notifyingvalue, 42); + assert.equal(el.$.basic.notifyingValue, 42); + assert.equal(el.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.compose.$.basic2.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42); assert.equal(el.$.basic.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42'); @@ -269,11 +269,11 @@ assert.equal(changed[4], true); assert.equal(changed[5], true); assert.equal(changed[6], true); - assert.equal(el.$.basic.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic2.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic2.notifyingvalue, 42); + assert.equal(el.$.basic.notifyingValue, 42); + assert.equal(el.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.compose.$.basic2.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42); assert.equal(el.$.basic.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42'); @@ -304,11 +304,11 @@ assert.equal(changed[4], true); assert.equal(changed[5], true); assert.equal(changed[6], true); - assert.equal(el.$.basic.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic2.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic2.notifyingvalue, 42); + assert.equal(el.$.basic.notifyingValue, 42); + assert.equal(el.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.compose.$.basic2.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42); assert.equal(el.$.basic.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42'); @@ -343,11 +343,11 @@ assert.equal(changed[5], true); assert.equal(changed[6], true); assert.equal(changed[7], true); - assert.equal(el.$.basic.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic2.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic2.notifyingvalue, 42); + assert.equal(el.$.basic.notifyingValue, 42); + assert.equal(el.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.compose.$.basic2.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42); assert.equal(el.$.basic.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42'); @@ -382,11 +382,11 @@ assert.equal(changed[5], true); assert.equal(changed[6], true); assert.equal(changed[7], true); - assert.equal(el.$.basic.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic2.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic2.notifyingvalue, 42); + assert.equal(el.$.basic.notifyingValue, 42); + assert.equal(el.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.compose.$.basic2.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42); assert.equal(el.$.basic.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42'); @@ -421,11 +421,11 @@ assert.equal(changed[5], true); assert.equal(changed[6], true); assert.equal(changed[7], true); - assert.equal(el.$.basic.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.compose.$.basic2.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic1.notifyingvalue, 42); - assert.equal(el.$.forward.$.compose.$.basic2.notifyingvalue, 42); + assert.equal(el.$.basic.notifyingValue, 42); + assert.equal(el.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.compose.$.basic2.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, 42); + assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, 42); assert.equal(el.$.basic.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic1.getAttribute('attrvalue'), '42'); assert.equal(el.$.compose.$.basic2.getAttribute('attrvalue'), '42'); @@ -440,13 +440,13 @@ } }; el.nested = nested; - assert.equal(el.$.basic.notifyingvalue, false); - assert.equal(el.$.compose.$.basic1.notifyingvalue, false); - assert.equal(el.$.compose.$.basic2.notifyingvalue, false); - assert.equal(el.$.compose.$.basic3.notifyingvalue, true); - assert.equal(el.$.forward.$.compose.$.basic1.notifyingvalue, false); - assert.equal(el.$.forward.$.compose.$.basic2.notifyingvalue, false); - assert.equal(el.$.forward.$.compose.$.basic3.notifyingvalue, true); + assert.equal(el.$.basic.notifyingValue, false); + assert.equal(el.$.compose.$.basic1.notifyingValue, false); + assert.equal(el.$.compose.$.basic2.notifyingValue, false); + assert.equal(el.$.compose.$.basic3.notifyingValue, true); + assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, false); + assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, false); + assert.equal(el.$.forward.$.compose.$.basic3.notifyingValue, true); assert.equal(el.$.basic.hasAttribute('attrvalue'), false); assert.equal(el.$.compose.$.basic1.hasAttribute('attrvalue'), false); assert.equal(el.$.compose.$.basic2.hasAttribute('attrvalue'), false); @@ -455,14 +455,14 @@ assert.equal(el.$.forward.$.compose.$.basic2.hasAttribute('attrvalue'), false); assert.equal(el.$.forward.$.compose.$.basic3.hasAttribute('attrvalue'), true); - el.$.basic.notifyingvalue = true; - assert.equal(el.$.basic.notifyingvalue, true); - assert.equal(el.$.compose.$.basic1.notifyingvalue, true); - assert.equal(el.$.compose.$.basic2.notifyingvalue, true); - assert.equal(el.$.compose.$.basic3.notifyingvalue, false); - assert.equal(el.$.forward.$.compose.$.basic1.notifyingvalue, true); - assert.equal(el.$.forward.$.compose.$.basic2.notifyingvalue, true); - assert.equal(el.$.forward.$.compose.$.basic3.notifyingvalue, false); + el.$.basic.notifyingValue = true; + assert.equal(el.$.basic.notifyingValue, true); + assert.equal(el.$.compose.$.basic1.notifyingValue, true); + assert.equal(el.$.compose.$.basic2.notifyingValue, true); + assert.equal(el.$.compose.$.basic3.notifyingValue, false); + assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, true); + assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, true); + assert.equal(el.$.forward.$.compose.$.basic3.notifyingValue, false); assert.equal(el.$.basic.hasAttribute('attrvalue'), true); assert.equal(el.$.compose.$.basic1.hasAttribute('attrvalue'), true); assert.equal(el.$.compose.$.basic2.hasAttribute('attrvalue'), true); @@ -471,14 +471,14 @@ assert.equal(el.$.forward.$.compose.$.basic2.hasAttribute('attrvalue'), true); assert.equal(el.$.forward.$.compose.$.basic3.hasAttribute('attrvalue'), false); - el.$.forward.$.compose.$.basic1.notifyingvalue = false; - assert.equal(el.$.basic.notifyingvalue, false); - assert.equal(el.$.compose.$.basic1.notifyingvalue, false); - assert.equal(el.$.compose.$.basic2.notifyingvalue, false); - assert.equal(el.$.compose.$.basic3.notifyingvalue, true); - assert.equal(el.$.forward.$.compose.$.basic1.notifyingvalue, false); - assert.equal(el.$.forward.$.compose.$.basic2.notifyingvalue, false); - assert.equal(el.$.forward.$.compose.$.basic3.notifyingvalue, true); + el.$.forward.$.compose.$.basic1.notifyingValue = false; + assert.equal(el.$.basic.notifyingValue, false); + assert.equal(el.$.compose.$.basic1.notifyingValue, false); + assert.equal(el.$.compose.$.basic2.notifyingValue, false); + assert.equal(el.$.compose.$.basic3.notifyingValue, true); + assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, false); + assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, false); + assert.equal(el.$.forward.$.compose.$.basic3.notifyingValue, true); assert.equal(el.$.basic.hasAttribute('attrvalue'), false); assert.equal(el.$.compose.$.basic1.hasAttribute('attrvalue'), false); assert.equal(el.$.compose.$.basic2.hasAttribute('attrvalue'), false); @@ -488,13 +488,13 @@ assert.equal(el.$.forward.$.compose.$.basic3.hasAttribute('attrvalue'), true); el.setPathValue('nested.obj.value', true); - assert.equal(el.$.basic.notifyingvalue, true); - assert.equal(el.$.compose.$.basic1.notifyingvalue, true); - assert.equal(el.$.compose.$.basic2.notifyingvalue, true); - assert.equal(el.$.compose.$.basic3.notifyingvalue, false); - assert.equal(el.$.forward.$.compose.$.basic1.notifyingvalue, true); - assert.equal(el.$.forward.$.compose.$.basic2.notifyingvalue, true); - assert.equal(el.$.forward.$.compose.$.basic3.notifyingvalue, false); + assert.equal(el.$.basic.notifyingValue, true); + assert.equal(el.$.compose.$.basic1.notifyingValue, true); + assert.equal(el.$.compose.$.basic2.notifyingValue, true); + assert.equal(el.$.compose.$.basic3.notifyingValue, false); + assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, true); + assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, true); + assert.equal(el.$.forward.$.compose.$.basic3.notifyingValue, false); assert.equal(el.$.basic.hasAttribute('attrvalue'), true); assert.equal(el.$.compose.$.basic1.hasAttribute('attrvalue'), true); assert.equal(el.$.compose.$.basic2.hasAttribute('attrvalue'), true); @@ -504,14 +504,14 @@ assert.equal(el.$.forward.$.compose.$.basic3.hasAttribute('attrvalue'), false); // no two way binding through negation - el.$.compose.$.basic3.notifyingvalue = true; - assert.equal(el.$.basic.notifyingvalue, true); - assert.equal(el.$.compose.$.basic1.notifyingvalue, true); - assert.equal(el.$.compose.$.basic2.notifyingvalue, true); - assert.equal(el.$.compose.$.basic3.notifyingvalue, true); - assert.equal(el.$.forward.$.compose.$.basic1.notifyingvalue, true); - assert.equal(el.$.forward.$.compose.$.basic2.notifyingvalue, true); - assert.equal(el.$.forward.$.compose.$.basic3.notifyingvalue, false); + el.$.compose.$.basic3.notifyingValue = true; + assert.equal(el.$.basic.notifyingValue, true); + assert.equal(el.$.compose.$.basic1.notifyingValue, true); + assert.equal(el.$.compose.$.basic2.notifyingValue, true); + assert.equal(el.$.compose.$.basic3.notifyingValue, true); + assert.equal(el.$.forward.$.compose.$.basic1.notifyingValue, true); + assert.equal(el.$.forward.$.compose.$.basic2.notifyingValue, true); + assert.equal(el.$.forward.$.compose.$.basic3.notifyingValue, false); assert.equal(el.$.basic.hasAttribute('attrvalue'), true); assert.equal(el.$.compose.$.basic1.hasAttribute('attrvalue'), true); assert.equal(el.$.compose.$.basic2.hasAttribute('attrvalue'), true); @@ -530,13 +530,13 @@ } }; el.nested = nested; - assert.equal(el.$.compose.$.basic1.notifyingvalue, 41); + assert.equal(el.$.compose.$.basic1.notifyingValue, 41); assert.equal(el.$.compose.$.basic1.othervalue, 99); el.setPathValue('nested.obj.value', 42); - assert.equal(el.$.compose.$.basic1.notifyingvalue, 42); + assert.equal(el.$.compose.$.basic1.notifyingValue, 42); assert.equal(el.$.compose.$.basic1.othervalue, 99); el.setPathValue('nested.obj.value2', 98); - assert.equal(el.$.compose.$.basic1.notifyingvalue, 42); + assert.equal(el.$.compose.$.basic1.notifyingValue, 42); assert.equal(el.$.compose.$.basic1.othervalue, 98); }); From f33266dd77b9711c94d519f767460d49b53a5ded Mon Sep 17 00:00:00 2001 From: "Scott J. Miles" Date: Mon, 9 Feb 2015 18:27:45 -0800 Subject: [PATCH 5/7] add dash-case awareness to serializeValueToAttribute --- src/features/micro/attributes.html | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/features/micro/attributes.html b/src/features/micro/attributes.html index 7a0f9c9547..031674976a 100644 --- a/src/features/micro/attributes.html +++ b/src/features/micro/attributes.html @@ -93,13 +93,13 @@ }, deserialize: function(name, value, type) { - + // var hasAttribute = this.hasAttribute(name); if (!hasAttribute && (type != Boolean) && (this[name] == null)) { return; } - - switch(type) { + // + switch (type) { case Number: value = Number(value); @@ -133,16 +133,24 @@ serialize: function(value) { switch (typeof value) { + case 'boolean': return value ? '' : undefined; + case 'object': if (value instanceof Date) { return value; - } else { - return value ? JSON.stringify(value) : undefined; + } else if (value) { + try { + return JSON.stringify(value); + } catch(x) { + return ''; + } } + default: return value != null ? value : undefined; + } }, @@ -153,11 +161,21 @@ serializeValueToAttribute: function(value, attribute, node) { node = node || this; value = this.serialize(value); + attribute = this.camelToDashCase(attribute); if (value !== undefined) { node.setAttribute(attribute, value); } else { node.removeAttribute(attribute); } + }, + + // TODO(sjmiles): duplicate of function in Annotations library + camelToDashCase: function(camel) { + return camel.replace(/([a-z][A-Z])/g, + function (g) { + return g[0] + '-' + g[1].toLowerCase() + } + ); } }); From bc7a23ff29b940ce228d3177937671488d5df6c2 Mon Sep 17 00:00:00 2001 From: "Scott J. Miles" Date: Mon, 9 Feb 2015 18:35:03 -0800 Subject: [PATCH 6/7] test dash-case for serializing --- test/unit/bind-elements.html | 2 +- test/unit/bind.html | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/unit/bind-elements.html b/test/unit/bind-elements.html index ee235eb8ac..51fd6ea24e 100644 --- a/test/unit/bind-elements.html +++ b/test/unit/bind-elements.html @@ -93,7 +93,7 @@ type: Array, reflect: true }, - reflectednumber: { + reflectedNumber: { type: Number, reflect: true }, diff --git a/test/unit/bind.html b/test/unit/bind.html index 7cb24cf2dd..491b308852 100644 --- a/test/unit/bind.html +++ b/test/unit/bind.html @@ -359,12 +359,12 @@ }); test('reflect number', function() { - el.reflectednumber = 765; - assert.equal(el.getAttribute('reflectednumber'), '765'); - el.reflectednumber = 765.4321; - assert.equal(el.getAttribute('reflectednumber'), '765.4321'); - el.reflectednumber = null; - assert(!el.hasAttribute('reflectednumber')); + el.reflectedNumber = 765; + assert.equal(el.getAttribute('reflected-number'), '765'); + el.reflectedNumber = 765.4321; + assert.equal(el.getAttribute('reflected-number'), '765.4321'); + el.reflectedNumber = null; + assert(!el.hasAttribute('reflected-number')); }); test('reflect boolean', function() { From c15063e0371585a970601182cc840aa21cb11806 Mon Sep 17 00:00:00 2001 From: "Scott J. Miles" Date: Thu, 12 Feb 2015 09:55:55 -0800 Subject: [PATCH 7/7] rearrangements --- dist/layout.html | 318 ----- dist/polymer-simplex.html | 19 - dist/polymer.html | 1349 -------------------- docs.html => docs/index.html | 0 polymer-mini.html | 2 +- src/{features/mini => lib}/dom-module.html | 0 src/polymer.html | 1 + 7 files changed, 2 insertions(+), 1687 deletions(-) delete mode 100644 dist/layout.html delete mode 100644 dist/polymer-simplex.html delete mode 100644 dist/polymer.html rename docs.html => docs/index.html (100%) rename src/{features/mini => lib}/dom-module.html (100%) diff --git a/dist/layout.html b/dist/layout.html deleted file mode 100644 index e16556c35b..0000000000 --- a/dist/layout.html +++ /dev/null @@ -1,318 +0,0 @@ - - diff --git a/dist/polymer-simplex.html b/dist/polymer-simplex.html deleted file mode 100644 index 0585214e42..0000000000 --- a/dist/polymer-simplex.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - diff --git a/dist/polymer.html b/dist/polymer.html deleted file mode 100644 index ffa2e9657a..0000000000 --- a/dist/polymer.html +++ /dev/null @@ -1,1349 +0,0 @@ - - - - - diff --git a/docs.html b/docs/index.html similarity index 100% rename from docs.html rename to docs/index.html diff --git a/polymer-mini.html b/polymer-mini.html index 36333f0a7f..6d9d3bbc6f 100644 --- a/polymer-mini.html +++ b/polymer-mini.html @@ -9,7 +9,7 @@ --> - + diff --git a/src/features/mini/dom-module.html b/src/lib/dom-module.html similarity index 100% rename from src/features/mini/dom-module.html rename to src/lib/dom-module.html diff --git a/src/polymer.html b/src/polymer.html index ef1a2df1f2..dbfe532bbe 100644 --- a/src/polymer.html +++ b/src/polymer.html @@ -29,6 +29,7 @@ if (prototype.extends) { options.extends = prototype.extends; } + console.log('[' + prototype.is + ']: registered'); document.registerElement(prototype.is, options); return elementClass; };