Files
polymer/components/polymer/src/features/published.html
2014-11-17 10:38:22 -08:00

90 lines
2.6 KiB
HTML

<script>
/**
* Define public property API.
*
* published: {
* <property>: <Type || Object>,
* ...
*
* // `foo` property can be assigned via attribute, will be deserialized to
* // the specified data-type. All `published` properties have this behavior.
* foo: String,
*
* // `bar` property has additional behavior specifiers.
* // type: as above, type for (de-)serialization
* // notify: true to send a signal when a value is set to this property
* // reflect: true to serialize the property to an attribute
* // readOnly: if true, the property has no setter
* bar: {
* type: Boolean,
* notify: true
* }
* }
*
* By itself the published feature doesn't do anything but provide property
* information. Other features use this information to control behavior.
*
* The `type` information is used by the `attributes` feature to convert
* String values in attributes to properties.
*
* The `bind-effects` feature uses property information to control property
* access.
*
* Marking a property as `notify` causes a change in the property to
* fire a non-bubbling event called `<property>-changed`. Elements that
* have enabled two-way binding to the property use this event to
* observe changes.
*
* `readOnly` properties have a getter, but no setter. To set a read-only
* property, use the private setter method `_set_<property>(value)`.
*
* @class feature: published
*/
Base.addFeature({
published: {
},
nob: Object.create(null),
register: function(prototype) {
// TODO(sjmiles): move to a different module
if (prototype.addPropertyEffect) {
for (var n in prototype.published) {
if (prototype.isNotifyProperty(n)) {
prototype.addPropertyEffect(n, 'notify');
}
}
}
},
getPublishInfo: function(property) {
var p = this.published[property];
if (typeof(p) === 'function') {
p = this.published[property] = {
type: p
};
}
return p || Base.nob;
},
getPublishedPropertyType: function(property) {
return this.getPublishInfo(property).type;
},
isReadOnlyProperty: function(property) {
return this.getPublishInfo(property).readOnly;
},
isNotifyProperty: function(property) {
return this.getPublishInfo(property).notify;
},
isReflectedProperty: function(property) {
return this.getPublishInfo(property).reflect;
}
});
</script>