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

Side by Side Diff: lib/html/src/DataAttributeMap.dart

Issue 9930008: Fix issue http://code.google.com/p/dart/issues/detail?id=1877 without degrading performance. Impro… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review fixes Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « lib/html/frog/html_frog.dart ('k') | 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 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 /** 5 /**
6 * Provides a Map abstraction on top of data-* attributes, similar to the 6 * Provides a Map abstraction on top of data-* attributes, similar to the
7 * dataSet in the old DOM. 7 * dataSet in the old DOM.
8 */ 8 */
9 class _DataAttributeMap implements Map<String, String> { 9 class _DataAttributeMap implements AttributeMap {
10 10
11 final Map<String, String> _attributes; 11 final Map<String, String> _attributes;
12 12
13 _DataAttributeMap(this._attributes); 13 _DataAttributeMap(this._attributes);
14 14
15 // interface Map 15 // interface Map
16 16
17 // TODO: Use lazy iterator when it is available on Map. 17 // TODO: Use lazy iterator when it is available on Map.
18 bool containsValue(String value) => getValues().some((v) => v == value); 18 bool containsValue(String value) => getValues().some((v) => v == value);
19 19
20 bool containsKey(String key) => _attributes.containsKey(_attr(key)); 20 bool containsKey(String key) => _attributes.containsKey(_attr(key));
21 21
22 String operator [](String key) => _attributes[_attr(key)]; 22 String operator [](String key) => _attributes[_attr(key)];
23 23
24 void operator []=(String key, String value) { 24 void operator []=(String key, value) {
25 _attributes[_attr(key)] = value; 25 _attributes[_attr(key)] = '$value';
26 } 26 }
27 27
28 String putIfAbsent(String key, String ifAbsent()) { 28 String putIfAbsent(String key, String ifAbsent()) {
29 if (!containsKey(key)) { 29 if (!containsKey(key)) {
30 return this[key] = ifAbsent(); 30 return this[key] = ifAbsent();
31 } 31 }
32 return this[key]; 32 return this[key];
33 } 33 }
34 34
35 String remove(String key) => _attributes.remove(_attr(key)); 35 String remove(String key) => _attributes.remove(_attr(key));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 // TODO: Use lazy iterator when it is available on Map. 74 // TODO: Use lazy iterator when it is available on Map.
75 bool isEmpty() => length == 0; 75 bool isEmpty() => length == 0;
76 76
77 // Helpers. 77 // Helpers.
78 String _attr(String key) => 'data-$key'; 78 String _attr(String key) => 'data-$key';
79 bool _matches(String key) => key.startsWith('data-'); 79 bool _matches(String key) => key.startsWith('data-');
80 String _strip(String key) => key.substring(5); 80 String _strip(String key) => key.substring(5);
81 } 81 }
82 82
OLDNEW
« no previous file with comments | « lib/html/frog/html_frog.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698