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

Unified Diff: lib/src/js_object_map.dart

Issue 615913004: Add @jsify annotation. Support automatically proxying Lists and Maps to Dart in Proxies. Support co… (Closed) Base URL: https://github.com/dart-lang/js-interop.git@master
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: lib/src/js_object_map.dart
diff --git a/lib/src/js_object_map.dart b/lib/src/js_object_map.dart
new file mode 100644
index 0000000000000000000000000000000000000000..6831bd792fff7a7a691ff8bed4be07aa5a5a7dc3
--- /dev/null
+++ b/lib/src/js_object_map.dart
@@ -0,0 +1,73 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library js.js_object_map;
+
+import 'dart:collection' show Maps;
+import 'dart:js';
+
+import 'package:js/src/js_impl.dart';
+
+/**
+ * A [Map] interface wrapper for [JsObject]s.
+ */
+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.
+ final JsObject _o;
+
+ JsObjectMap.fromJsObject(JsObject o) : _o = o;
+
+ @override
+ V operator [](String key) => toDart(_o[key]) as V;
+
+ @override
+ void operator []=(String key, V value) {
+ _o[key] = toJs(value);
+ }
+
+ @override
+ V remove(String key) {
+ final value = this[key];
+ _o.deleteProperty(key);
+ return value as V;
+ }
+
+ @override
+ Iterable<String> get keys =>
+ context['Object'].callMethod('keys', [_o]) as List<String>;
+
+ @override
+ bool containsValue(V value) => Maps.containsValue(this, value);
+
+ @override
+ bool containsKey(String key) => _o.hasProperty(key);
+
+ @override
+ V putIfAbsent(String key, V ifAbsent()) =>
+ Maps.putIfAbsent(this, key, ifAbsent) as V;
+
+ @override
+ void addAll(Map<String, V> other) {
+ if (other != null) {
+ other.forEach((k,v) => this[k] = v);
+ }
+ }
+
+ @override
+ void clear() => Maps.clear(this);
+
+ @override
+ void forEach(void f(String key, V value)) => Maps.forEach(this, f);
+
+ @override
+ Iterable<V> get values => Maps.getValues(this);
+
+ @override
+ int get length => Maps.length(this);
+
+ @override
+ bool get isEmpty => Maps.isEmpty(this);
+
+ @override
+ bool get isNotEmpty => Maps.isNotEmpty(this);
+}

Powered by Google App Engine
This is Rietveld 408576698