Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.8 demodulate #1264

Merged
merged 3 commits into from
Mar 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions polymer-micro.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,17 @@

<script>

using('Base', function(Base) {
Polymer.Base.addFeature({

Base.addFeature({
registerFeatures: function() {
this._prepMixins();
this._prepExtends();
this._prepConstructor();
},

registerFeatures: function() {
this._prepMixins();
this._prepExtends();
this._prepConstructor();
},

initFeatures: function() {
this._marshalAttributes();
}

});
initFeatures: function() {
this._marshalAttributes();
}

});

Expand Down
43 changes: 20 additions & 23 deletions polymer-mini.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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
-->

<link rel="import" href="polymer-micro.html">

<link rel="import" href="src/lib/dom-module.html">
Expand All @@ -17,29 +18,25 @@

<script>

using('Base', function(Base) {

Base.addFeature({

registerFeatures: function() {
this._prepMixins();
this._prepExtends();
this._prepConstructor();
this._prepTemplate();
this._prepContent();
},

initFeatures: function() {
this._poolContent();
this._pushHost();
this._stampTemplate();
this._popHost();
this._marshalAttributes();
this._readyContent();
}

});

Polymer.Base.addFeature({

registerFeatures: function() {
this._prepMixins();
this._prepExtends();
this._prepConstructor();
this._prepTemplate();
this._prepContent();
},

initFeatures: function() {
this._poolContent();
this._pushHost();
this._stampTemplate();
this._popHost();
this._marshalAttributes();
this._readyContent();
}

});

</script>
Expand Down
52 changes: 24 additions & 28 deletions polymer.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,30 @@

<script>

using('Base', function(Base) {

Base.addFeature({

registerFeatures: function() {
this._prepMixins();
this._prepExtends();
this._prepConstructor();
this._prepTemplate();
this._prepAnnotations();
this._prepEffects();
this._prepContent();
},

initFeatures: function() {
this._poolContent();
this._pushHost();
this._setupConfigure();
this._stampTemplate();
this._marshalAnnotationReferences();
this._popHost();
this._marshalInstanceEffects();
this._marshalAttributes();
this._marshalListeners();
this._readyContent();
}

});
Polymer.Base.addFeature({

registerFeatures: function() {
this._prepMixins();
this._prepExtends();
this._prepConstructor();
this._prepTemplate();
this._prepAnnotations();
this._prepEffects();
this._prepContent();
},

initFeatures: function() {
this._poolContent();
this._pushHost();
this._setupConfigure();
this._stampTemplate();
this._marshalAnnotationReferences();
this._popHost();
this._marshalInstanceEffects();
this._marshalAttributes();
this._marshalListeners();
this._readyContent();
}

});

Expand Down
211 changes: 99 additions & 112 deletions src/features/micro/attributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,134 +55,121 @@
* @class base feature: attributes
*/

using(['Base', 'Annotations'], function(Base, Annotations) {
Polymer.Base.addFeature({

Base.addFeature({
_marshalAttributes: function() {
this._takeAttributes();
this._installHostAttributes(this.hostAttributes);
},

_marshalAttributes: function() {
this._takeAttributes();
this._installHostAttributes(this.hostAttributes);
},

_installHostAttributes: function(attributes) {
if (attributes) {
this.cloneAttributes(this, attributes);
_installHostAttributes: function(attributes) {
if (attributes) {
this.cloneAttributes(this, attributes);
}
},

cloneAttributes: function(node, attr$) {
attr$.split(' ').forEach(function(a) {
node.setAttribute(a, '');
});
},

_takeAttributes: function() {
this._takeAttributesToModel(this);
},

_takeAttributesToModel: function(model) {
for (var propName in this.properties) {
var type = this.getPropertyType(propName);
var attrName = Polymer.Annotations.camelToDashCase(propName);
if (type && this.hasAttribute(attrName)) {
var val = this.getAttribute(attrName);
model[propName] = this.deserialize(val, type);
}
},

cloneAttributes: function(node, attr$) {
attr$.split(' ').forEach(function(a) {
node.setAttribute(a, '');
});
},

_takeAttributes: function() {
this._takeAttributesToModel(this);
},

_takeAttributesToModel: function(model) {
for (var propName in this.properties) {
var type = this.getPropertyType(propName);
var attrName = Annotations.camelToDashCase(propName);
if (type && this.hasAttribute(attrName)) {
var val = this.getAttribute(attrName);
model[propName] = this.deserialize(val, type);
}
}
},

setAttributeToProperty: function(model, attrName) {
// Don't deserialize back to property if currently reflecting
if (!this._serializing) {
var propName = Polymer.Annotations.dashToCamelCase(attrName);
var type = this.getPropertyType(propName);
if (type) {
var val = this.getAttribute(attrName);
model[propName] = this.deserialize(val, type);
}
},

setAttributeToProperty: function(model, attrName) {
// Don't deserialize back to property if currently reflecting
if (!this._serializing) {
var propName = Annotations.dashToCamelCase(attrName);
var type = this.getPropertyType(propName);
if (type) {
var val = this.getAttribute(attrName);
model[propName] = this.deserialize(val, type);
}
},

_serializing: false,
reflectPropertyToAttribute: function(name) {
this._serializing = true;
this.serializeValueToAttribute(this[name], name);
this._serializing = false;
},

serializeValueToAttribute: function(value, attribute, node) {
var str = this.serialize(value);
(node || this)
[str === undefined ? 'removeAttribute' : 'setAttribute']
(Polymer.Annotations.camelToDashCase(attribute), str);
},

deserialize: function(value, type) {
switch (type) {

case Number:
value = Number(value);
break;

case Boolean:
value = (value !== null);
break;

case Object:
case Array:
try {
value = JSON.parse(value);
} catch(x) {
value = '[invalid JSON]';
}
}
},
break;

deserialize: function(value, type) {
switch (type) {
case Date:
value = new Date(value);
break;

case Number:
value = Number(value);
break;

case Boolean:
value = (value !== null);
break;

case Object:
case Array:
try {
value = JSON.parse(value);
} catch(x) {
value = '[invalid JSON]';
}
break;
case String:
default:
break;

case Date:
value = new Date(value);
break;

case String:
default:
break;

}
return value;
}
return value;

},
},

serialize: function(value) {
switch (typeof value) {
serialize: function(value) {
switch (typeof value) {

case 'boolean':
return value ? '' : undefined;
case 'boolean':
return value ? '' : undefined;

case 'object':
if (value instanceof Date) {
return value;
} else if (value) {
try {
return JSON.stringify(value);
} catch(x) {
return '';
}
case 'object':
if (value instanceof Date) {
return value;
} else if (value) {
try {
return JSON.stringify(value);
} catch(x) {
return '';
}
}

default:
return value != null ? value : undefined;
default:
return value != null ? value : undefined;

}
},

_serializing: false,
reflectPropertyToAttribute: function(name) {
this._serializing = true;
this.serializeValueToAttribute(this[name], name);
this._serializing = false;
},

serializeValueToAttribute: function(value, attribute, node) {
value = this.serialize(value);
(node || this)[value === undefined ? 'removeAttribute' : 'setAttribute'](
this.camelToDashCase(attribute), value
);
},

// 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()
}
);
}

});
}

});

Expand Down
Loading