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

Side by Side Diff: runtime/observatory/lib/src/elements/nav/notify.dart

Issue 2211603002: Centralized event streams (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merged with master Created 4 years, 4 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'dart:html'; 5 import 'dart:html';
6 import 'dart:async'; 6 import 'dart:async';
7 import 'package:observatory/models.dart' as M; 7 import 'package:observatory/models.dart' as M;
8 import 'package:observatory/src/elements/helpers/tag.dart'; 8 import 'package:observatory/src/elements/helpers/tag.dart';
9 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; 9 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart';
10 import 'package:observatory/src/elements/nav/notify_event.dart'; 10 import 'package:observatory/src/elements/nav/notify_event.dart';
11 import 'package:observatory/src/elements/nav/notify_exception.dart'; 11 import 'package:observatory/src/elements/nav/notify_exception.dart';
12 12
13 class NavNotifyElement extends HtmlElement implements Renderable { 13 class NavNotifyElement extends HtmlElement implements Renderable {
14 static const tag = const Tag<NavNotifyElement>('nav-notify-wrapped', 14 static const tag = const Tag<NavNotifyElement>('nav-notify-wrapped',
15 dependencies: const [ NavNotifyEventElement.tag, 15 dependencies: const [ NavNotifyEventElement.tag,
16 NavNotifyExceptionElement.tag ]); 16 NavNotifyExceptionElement.tag ]);
17 17
18 RenderingScheduler _r; 18 RenderingScheduler _r;
19 19
20 Stream<RenderedEvent<NavNotifyElement>> get onRendered => _r.onRendered; 20 Stream<RenderedEvent<NavNotifyElement>> get onRendered => _r.onRendered;
21 21
22 M.NotificationRepository _repository; 22 M.NotificationRepository _repository;
23 StreamSubscription _subscription; 23 StreamSubscription _subscription;
24 24
25 bool _notifyOnPause; 25 bool _notifyOnPause;
26
26 bool get notifyOnPause => _notifyOnPause; 27 bool get notifyOnPause => _notifyOnPause;
28
27 set notifyOnPause(bool value) => 29 set notifyOnPause(bool value) =>
28 _notifyOnPause = _r.checkAndReact(_notifyOnPause, value); 30 _notifyOnPause = _r.checkAndReact(_notifyOnPause, value);
29 31
30 factory NavNotifyElement(M.NotificationRepository repository, 32 factory NavNotifyElement(M.NotificationRepository repository,
31 {bool notifyOnPause: true, RenderingQueue queue}) { 33 {bool notifyOnPause: true, RenderingQueue queue}) {
32 assert(repository != null); 34 assert(repository != null);
33 assert(notifyOnPause != null); 35 assert(notifyOnPause != null);
34 NavNotifyElement e = document.createElement(tag.name); 36 NavNotifyElement e = document.createElement(tag.name);
35 e._r = new RenderingScheduler(e, queue: queue); 37 e._r = new RenderingScheduler(e, queue: queue);
36 e._repository = repository; 38 e._repository = repository;
37 e._notifyOnPause = notifyOnPause; 39 e._notifyOnPause = notifyOnPause;
38 return e; 40 return e;
39 } 41 }
40 42
41 NavNotifyElement.created() : super.created(); 43 NavNotifyElement.created() : super.created();
42 44
43 @override 45 @override
44 void attached() { 46 void attached() {
45 super.attached(); 47 super.attached();
48 _subscription = _repository.onChange.listen((_) => _r.dirty());
46 _r.enable(); 49 _r.enable();
47 _subscription = _repository.onChange.listen((_) => _r.dirty());
48 } 50 }
49 51
50 @override 52 @override
51 void detached() { 53 void detached() {
52 super.detached(); 54 super.detached();
53 children = []; 55 children = [];
54 _r.disable(notify: true); 56 _r.disable(notify: true);
55 _subscription.cancel(); 57 _subscription.cancel();
56 } 58 }
57 59
(...skipping 23 matching lines...) Expand all
81 return new NavNotifyExceptionElement( 83 return new NavNotifyExceptionElement(
82 notification.exception, stacktrace: notification.stacktrace, 84 notification.exception, stacktrace: notification.stacktrace,
83 queue: _r.queue) 85 queue: _r.queue)
84 ..onDelete.listen((_) => _repository.delete(notification)); 86 ..onDelete.listen((_) => _repository.delete(notification));
85 } else { 87 } else {
86 assert(false); 88 assert(false);
87 return new DivElement()..text = 'Invalid Notification Type'; 89 return new DivElement()..text = 'Invalid Notification Type';
88 } 90 }
89 } 91 }
90 } 92 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/elements/nav/menu_wrapper.dart ('k') | runtime/observatory/lib/src/elements/nav/notify_event.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698