Unified
Split
Showing
with
83 additions
and 62 deletions.
- +1 −1 src/annotations/annotations.html
- +58 −57 src/bind/bind-effects.html
- +24 −4 src/polymer.html
| @@ -161,7 +161,7 @@ | ||
| if (mode) { | ||
| node.removeAttribute(n); | ||
| return { | ||
| kind: 'attribute', | ||
| kind: 'property', | ||
| mode: mode, | ||
| name: n, | ||
| value: v | ||
| @@ -8,6 +8,7 @@ | ||
| subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
| --> | ||
| <script> | ||
| using(['bind'], function(Bind) { | ||
| Bind.addComputedPropertyEffect = function(model, name, expression) { | ||
| @@ -28,67 +29,67 @@ | ||
| Bind.addBuilders({ | ||
| method: function(model, source, effect) { | ||
| // TODO(sjmiles): validation system requires a blessed | ||
| // validator effect which needs to be processed first. | ||
| /* | ||
| if (typeof this[effect] === 'function') { | ||
| return [ | ||
| 'var validated = this.' + effect + '(value, old)', | ||
| 'if (validated !== undefined) {', | ||
| ' // recurse', | ||
| ' this[property] = validated;', | ||
| ' return;', | ||
| '}' | ||
| ].join('\n'); | ||
| } | ||
| */ | ||
| // TODO(sjmiles): validation system requires a blessed | ||
| // validator effect which needs to be processed first. | ||
| /* | ||
| if (typeof this[effect] === 'function') { | ||
| return [ | ||
| 'var validated = this.' + effect + '(value, old)', | ||
| 'if (validated !== undefined) {', | ||
| ' // recurse', | ||
| ' this[property] = validated;', | ||
| ' return;', | ||
| '}' | ||
| ].join('\n'); | ||
| } | ||
| */ | ||
| // | ||
| return 'this.' + effect + '(this._data.' + source + ', old);' | ||
| }, | ||
| // basic modus operandi | ||
| // | ||
| return 'this.' + effect + '(this._data.' + source + ', old);' | ||
| }, | ||
| // basic modus operandi | ||
| // | ||
| // <hostPath> %=% <targetPath> | ||
| // (node = <$.id | nodes[index]>) | ||
| // <model[.path]> %=% node.<property> | ||
| // | ||
| // flow-up: | ||
| // set(model): node.<property> = <model[.path]> | ||
| // | ||
| // flow-down: | ||
| // node.on.<property>-changed: <model[.path]> = e.detail.value | ||
| notify: function(model, source) { | ||
| model._notifyChange = Bind._notifyChange; | ||
| return 'this._notifyChange(\'' + source + '\')'; | ||
| }, | ||
| compute: function(model, source, effect) { | ||
| return 'this.' + effect.property | ||
| + ' = this.' + effect.method + '(this._data.' + source + ');'; | ||
| }, | ||
| // implement effect directives from template annotations | ||
| // _nodes[info.index][info.name] = {{info.value}} | ||
| annotation: function(model, hostProperty, info) { | ||
| var property = info.name || 'textContent'; | ||
| if (property !== 'textContent') { | ||
| // <node>.on.<property>-changed: <path> = e.detail.value | ||
| Bind._addAnnotatedListener(model, info.index, property, info.value); | ||
| } | ||
| // | ||
| // flow-down | ||
| // <hostPath> %=% <targetPath> | ||
| // (node = <$.id | nodes[index]>) | ||
| // <model[.path]> %=% node.<property> | ||
| // | ||
| // construct the effect to occur when [property] changes: | ||
| // set nodes[index][name] to this[value] | ||
| // flow-up: | ||
| // set(model): node.<property> = <model[.path]> | ||
| // | ||
| //console.log('[_annotationEffectBuilder]: [%s] %=% [%s].[%s]', info.value, info.index, property); | ||
| return 'this._nodes[' + info.index + '].' + property | ||
| + ' = this._data.' + info.value + ';'; | ||
| } | ||
| // flow-down: | ||
| // node.on.<property>-changed: <model[.path]> = e.detail.value | ||
| notify: function(model, source) { | ||
| model._notifyChange = Bind._notifyChange; | ||
| return 'this._notifyChange(\'' + source + '\')'; | ||
| }, | ||
| compute: function(model, source, effect) { | ||
| return 'this.' + effect.property | ||
| + ' = this.' + effect.method + '(this._data.' + source + ');'; | ||
| }, | ||
| // implement effect directives from template annotations | ||
| // _nodes[info.index][info.name] = {{info.value}} | ||
| annotation: function(model, hostProperty, info) { | ||
| var property = info.name || 'textContent'; | ||
| if (property !== 'textContent') { | ||
| // <node>.on.<property>-changed: <path> = e.detail.value | ||
| Bind._addAnnotatedListener(model, info.index, property, info.value); | ||
| } | ||
| // | ||
| // flow-down | ||
| // | ||
| // construct the effect to occur when [property] changes: | ||
| // set nodes[index][name] to this[value] | ||
| // | ||
| //console.log('[_annotationEffectBuilder]: [%s] %=% [%s].[%s]', info.value, info.index, property); | ||
| return 'this._nodes[' + info.index + '].' + property | ||
| + ' = this._data.' + info.value + ';'; | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| </script> | ||
| @@ -17,9 +17,8 @@ | ||
| Base.__proto__ = HTMLElement.prototype; | ||
| window.Polymer = function(prototype) { | ||
| prototype.__proto__ = Base; | ||
| prototype.registerCallback(); | ||
| var Polymer = function(prototype) { | ||
| var ctor = desugar(prototype); | ||
| // native Custom Elements treats 'undefined' extends property | ||
| // as valued, the property must not exist to be ignored | ||
| var options = { | ||
| @@ -30,11 +29,32 @@ | ||
| } | ||
| // TODO(sjmiles): temporary BC for s\name\tag | ||
| document.registerElement(prototype.tag || prototype.name, options); | ||
| return prototype.constructor; | ||
| return ctor; | ||
| }; | ||
| var desugar = function(prototype) { | ||
| prototype.__proto__ = Base; | ||
| prototype.registerCallback(); | ||
| return prototype.construtor; | ||
| }; | ||
| window.Polymer = Polymer; | ||
| Polymer.desugar = desugar; | ||
| return Polymer; | ||
| }); | ||
| /* | ||
| // Raw usage | ||
| [ctor =] Polymer.desugar(prototype); | ||
| document.registerElement(name, { | ||
| prototype: prototype, | ||
| extends: extends | ||
| }); | ||
| // Simplified usage | ||
| [ctor = ] Polymer(prototype); | ||
| */ | ||
| </script> | ||