|
75 | 75 | prototype._publishLC = this.lowerCaseMap(publish);
|
76 | 76 | }
|
77 | 77 | },
|
78 |
| - // sync prototype to property descriptors; |
79 |
| - // desriptor format contains default value and optionally a |
80 |
| - // hint for reflecting the property to an attribute. |
81 |
| - // e.g. {foo: 5, bar: {value: true, reflect: true}} |
82 |
| - // reflect: {foo: true} is also supported |
83 | 78 | //
|
84 |
| - requireProperties: function(propertyDescriptors, prototype, base) { |
85 |
| - // reflected properties |
| 79 | + // `name: value` entries in the `publish` object may need to generate |
| 80 | + // matching properties on the prototype. |
| 81 | + // |
| 82 | + // Values that are objects may have a `reflect` property, which |
| 83 | + // signals that the value describes property control metadata. |
| 84 | + // In metadata objects, the prototype default value (if any) |
| 85 | + // is encoded in the `value` property. |
| 86 | + // |
| 87 | + // publish: { |
| 88 | + // foo: 5, |
| 89 | + // bar: {value: true, reflect: true}, |
| 90 | + // zot: {} |
| 91 | + // } |
| 92 | + // |
| 93 | + // `reflect` metadata property controls whether changes to the property |
| 94 | + // are reflected back to the attribute (default false). |
| 95 | + // |
| 96 | + // A value is stored on the prototype unless it's === `undefined`, |
| 97 | + // in which case the base chain is checked for a value. |
| 98 | + // If the basal value is also undefined, `null` is stored on the prototype. |
| 99 | + // |
| 100 | + // The reflection data is stored on another prototype object, `reflect` |
| 101 | + // which also can be specified directly. |
| 102 | + // |
| 103 | + // reflect: { |
| 104 | + // foo: true |
| 105 | + // } |
| 106 | + // |
| 107 | + requireProperties: function(propertyInfos, prototype, base) { |
| 108 | + // per-prototype storage for reflected properties |
86 | 109 | prototype.reflect = prototype.reflect || {};
|
87 | 110 | // ensure a prototype value for each property
|
88 | 111 | // and update the property's reflect to attribute status
|
89 |
| - for (var n in propertyDescriptors) { |
90 |
| - var propertyDescriptor = propertyDescriptors[n]; |
91 |
| - var reflects = this.reflectHintForDescriptor(propertyDescriptor); |
92 |
| - if (prototype.reflect[n] === undefined && reflects !== undefined) { |
93 |
| - prototype.reflect[n] = reflects; |
| 112 | + for (var n in propertyInfos) { |
| 113 | + var value = propertyInfos[n]; |
| 114 | + // value has metadata if it has a `reflect` property |
| 115 | + if (value && value.reflect !== undefined) { |
| 116 | + prototype.reflect[n] = Boolean(value.reflect); |
| 117 | + value = value.value; |
94 | 118 | }
|
95 |
| - if (prototype[n] === undefined) { |
96 |
| - prototype[n] = this.valueForDescriptor(propertyDescriptor); |
| 119 | + // only set a value if one is specified |
| 120 | + if (value !== undefined) { |
| 121 | + prototype[n] = value; |
97 | 122 | }
|
98 | 123 | }
|
99 | 124 | },
|
100 |
| - valueForDescriptor: function(propertyDescriptor) { |
101 |
| - var value = typeof propertyDescriptor === 'object' && |
102 |
| - propertyDescriptor ? propertyDescriptor.value : propertyDescriptor; |
103 |
| - return value !== undefined ? value : null; |
104 |
| - }, |
105 |
| - // returns the value of the descriptor's 'reflect' property or undefined |
106 |
| - reflectHintForDescriptor: function(propertyDescriptor) { |
107 |
| - if (typeof propertyDescriptor === 'object' && |
108 |
| - propertyDescriptor && propertyDescriptor.reflect !== undefined) { |
109 |
| - return propertyDescriptor.reflect; |
110 |
| - } |
111 |
| - }, |
112 | 125 | lowerCaseMap: function(properties) {
|
113 | 126 | var map = {};
|
114 | 127 | for (var n in properties) {
|
|
154 | 167 | this.createPropertyAccessor(n);
|
155 | 168 | }
|
156 | 169 | }
|
157 |
| - |
158 | 170 | var n$ = prototype._computedNames;
|
159 | 171 | if (n$ && n$.length) {
|
160 | 172 | for (var i=0, l=n$.length, n, fn; (i<l) && (n=n$[i]); i++) {
|
161 | 173 | this.createPropertyAccessor(n);
|
162 | 174 | }
|
163 | 175 | }
|
164 |
| - |
165 | 176 | }
|
166 | 177 | };
|
167 | 178 |
|
|
0 commit comments