OLD | NEW |
1 <!-- | 1 <!-- |
2 // Copyright 2014 The Chromium Authors. All rights reserved. | 2 // Copyright 2014 The Chromium Authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 --> | 5 --> |
6 <import src="sky-binder.sky" as="binder" /> | 6 <import src="sky-binder.sky" as="binder" /> |
7 <script> | 7 <script> |
8 var attributeConverters = { | 8 var attributeConverters = { |
9 boolean: function(value) { | 9 boolean: function(value) { |
10 if (typeof value == 'string') | 10 if (typeof value == 'string') |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 this.attributes = parseAttributeSpec(definition.getAttribute('attributes')); | 70 this.attributes = parseAttributeSpec(definition.getAttribute('attributes')); |
71 this.eventHandlers = collectEventHandlers(definition); | 71 this.eventHandlers = collectEventHandlers(definition); |
72 this.template = definition.querySelector('template'); | 72 this.template = definition.querySelector('template'); |
73 Object.preventExtensions(this); | 73 Object.preventExtensions(this); |
74 } | 74 } |
75 | 75 |
76 getEventHandler(eventName) { | 76 getEventHandler(eventName) { |
77 return this.definition.getAttribute('on-' + eventName); | 77 return this.definition.getAttribute('on-' + eventName); |
78 } | 78 } |
79 | 79 |
80 getAttributeNames() { | |
81 // TODO(esprehn): We can replace this method with | |
82 // Array.from(registration.attributes) once we turn that on. | |
83 var names = [] | |
84 this.attributes.forEach(function(converter, name) { | |
85 names.push(name); | |
86 }); | |
87 return names; | |
88 } | |
89 | |
90 synthesizeAttributes(prototype) { | 80 synthesizeAttributes(prototype) { |
91 this.attributes.forEach(function(converter, name) { | 81 this.attributes.forEach(function(converter, name) { |
92 Object.defineProperty(prototype, name, { | 82 Object.defineProperty(prototype, name, { |
93 get: function() { | 83 get: function() { |
94 return converter(this.getAttribute(name)); | 84 return converter(this.getAttribute(name)); |
95 }, | 85 }, |
96 set: function(newValue) { | 86 set: function(newValue) { |
97 this.setAttribute(name, converter(newValue)); | 87 this.setAttribute(name, converter(newValue)); |
98 }, | 88 }, |
99 enumerable: true, | 89 enumerable: true, |
(...skipping 22 matching lines...) Expand all Loading... |
122 | 112 |
123 if (registrations.has(registration.tagName)) { | 113 if (registrations.has(registration.tagName)) { |
124 throw new Error('Duplicate registration for tag name: ' + | 114 throw new Error('Duplicate registration for tag name: ' + |
125 registration.tagName); | 115 registration.tagName); |
126 } | 116 } |
127 | 117 |
128 registration.synthesizeAttributes(this.prototype); | 118 registration.synthesizeAttributes(this.prototype); |
129 | 119 |
130 // TODO(esprehn): Combine the two element registries here and in sky binder. | 120 // TODO(esprehn): Combine the two element registries here and in sky binder. |
131 binder.registerElement(registration.tagName, { | 121 binder.registerElement(registration.tagName, { |
132 attributeNames: registration.getAttributeNames(), | 122 attributeNames: Array.from(registration.attributes.keys()), |
133 }); | 123 }); |
134 | 124 |
135 registrations.set(registration.tagName, registration); | 125 registrations.set(registration.tagName, registration); |
136 return document.registerElement(registration.tagName, { | 126 return document.registerElement(registration.tagName, { |
137 prototype: this.prototype, | 127 prototype: this.prototype, |
138 }); | 128 }); |
139 } | 129 } |
140 | 130 |
141 created() { | 131 created() { |
142 // override | 132 // override |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 binding.setValue(this[name]); | 241 binding.setValue(this[name]); |
252 binding.discardChanges(); | 242 binding.discardChanges(); |
253 } | 243 } |
254 } | 244 } |
255 this.dirtyPropertyBindings = null; | 245 this.dirtyPropertyBindings = null; |
256 } | 246 } |
257 }; | 247 }; |
258 | 248 |
259 module.exports = SkyElement; | 249 module.exports = SkyElement; |
260 </script> | 250 </script> |
OLD | NEW |