|
24 | 24 | attributeChanged: true, |
25 | 25 | }; |
26 | 26 |
|
27 | | - const noCopyProps = Object.assign({ |
| 27 | + const excludeProps = Object.assign({ |
28 | 28 | behaviors: true |
29 | 29 | }, metaProps); |
30 | 30 |
|
31 | | - const filteredProps = Object.assign({ |
| 31 | + const lifecycleProps = Object.assign({ |
32 | 32 | listeners: true, |
33 | 33 | hostAttributes: true |
34 | 34 | }, metaProps); |
35 | 35 |
|
36 | 36 | function copyProperties(source, target) { |
37 | 37 | for (let p in source) { |
38 | | - // NOTE: cannot copy `noCopyProps` methods onto prototype at least because |
| 38 | + // NOTE: cannot copy `excludeProps` methods onto prototype at least because |
39 | 39 | // `super.ready` must be called and is not included in the user fn. |
40 | | - if (!(p in noCopyProps)) { |
| 40 | + if (!(p in excludeProps)) { |
41 | 41 | let pd = Object.getOwnPropertyDescriptor(source, p); |
42 | 42 | if (pd) { |
43 | 43 | Object.defineProperty(target, p, pd); |
|
95 | 95 | // If lifecycle is called (super then me), order is |
96 | 96 | // (1) C.created, (2) A.created, (3) B.created, (4) element.created |
97 | 97 | // (again same as 1.x) |
98 | | - function copyAndFilterBehaviors(proto, behaviors, lifecycle) { |
| 98 | + function applyBehaviors(proto, behaviors, lifecycle) { |
99 | 99 | for (let i=0; i<behaviors.length; i++) { |
100 | | - copyAndFilterProperties(proto, behaviors[i], lifecycle); |
| 100 | + applyInfo(proto, behaviors[i], lifecycle); |
101 | 101 | } |
102 | 102 | } |
103 | 103 |
|
104 | | - function copyAndFilterProperties(proto, infoOrBehavior, lifecycle) { |
105 | | - copyProperties(infoOrBehavior, proto); |
106 | | - for (let p in filteredProps) { |
107 | | - if (infoOrBehavior[p]) { |
| 104 | + function applyInfo(proto, info, lifecycle) { |
| 105 | + copyProperties(info, proto); |
| 106 | + for (let p in lifecycleProps) { |
| 107 | + if (info[p]) { |
108 | 108 | lifecycle[p] = lifecycle[p] || []; |
109 | | - lifecycle[p].push(infoOrBehavior[p]); |
| 109 | + lifecycle[p].push(info[p]); |
110 | 110 | } |
111 | 111 | } |
112 | 112 | } |
|
219 | 219 | function GenerateClassFromInfo(info, Base, behaviors) { |
220 | 220 |
|
221 | 221 | // manages behavior and lifecycle processing (filled in after class definition) |
222 | | - let activeBehaviors; |
| 222 | + let behaviorList; |
223 | 223 | const lifecycle = {}; |
224 | 224 |
|
225 | 225 | /** @private */ |
226 | 226 | class PolymerGenerated extends Base { |
227 | 227 |
|
228 | 228 | static get properties() { |
229 | 229 | const properties = {}; |
230 | | - if (activeBehaviors) { |
231 | | - for (let i=0, b; i < activeBehaviors.length; i++) { |
232 | | - b = activeBehaviors[i]; |
| 230 | + if (behaviorList) { |
| 231 | + for (let i=0, b; i < behaviorList.length; i++) { |
| 232 | + b = behaviorList[i]; |
233 | 233 | mergeElementProperties(properties, b.properties); |
234 | 234 | } |
235 | 235 | } |
|
239 | 239 |
|
240 | 240 | static get observers() { |
241 | 241 | let observers = []; |
242 | | - if (activeBehaviors) { |
243 | | - for (let i=0, b; i < activeBehaviors.length; i++) { |
244 | | - b = activeBehaviors[i]; |
| 242 | + if (behaviorList) { |
| 243 | + for (let i=0, b; i < behaviorList.length; i++) { |
| 244 | + b = behaviorList[i]; |
245 | 245 | if (b.observers) { |
246 | 246 | observers = observers.concat(b.observers); |
247 | 247 | } |
|
279 | 279 | `is` in `beforeRegister` as you could in 1.x. |
280 | 280 | */ |
281 | 281 | const proto = this; |
282 | | - if (activeBehaviors) { |
283 | | - copyAndFilterBehaviors(proto, activeBehaviors, lifecycle); |
| 282 | + if (behaviorList) { |
| 283 | + applyBehaviors(proto, behaviorList, lifecycle); |
284 | 284 | } |
285 | | - copyAndFilterProperties(proto, info, lifecycle); |
| 285 | + applyInfo(proto, info, lifecycle); |
286 | 286 | let list = lifecycle.beforeRegister; |
287 | 287 | if (list) { |
288 | 288 | for (let i=0; i < list.length; i++) { |
|
403 | 403 | } |
404 | 404 | let superBehaviors = Base.prototype.behaviors; |
405 | 405 | // get flattened, deduped list of behaviors *not* already on super class |
406 | | - activeBehaviors = flattenBehaviors(behaviors, null, superBehaviors); |
| 406 | + behaviorList = flattenBehaviors(behaviors, null, superBehaviors); |
407 | 407 | PolymerGenerated.prototype.behaviors = superBehaviors ? |
408 | | - superBehaviors.concat(behaviors) : activeBehaviors; |
| 408 | + superBehaviors.concat(behaviors) : behaviorList; |
409 | 409 | } |
410 | 410 |
|
411 | 411 | PolymerGenerated.generatedFrom = info; |
|
0 commit comments