mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
90 lines
2.6 KiB
HTML
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> |