| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'package:logging/logging.dart'; | 6 import 'package:logging/logging.dart'; |
| 7 import 'package:observe/observe.dart'; | 7 import 'package:observe/observe.dart'; |
| 8 import 'package:observe/src/dirty_check.dart' as dirty_check; | 8 import 'package:observe/src/dirty_check.dart' as dirty_check; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 import 'observe_test_utils.dart'; | 10 import 'observe_test_utils.dart'; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 final watch = createModel(null) is! ChangeNotifierMixin; | 66 final watch = createModel(null) is! ChangeNotifierMixin; |
| 67 | 67 |
| 68 // Track the subscriptions so we can clean them up in tearDown. | 68 // Track the subscriptions so we can clean them up in tearDown. |
| 69 List subs; | 69 List subs; |
| 70 | 70 |
| 71 int initialObservers; | 71 int initialObservers; |
| 72 setUp(() { | 72 setUp(() { |
| 73 initialObservers = dirty_check.allObservablesCount; | 73 initialObservers = dirty_check.allObservablesCount; |
| 74 subs = []; | 74 subs = []; |
| 75 | 75 |
| 76 if (watch) runAsync(Observable.dirtyCheck); | 76 if (watch) scheduleMicrotask(Observable.dirtyCheck); |
| 77 }); | 77 }); |
| 78 | 78 |
| 79 tearDown(() { | 79 tearDown(() { |
| 80 for (var sub in subs) sub.cancel(); | 80 for (var sub in subs) sub.cancel(); |
| 81 performMicrotaskCheckpoint(); | 81 performMicrotaskCheckpoint(); |
| 82 | 82 |
| 83 expect(dirty_check.allObservablesCount, initialObservers, | 83 expect(dirty_check.allObservablesCount, initialObservers, |
| 84 reason: 'Observable object leaked'); | 84 reason: 'Observable object leaked'); |
| 85 }); | 85 }); |
| 86 | 86 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 expectChanges(records, _changedValue(1)); | 172 expectChanges(records, _changedValue(1)); |
| 173 }); | 173 }); |
| 174 | 174 |
| 175 observeTest('cancel listening', () { | 175 observeTest('cancel listening', () { |
| 176 var t = createModel(123); | 176 var t = createModel(123); |
| 177 var sub; | 177 var sub; |
| 178 sub = t.changes.listen(expectAsync1((records) { | 178 sub = t.changes.listen(expectAsync1((records) { |
| 179 expectChanges(records, _changedValue(1)); | 179 expectChanges(records, _changedValue(1)); |
| 180 sub.cancel(); | 180 sub.cancel(); |
| 181 t.value = 777; | 181 t.value = 777; |
| 182 runAsync(Observable.dirtyCheck); | 182 scheduleMicrotask(Observable.dirtyCheck); |
| 183 })); | 183 })); |
| 184 t.value = 42; | 184 t.value = 42; |
| 185 }); | 185 }); |
| 186 | 186 |
| 187 observeTest('cancel and reobserve', () { | 187 observeTest('cancel and reobserve', () { |
| 188 var t = createModel(123); | 188 var t = createModel(123); |
| 189 var sub; | 189 var sub; |
| 190 sub = t.changes.listen(expectAsync1((records) { | 190 sub = t.changes.listen(expectAsync1((records) { |
| 191 expectChanges(records, _changedValue(1)); | 191 expectChanges(records, _changedValue(1)); |
| 192 sub.cancel(); | 192 sub.cancel(); |
| 193 | 193 |
| 194 runAsync(expectAsync0(() { | 194 scheduleMicrotask(expectAsync0(() { |
| 195 subs.add(t.changes.listen(expectAsync1((records) { | 195 subs.add(t.changes.listen(expectAsync1((records) { |
| 196 expectChanges(records, _changedValue(1)); | 196 expectChanges(records, _changedValue(1)); |
| 197 }))); | 197 }))); |
| 198 t.value = 777; | 198 t.value = 777; |
| 199 runAsync(Observable.dirtyCheck); | 199 scheduleMicrotask(Observable.dirtyCheck); |
| 200 })); | 200 })); |
| 201 })); | 201 })); |
| 202 t.value = 42; | 202 t.value = 42; |
| 203 }); | 203 }); |
| 204 | 204 |
| 205 observeTest('cannot modify changes list', () { | 205 observeTest('cannot modify changes list', () { |
| 206 var t = createModel(123); | 206 var t = createModel(123); |
| 207 var records = null; | 207 var records = null; |
| 208 subs.add(t.changes.listen((r) { records = r; })); | 208 subs.add(t.changes.listen((r) { records = r; })); |
| 209 t.value = 42; | 209 t.value = 42; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 @observable T value; | 253 @observable T value; |
| 254 | 254 |
| 255 WatcherModel([T initialValue]) : value = initialValue; | 255 WatcherModel([T initialValue]) : value = initialValue; |
| 256 | 256 |
| 257 String toString() => '#<$runtimeType value: $value>'; | 257 String toString() => '#<$runtimeType value: $value>'; |
| 258 } | 258 } |
| 259 | 259 |
| 260 class ModelSubclass<T> extends WatcherModel<T> { | 260 class ModelSubclass<T> extends WatcherModel<T> { |
| 261 ModelSubclass([T initialValue]) : super(initialValue); | 261 ModelSubclass([T initialValue]) : super(initialValue); |
| 262 } | 262 } |
| OLD | NEW |