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

Side by Side Diff: lib/src/emitters.dart

Issue 11315020: Add attribute information table so we generate correct setters. (Closed) Base URL: https://github.com/dart-lang/dart-web-components.git@master
Patch Set: Created 8 years, 1 month 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 | lib/src/html5_utils.dart » ('j') | lib/src/html5_utils.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** Collects several code emitters for the template tool. */ 5 /** Collects several code emitters for the template tool. */
6 // TODO(sigmund): add visitor that applies all emitters on a component 6 // TODO(sigmund): add visitor that applies all emitters on a component
7 // TODO(sigmund): add support for conditionals, so context is changed at that 7 // TODO(sigmund): add support for conditionals, so context is changed at that
8 // point. 8 // point.
9 library emitters; 9 library emitters;
10 10
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 if (e.oldValue != null && e.oldValue != '') { 211 if (e.oldValue != null && e.oldValue != '') {
212 $elemField.classes.remove(e.oldValue); 212 $elemField.classes.remove(e.oldValue);
213 } 213 }
214 if (e.newValue != null && e.newValue != '') { 214 if (e.newValue != null && e.newValue != '') {
215 $elemField.classes.add(e.newValue); 215 $elemField.classes.add(e.newValue);
216 } 216 }
217 }); 217 });
218 '''); 218 ''');
219 } 219 }
220 } else { 220 } else {
221 // Note: it is important for correctness to use the DOM setter if it
222 // is available. Otherwise changes will not be applied. This is most
223 // easily observed with "InputElement.value", ".checked", etc.
224 var setter;
225 var allowedTags = htmlAttributeTags[name];
Siggi Cherem (dart-lang) 2012/10/27 00:46:45 nit: maybe some alternative name? allowedTags ring
226 if (allowedTags == allHtmlElements ||
227 allowedTags != null && allowedTags.contains(elem.tagName)) {
228 var renamed = elementFieldRenames[name];
Siggi Cherem (dart-lang) 2012/10/27 00:46:45 elementFieldRenames => domToDartHtml?
229 setter = renamed != null ? renamed : name;
230 } else {
231 setter = 'attributes["$name"]';
232 }
233
221 var val = attrInfo.boundValue; 234 var val = attrInfo.boundValue;
222 var stopperName = attrInfo.stopperNames[0]; 235 var stopperName = attrInfo.stopperNames[0];
223 var setter;
224 // TODO(sigmund): use setters when they are available (issue #112)
225 if (elem.tagName == 'input' && (name == 'value' || name == 'checked')) {
226 setter = name;
227 } else {
228 setter = 'attributes["$name"]';
229 }
230 context.insertedMethod.add(''' 236 context.insertedMethod.add('''
231 $stopperName = autogenerated.watchAndInvoke(() => $val, (e) { 237 $stopperName = autogenerated.watchAndInvoke(() => $val, (e) {
232 $elemField.$setter = e.newValue; 238 $elemField.$setter = e.newValue;
233 }); 239 });
234 '''); 240 ''');
235 } 241 }
236 }); 242 });
237 243
238 // stop-functions for watchers associated with data-bound content 244 // stop-functions for watchers associated with data-bound content
239 if (elemInfo.contentBinding != null) { 245 if (elemInfo.contentBinding != null) {
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 (c) => PathInfo.relativePath(_info, c)); 675 (c) => PathInfo.relativePath(_info, c));
670 printer.add(codegen.importList(imports)) 676 printer.add(codegen.importList(imports))
671 .add(codegen.mainDartCode(codeInfo.code, 677 .add(codegen.mainDartCode(codeInfo.code,
672 _context.declarations.formatString(0), 678 _context.declarations.formatString(0),
673 _context.createdMethod.formatString(1), 679 _context.createdMethod.formatString(1),
674 _context.insertedMethod.formatString(1), 680 _context.insertedMethod.formatString(1),
675 document.body.innerHTML.trim())); 681 document.body.innerHTML.trim()));
676 return printer.formatString(); 682 return printer.formatString();
677 } 683 }
678 } 684 }
OLDNEW
« no previous file with comments | « no previous file | lib/src/html5_utils.dart » ('j') | lib/src/html5_utils.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698