| 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 'package:observe/observe.dart'; | 5 import 'package:observe/observe.dart'; |
| 6 import 'package:unittest/unittest.dart'; | 6 import 'package:unittest/unittest.dart'; |
| 7 import 'observe_test_utils.dart'; | 7 import 'observe_test_utils.dart'; |
| 8 | 8 |
| 9 // This file contains code ported from: | 9 // This file contains code ported from: |
| 10 // https://github.com/rafaelw/ChangeSummary/blob/master/tests/test.js | 10 // https://github.com/rafaelw/ChangeSummary/blob/master/tests/test.js |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 145 |
| 146 observeTest('Path Value With Indices', () { | 146 observeTest('Path Value With Indices', () { |
| 147 var model = toObservable([]); | 147 var model = toObservable([]); |
| 148 var path = observePath(model, '0'); | 148 var path = observePath(model, '0'); |
| 149 path.changes.listen(expectAsync1((_) { | 149 path.changes.listen(expectAsync1((_) { |
| 150 expect(path.value, 123); | 150 expect(path.value, 123); |
| 151 })); | 151 })); |
| 152 model.add(123); | 152 model.add(123); |
| 153 }); | 153 }); |
| 154 | 154 |
| 155 group('ObservableList', () { |
| 156 observeTest('isNotEmpty', () { |
| 157 var model = new ObservableList(); |
| 158 var path = observePath(model, 'isNotEmpty'); |
| 159 expect(path.value, false); |
| 160 |
| 161 var future = path.changes.first.then((_) { |
| 162 expect(path.value, true); |
| 163 }); |
| 164 model.add(123); |
| 165 |
| 166 return future; |
| 167 }); |
| 168 |
| 169 observeTest('isEmpty', () { |
| 170 var model = new ObservableList(); |
| 171 var path = observePath(model, 'isEmpty'); |
| 172 expect(path.value, true); |
| 173 |
| 174 var future = path.changes.first.then((_) { |
| 175 expect(path.value, false); |
| 176 }); |
| 177 model.add(123); |
| 178 |
| 179 return future; |
| 180 }); |
| 181 }); |
| 182 |
| 155 for (var createModel in [() => new TestModel(), () => new WatcherModel()]) { | 183 for (var createModel in [() => new TestModel(), () => new WatcherModel()]) { |
| 156 observeTest('Path Observation - ${createModel().runtimeType}', () { | 184 observeTest('Path Observation - ${createModel().runtimeType}', () { |
| 157 var model = createModel()..a = | 185 var model = createModel()..a = |
| 158 (createModel()..b = (createModel()..c = 'hello, world')); | 186 (createModel()..b = (createModel()..c = 'hello, world')); |
| 159 | 187 |
| 160 var path = observePath(model, 'a.b.c'); | 188 var path = observePath(model, 'a.b.c'); |
| 161 var lastValue = null; | 189 var lastValue = null; |
| 162 var sub = path.changes.listen((_) { lastValue = path.value; }); | 190 var sub = path.changes.listen((_) { lastValue = path.value; }); |
| 163 | 191 |
| 164 model.a.b.c = 'hello, mom'; | 192 model.a.b.c = 'hello, mom'; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 369 |
| 342 class WatcherModel extends Observable { | 370 class WatcherModel extends Observable { |
| 343 // TODO(jmesserly): dart2js does not let these be on the same line: | 371 // TODO(jmesserly): dart2js does not let these be on the same line: |
| 344 // @observable var a, b, c; | 372 // @observable var a, b, c; |
| 345 @observable var a; | 373 @observable var a; |
| 346 @observable var b; | 374 @observable var b; |
| 347 @observable var c; | 375 @observable var c; |
| 348 | 376 |
| 349 WatcherModel(); | 377 WatcherModel(); |
| 350 } | 378 } |
| OLD | NEW |