OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013, 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 import 'dart:html'; | |
6 import 'dart:async'; | |
7 import 'package:observatory/service_html.dart' show Isolate; | |
8 import 'package:observatory/repositories.dart' show IsolateUpdateEvent; | |
9 import 'shims/binding.dart'; | |
10 import 'helpers/tag.dart'; | |
11 import 'isolate_ref.dart'; | |
12 | |
13 class IsolateRefElementWrapper extends HtmlElement { | |
14 | |
15 static final binder = new Binder<IsolateRefElementWrapper>( | |
16 const [const Binding('ref')]); | |
17 | |
18 static const tag = const Tag<IsolateRefElementWrapper>('isolate-ref'); | |
19 | |
20 final StreamController<IsolateUpdateEvent> _updatesController = | |
21 new StreamController<IsolateUpdateEvent>(); | |
22 Stream<IsolateUpdateEvent> _updates; | |
23 StreamSubscription _subscription; | |
24 | |
25 Isolate _isolate; | |
26 Isolate get ref => _isolate; | |
27 void set ref(Isolate ref) { _isolate = ref; _detached(); _attached(); } | |
28 | |
29 IsolateRefElementWrapper.created() : super.created() { | |
30 _updates = _updatesController.stream.asBroadcastStream(); | |
31 binder.registerCallback(this); | |
32 createShadowRoot(); | |
33 render(); | |
34 } | |
35 | |
36 @override | |
37 void attached() { | |
38 super.attached(); | |
39 _attached(); | |
40 } | |
41 | |
42 void _attached() { | |
43 if (ref != null) { | |
44 _subscription = ref.changes.listen((_) { | |
45 _updatesController.add(new IsolateUpdateEvent(ref)); | |
Cutch
2016/07/07 19:50:57
This pattern is going to appear often. Maybe subsc
cbernaschina
2016/07/07 22:08:13
Working on it.
| |
46 }); | |
47 } | |
48 render(); | |
49 } | |
50 | |
51 @override | |
52 void detached() { | |
53 super.detached(); | |
54 _detached(); | |
55 } | |
56 | |
57 void _detached() { | |
58 if (_subscription != null) { | |
59 _subscription.cancel(); | |
60 _subscription = null; | |
61 } | |
62 } | |
63 | |
64 void render() { | |
65 shadowRoot.children = []; | |
66 if (ref == null) return; | |
67 | |
68 shadowRoot.children = [ | |
69 new IsolateRefElement(_isolate, _updates) | |
70 ]; | |
71 } | |
72 } | |
OLD | NEW |