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 |
(...skipping 13 matching lines...) Expand all Loading... |
24 /** Whether this batch is currently firing and therefore is sealed. */ | 24 /** Whether this batch is currently firing and therefore is sealed. */ |
25 bool sealed = false; | 25 bool sealed = false; |
26 | 26 |
27 /** | 27 /** |
28 * Private constructor that shouldn't be used externally. Use [wrap] to ensure | 28 * Private constructor that shouldn't be used externally. Use [wrap] to ensure |
29 * that a batch exists when running a function. | 29 * that a batch exists when running a function. |
30 */ | 30 */ |
31 EventBatch._internal() : summaries = new Map<int, EventSummary>(); | 31 EventBatch._internal() : summaries = new Map<int, EventSummary>(); |
32 | 32 |
33 /** | 33 /** |
34 * Ensure there is an event batch where [userFunction] can accumuluate events. | 34 * Ensure there is an event batch where [userFunction] can accumulate events. |
35 * When the batch is complete, fire all events at once. | 35 * When the batch is complete, fire all events at once. |
36 */ | 36 */ |
37 static Function wrap(userFunction(var a)) { | 37 static Function wrap(userFunction(var a)) { |
38 return (e) { | 38 return (e) { |
39 if (current == null) { | 39 if (current == null) { |
40 // Not in a batch so create one. | 40 // Not in a batch so create one. |
41 final batch = new EventBatch._internal(); | 41 final batch = new EventBatch._internal(); |
42 current = batch; | 42 current = batch; |
43 var result = null; | 43 var result = null; |
44 try { | 44 try { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 /** Fires all events at once. */ | 97 /** Fires all events at once. */ |
98 void _notify() { | 98 void _notify() { |
99 assert(!sealed); | 99 assert(!sealed); |
100 sealed = true; | 100 sealed = true; |
101 for (final summary in summaries.values) { | 101 for (final summary in summaries.values) { |
102 summary.notify(); | 102 summary.notify(); |
103 } | 103 } |
104 } | 104 } |
105 } | 105 } |
OLD | NEW |