-
Notifications
You must be signed in to change notification settings - Fork 2k
/
published.html
99 lines (88 loc) · 3.12 KB
/
published.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
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
-->
<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>