Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(579)

Side by Side Diff: pkg/mdv/test/mdv_test_utils.dart

Issue 19771010: implement dirty checking for @observable objects (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library observe_utils;
6
7 import 'dart:async';
8 import 'package:observe/observe.dart';
9 import 'package:unittest/unittest.dart';
10
11 toSymbolMap(Map map) {
12 var result = new ObservableMap.linked();
13 map.forEach((key, value) {
14 if (value is Map) value = toSymbolMap(value);
15 result[new Symbol(key)] = value;
16 });
17 return result;
18 }
19
20 class FooBarModel extends ObservableBase {
21 @observable var foo;
22 @observable var bar;
23
24 FooBarModel([this.foo, this.bar]);
25 }
26
27 class FooBarNotifyModel extends ChangeNotifierBase implements FooBarModel {
28 var _foo;
29 var _bar;
30
31 FooBarNotifyModel([this._foo, this._bar]);
32
33 get foo => _foo;
34 set foo(value) {
35 _foo = notifyPropertyChange(const Symbol('foo'), _foo, value);
36 }
37
38 get bar => _bar;
39 set bar(value) {
40 _bar = notifyPropertyChange(const Symbol('bar'), _bar, value);
41 }
42 }
43
44 // TODO(jmesserly): this is a copy/paste from observe_test_utils.dart
45 // Is it worth putting it in its own package, or in an existing one?
46
47 void performMicrotaskCheckpoint() {
Jennifer Messerly 2013/07/19 01:32:58 went with this name to match change_summary & MDV
48 Observable.dirtyCheck();
49
50 while (_pending.length > 0) {
51 var pending = _pending;
52 _pending = [];
53
54 for (var callback in pending) {
55 try {
56 callback();
57 } catch (e, s) {
58 new Completer().completeError(e, s);
59 }
60 }
61
62 Observable.dirtyCheck();
63 }
64 }
65
66 List<Function> _pending = [];
67
68 wrapMicrotask(void testCase()) {
69 return () {
70 runZonedExperimental(() {
71 try {
72 testCase();
73 } finally {
74 performMicrotaskCheckpoint();
75 }
76 }, onRunAsync: (callback) => _pending.add(callback));
77 };
78 }
79
80 observeTest(name, testCase) => test(name, wrapMicrotask(testCase));
81
82 solo_observeTest(name, testCase) => solo_test(name, wrapMicrotask(testCase));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698