| 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 'observe_test_utils.dart'; | 9 import 'observe_test_utils.dart'; |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 }); | 42 }); |
| 43 | 43 |
| 44 tearDown(() { | 44 tearDown(() { |
| 45 subscription.cancel(); | 45 subscription.cancel(); |
| 46 }); | 46 }); |
| 47 | 47 |
| 48 test('logs debug information', () { | 48 test('logs debug information', () { |
| 49 var maxNumIterations = dirty_check.MAX_DIRTY_CHECK_CYCLES; | 49 var maxNumIterations = dirty_check.MAX_DIRTY_CHECK_CYCLES; |
| 50 | 50 |
| 51 var x = new WatcherModel(0); | 51 var x = new WatcherModel(0); |
| 52 var sub = x.changes.listen(expectAsync((_) { | 52 int called = 0; |
| 53 var sub = x.changes.listen((_) { |
| 54 called++; |
| 53 x.value++; | 55 x.value++; |
| 54 }, count: maxNumIterations)); | 56 }); |
| 55 x.value = 1; | 57 x.value = 1; |
| 56 Observable.dirtyCheck(); | 58 Observable.dirtyCheck(); |
| 59 expect(called, maxNumIterations); |
| 57 expect(x.value, maxNumIterations + 1); | 60 expect(x.value, maxNumIterations + 1); |
| 58 expect(messages.length, 2); | 61 expect(messages.length, 2); |
| 59 | 62 |
| 60 expect(messages[0], contains('Possible loop')); | 63 expect(messages[0], contains('Possible loop')); |
| 61 expect(messages[1], contains('index 0')); | 64 expect(messages[1], contains('index 0')); |
| 62 expect(messages[1], contains('object: $x')); | 65 expect(messages[1], contains('object: $x')); |
| 63 | 66 |
| 64 sub.cancel(); | 67 sub.cancel(); |
| 65 }); | 68 }); |
| 66 }); | 69 }); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 t.value = 42; | 193 t.value = 42; |
| 191 }); | 194 }); |
| 192 | 195 |
| 193 test('cancel and reobserve', () { | 196 test('cancel and reobserve', () { |
| 194 var t = createModel(123); | 197 var t = createModel(123); |
| 195 var sub; | 198 var sub; |
| 196 sub = t.changes.listen(expectAsync((records) { | 199 sub = t.changes.listen(expectAsync((records) { |
| 197 expectPropertyChanges(records, 1); | 200 expectPropertyChanges(records, 1); |
| 198 sub.cancel(); | 201 sub.cancel(); |
| 199 | 202 |
| 200 scheduleMicrotask(expectAsync(() { | 203 scheduleMicrotask(() { |
| 201 subs.add(t.changes.listen(expectAsync((records) { | 204 subs.add(t.changes.listen(expectAsync((records) { |
| 202 expectPropertyChanges(records, 1); | 205 expectPropertyChanges(records, 1); |
| 203 }))); | 206 }))); |
| 204 t.value = 777; | 207 t.value = 777; |
| 205 scheduleMicrotask(Observable.dirtyCheck); | 208 scheduleMicrotask(Observable.dirtyCheck); |
| 206 })); | 209 }); |
| 207 })); | 210 })); |
| 208 t.value = 42; | 211 t.value = 42; |
| 209 }); | 212 }); |
| 210 | 213 |
| 211 test('cannot modify changes list', () { | 214 test('cannot modify changes list', () { |
| 212 var t = createModel(123); | 215 var t = createModel(123); |
| 213 var records = null; | 216 var records = null; |
| 214 subs.add(t.changes.listen((r) { | 217 subs.add(t.changes.listen((r) { |
| 215 records = r; | 218 records = r; |
| 216 })); | 219 })); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 @observable T value; | 283 @observable T value; |
| 281 | 284 |
| 282 WatcherModel([T initialValue]) : value = initialValue; | 285 WatcherModel([T initialValue]) : value = initialValue; |
| 283 | 286 |
| 284 String toString() => '#<$runtimeType value: $value>'; | 287 String toString() => '#<$runtimeType value: $value>'; |
| 285 } | 288 } |
| 286 | 289 |
| 287 class ModelSubclass<T> extends WatcherModel<T> { | 290 class ModelSubclass<T> extends WatcherModel<T> { |
| 288 ModelSubclass([T initialValue]) : super(initialValue); | 291 ModelSubclass([T initialValue]) : super(initialValue); |
| 289 } | 292 } |
| OLD | NEW |