Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: sky/framework/sky-element/sky-element.sky

Issue 858453002: Require a type for SkyElement attributes. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Handle null attr. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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')
11 return value == 'true'; 11 return value == 'true';
12 return !!value; 12 return !!value;
13 }, 13 },
14 number: function(value) { 14 number: function(value) {
15 return Number(value); 15 return Number(value);
16 }, 16 },
17 string: function(value) { 17 string: function(value) {
18 if (value === null) 18 if (value === null)
19 return ''; 19 return '';
20 return String(value); 20 return String(value);
21 }, 21 },
22 }; 22 };
23 23
24 function parseAttributeSpec(spec) { 24 function parseAttributeSpec(spec) {
25 var attributes = new Map(); 25 var attributes = new Map();
26 var attributeTokens = (spec || '').split(','); 26
27 if (!spec)
28 return attributes;
29
30 var attributeTokens = spec.split(',');
27 31
28 for (var i = 0; i < attributeTokens.length; ++i) { 32 for (var i = 0; i < attributeTokens.length; ++i) {
29 var parts = attributeTokens[i].split(':'); 33 var parts = attributeTokens[i].split(':');
34
35 if (parts.length != 2) {
36 console.error('Invalid attribute spec "' + spec + '", attributes must' +
37 ' be {name}:{type}, where type is one of boolean, number or' +
38 ' string.');
39 continue;
40 }
41
30 var name = parts[0].trim(); 42 var name = parts[0].trim();
31 var type = (parts[1] || '').trim(); 43 var type = parts[1].trim();
32 var converter = attributeConverters[type] || attributeConverters.string; 44 var converter = attributeConverters[type];
45
46 if (!converter) {
47 console.error('Invalid attribute spec "' + spec + '", type must be one'
48 + ' of boolean, number or string.');
49 continue;
50 }
33 51
34 attributes.set(name, converter); 52 attributes.set(name, converter);
35 } 53 }
36 54
37 return attributes; 55 return attributes;
38 } 56 }
39 57
40 function collectEventHandlers(definition) { 58 function collectEventHandlers(definition) {
41 var eventHandlers = []; 59 var eventHandlers = [];
42 var attributes = definition.getAttributes(); 60 var attributes = definition.getAttributes();
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 binding.setValue(this[name]); 259 binding.setValue(this[name]);
242 binding.discardChanges(); 260 binding.discardChanges();
243 } 261 }
244 } 262 }
245 this.dirtyPropertyBindings = null; 263 this.dirtyPropertyBindings = null;
246 } 264 }
247 }; 265 };
248 266
249 module.exports = SkyElement; 267 module.exports = SkyElement;
250 </script> 268 </script>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698