| 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 part of app; | |
| 6 | |
| 7 /// A [ServiceObject] is an object known to the VM service and is tied | |
| 8 /// to an owning [Isolate]. | |
| 9 abstract class ServiceObject extends Observable { | |
| 10 /// Owning isolate. | |
| 11 final Isolate isolate; | |
| 12 /// The complete service url of this object. | |
| 13 String get link => isolate.relativeLink(_id); | |
| 14 String _id; | |
| 15 /// The id of this object. | |
| 16 String get id => _id; | |
| 17 String _serviceType; | |
| 18 /// The service type of this object. | |
| 19 String get serviceType => _serviceType; | |
| 20 | |
| 21 /// Refresh [this]. Returns a future which completes to [this]. | |
| 22 Future refresh(); | |
| 23 | |
| 24 ServiceObject(this.isolate, this._id, this._serviceType); | |
| 25 } | |
| 26 | |
| 27 | |
| 28 /// A [ServiceObject] which implements [Map]. | |
| 29 class ServiceMap extends ServiceObject implements Map { | |
| 30 final Map _map = new ObservableMap(); | |
| 31 | |
| 32 ServiceMap(Isolate isolate, String id, String serviceType) : | |
| 33 super(isolate, id, serviceType) { | |
| 34 } | |
| 35 | |
| 36 ServiceMap.fromMap(Isolate isolate, Map m) : | |
| 37 super(isolate, m['id'], m['type']) { | |
| 38 _fill(m); | |
| 39 } | |
| 40 | |
| 41 Future refresh() { | |
| 42 isolate.getMap(_id).then(_fill); | |
| 43 return new Future.value(this); | |
| 44 } | |
| 45 | |
| 46 void _fill(Map m) { | |
| 47 _map.clear(); | |
| 48 _map.addAll(m); | |
| 49 // TODO(johnmccutchan): Recursively promote all contained Maps to | |
| 50 // ServiceMaps if they have a 'type' key. | |
| 51 } | |
| 52 | |
| 53 // Implement Map by forwarding methods to _map. | |
| 54 void addAll(Map other) => _map.addAll(other); | |
| 55 void clear() => _map.clear(); | |
| 56 bool containsValue(v) => _map.containsValue(v); | |
| 57 bool containsKey(k) => _map.containsKey(k); | |
| 58 void forEach(Function f) => _map.forEach(f); | |
| 59 putIfAbsent(key, Function ifAbsent) => _map.putIfAbsent(key, ifAbsent); | |
| 60 void remove(key) => _map.remove(key); | |
| 61 operator [](k) => _map[k]; | |
| 62 operator []=(k, v) => _map[k] = v; | |
| 63 bool get isEmpty => _map.isEmpty; | |
| 64 bool get isNotEmpty => _map.isNotEmpty; | |
| 65 Iterable get keys => _map.keys; | |
| 66 Iterable get values => _map.values; | |
| 67 int get length => _map.length; | |
| 68 } | |
| OLD | NEW |