OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 library observe.src.change_notifier; | 5 library observe.src.change_notifier; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection' show UnmodifiableListView; | 8 import 'dart:collection' show UnmodifiableListView; |
9 import 'package:observe/observe.dart'; | 9 import 'package:observe/observe.dart'; |
10 import 'package:observe/src/observable.dart' show notifyPropertyChangeHelper; | 10 import 'package:observe/src/observable.dart' show notifyPropertyChangeHelper; |
(...skipping 22 matching lines...) Expand all Loading... |
33 // for subclasses. Ideally they'd be protected. | 33 // for subclasses. Ideally they'd be protected. |
34 /** | 34 /** |
35 * Override this method to be called when the [changes] are first observed. | 35 * Override this method to be called when the [changes] are first observed. |
36 */ | 36 */ |
37 void observed() {} | 37 void observed() {} |
38 | 38 |
39 /** | 39 /** |
40 * Override this method to be called when the [changes] are no longer being | 40 * Override this method to be called when the [changes] are no longer being |
41 * observed. | 41 * observed. |
42 */ | 42 */ |
43 void unobserved() {} | 43 void unobserved() { |
| 44 // Free some memory |
| 45 _changes = null; |
| 46 } |
44 | 47 |
45 bool deliverChanges() { | 48 bool deliverChanges() { |
46 var records = _records; | 49 var records = _records; |
47 _records = null; | 50 _records = null; |
48 if (hasObservers && records != null) { | 51 if (hasObservers && records != null) { |
49 _changes.add(new UnmodifiableListView<ChangeRecord>(records)); | 52 _changes.add(new UnmodifiableListView<ChangeRecord>(records)); |
50 return true; | 53 return true; |
51 } | 54 } |
52 return false; | 55 return false; |
53 } | 56 } |
(...skipping 25 matching lines...) Expand all Loading... |
79 void notifyChange(ChangeRecord record) { | 82 void notifyChange(ChangeRecord record) { |
80 if (!hasObservers) return; | 83 if (!hasObservers) return; |
81 | 84 |
82 if (_records == null) { | 85 if (_records == null) { |
83 _records = []; | 86 _records = []; |
84 scheduleMicrotask(deliverChanges); | 87 scheduleMicrotask(deliverChanges); |
85 } | 88 } |
86 _records.add(record); | 89 _records.add(record); |
87 } | 90 } |
88 } | 91 } |
OLD | NEW |