Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 library js.js_object_map; | |
| 6 | |
| 7 import 'dart:collection' show Maps; | |
| 8 import 'dart:js'; | |
| 9 | |
| 10 import 'package:js/src/js_impl.dart'; | |
| 11 | |
| 12 /** | |
| 13 * A [Map] interface wrapper for [JsObject]s. | |
| 14 */ | |
| 15 class JsObjectMap<V> implements Map<String,V> { | |
|
alexandre.ardhuin
2014/10/01 20:36:51
You can use dart:collection.MapMixin to get rid of
justinfagnani
2014/10/07 20:32:24
Done.
| |
| 16 final JsObject _o; | |
| 17 | |
| 18 JsObjectMap.fromJsObject(JsObject o) : _o = o; | |
| 19 | |
| 20 @override | |
| 21 V operator [](String key) => toDart(_o[key]) as V; | |
| 22 | |
| 23 @override | |
| 24 void operator []=(String key, V value) { | |
| 25 _o[key] = toJs(value); | |
| 26 } | |
| 27 | |
| 28 @override | |
| 29 V remove(String key) { | |
| 30 final value = this[key]; | |
| 31 _o.deleteProperty(key); | |
| 32 return value as V; | |
| 33 } | |
| 34 | |
| 35 @override | |
| 36 Iterable<String> get keys => | |
| 37 context['Object'].callMethod('keys', [_o]) as List<String>; | |
| 38 | |
| 39 @override | |
| 40 bool containsValue(V value) => Maps.containsValue(this, value); | |
| 41 | |
| 42 @override | |
| 43 bool containsKey(String key) => _o.hasProperty(key); | |
| 44 | |
| 45 @override | |
| 46 V putIfAbsent(String key, V ifAbsent()) => | |
| 47 Maps.putIfAbsent(this, key, ifAbsent) as V; | |
| 48 | |
| 49 @override | |
| 50 void addAll(Map<String, V> other) { | |
| 51 if (other != null) { | |
| 52 other.forEach((k,v) => this[k] = v); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 @override | |
| 57 void clear() => Maps.clear(this); | |
| 58 | |
| 59 @override | |
| 60 void forEach(void f(String key, V value)) => Maps.forEach(this, f); | |
| 61 | |
| 62 @override | |
| 63 Iterable<V> get values => Maps.getValues(this); | |
| 64 | |
| 65 @override | |
| 66 int get length => Maps.length(this); | |
| 67 | |
| 68 @override | |
| 69 bool get isEmpty => Maps.isEmpty(this); | |
| 70 | |
| 71 @override | |
| 72 bool get isNotEmpty => Maps.isNotEmpty(this); | |
| 73 } | |
| OLD | NEW |