OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 part of observable; | 5 part of observable; |
6 | 6 |
7 /** | 7 /** |
8 * Accumulates change events from several observable objects. | 8 * Accumulates change events from several observable objects. |
9 * | 9 * |
10 * wrap() is public and used by client code. The other methods are used by | 10 * wrap() is public and used by client code. The other methods are used by |
11 * AbstractObservable, which works with this class to implement batching. | 11 * AbstractObservable, which works with this class to implement batching. |
12 */ | 12 */ |
13 class EventBatch { | 13 class EventBatch { |
14 | |
15 /** The current active batch, if any. */ | 14 /** The current active batch, if any. */ |
16 static EventBatch current; | 15 static EventBatch current; |
17 | 16 |
18 /** Used to generate unique ids for observable objects. */ | 17 /** Used to generate unique ids for observable objects. */ |
19 static int nextUid; | 18 static int nextUid; |
20 | 19 |
21 /** Map from observable object's uid to their tracked events. */ | 20 /** Map from observable object's uid to their tracked events. */ |
22 // TODO(sigmund): use [Observable] instead of [int] when [Map] can support it, | 21 // TODO(sigmund): use [Observable] instead of [int] when [Map] can support it, |
23 Map<int, EventSummary> summaries; | 22 Map<int, EventSummary> summaries; |
24 | 23 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 nextUid = 1; | 80 nextUid = 1; |
82 } | 81 } |
83 return nextUid++; | 82 return nextUid++; |
84 } | 83 } |
85 | 84 |
86 /** Retrieves the events associated with {@code obj}. */ | 85 /** Retrieves the events associated with {@code obj}. */ |
87 EventSummary getEvents(Observable obj) { | 86 EventSummary getEvents(Observable obj) { |
88 int uid = obj.uid; | 87 int uid = obj.uid; |
89 EventSummary summary = summaries[uid]; | 88 EventSummary summary = summaries[uid]; |
90 if (summary == null) { | 89 if (summary == null) { |
91 assert (!sealed); | 90 assert(!sealed); |
92 summary = new EventSummary(obj); | 91 summary = new EventSummary(obj); |
93 summaries[uid] = summary; | 92 summaries[uid] = summary; |
94 } | 93 } |
95 return summary; | 94 return summary; |
96 } | 95 } |
97 | 96 |
98 /** Fires all events at once. */ | 97 /** Fires all events at once. */ |
99 void _notify() { | 98 void _notify() { |
100 assert(!sealed); | 99 assert(!sealed); |
101 sealed = true; | 100 sealed = true; |
102 for (final summary in summaries.values) { | 101 for (final summary in summaries.values) { |
103 summary.notify(); | 102 summary.notify(); |
104 } | 103 } |
105 } | 104 } |
106 } | 105 } |
OLD | NEW |