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 /** | 5 /** |
6 * This library is used to implement [Observable] types. | 6 * This library is used to implement [Observable] types. |
7 * | 7 * |
8 * It exposes lower level functionality such as [hasObservers], [observeReads] | 8 * It exposes lower level functionality such as [hasObservers], [observeReads] |
9 * [notifyChange] and [notifyRead]. | 9 * [notifyChange] and [notifyRead]. |
10 * | 10 * |
11 * Unless you are mixing in [Observable], it is usually better to write: | 11 * Unless you are mixing in [Observable], it is usually better to write: |
12 * | 12 * |
13 * import 'package:web_ui/observe.dart'; | 13 * import 'package:web_ui/observe.dart'; |
14 */ | 14 */ |
15 library web_ui.observe.observable; | 15 library web_ui.observe.observable; |
16 | 16 |
17 import 'dart:async'; | 17 import 'dart:async'; |
18 import 'dart:collection' hide LinkedList; | 18 import 'dart:collection' hide LinkedList; |
19 import 'list.dart'; | 19 import 'list.dart'; |
20 import 'map.dart'; | 20 import 'map.dart'; |
21 import 'reference.dart'; | |
22 import 'set.dart'; | 21 import 'set.dart'; |
23 import 'package:web_ui/src/utils_observe.dart' show hash3, hash4; | 22 import 'package:web_ui/src/utils_observe.dart' show hash3, hash4; |
24 import 'package:web_ui/src/linked_list.dart'; | 23 import 'package:web_ui/src/linked_list.dart'; |
25 | 24 |
26 /** | 25 /** |
27 * Use `@observable` to make a class observable. All fields in the class will | 26 * Use `@observable` to make a class observable. All fields in the class will |
28 * be transformed to track changes. The overhead will be minimal unless they are | 27 * be transformed to track changes. The overhead will be minimal unless they are |
29 * actually being observed. | 28 * actually being observed. |
30 */ | 29 */ |
31 const observable = const _ObservableAnnotation(); | 30 const observable = const _ObservableAnnotation(); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 | 337 |
339 // If this is an assignment (and not insert/remove) then check if | 338 // If this is an assignment (and not insert/remove) then check if |
340 // the value actually changed. If not don't signal a change event. | 339 // the value actually changed. If not don't signal a change event. |
341 // This helps programmers avoid some common cases of cycles in their code. | 340 // This helps programmers avoid some common cases of cycles in their code. |
342 if ((type & (ChangeRecord.INSERT | ChangeRecord.REMOVE)) == 0) { | 341 if ((type & (ChangeRecord.INSERT | ChangeRecord.REMOVE)) == 0) { |
343 if (oldValue == newValue) return; | 342 if (oldValue == newValue) return; |
344 } | 343 } |
345 | 344 |
346 if (_changedObjects == null) { | 345 if (_changedObjects == null) { |
347 _changedObjects = []; | 346 _changedObjects = []; |
348 runAsync(deliverChangesSync); | 347 scheduleMicrotask(deliverChangesSync); |
349 } | 348 } |
350 if (self.$_changes == null) { | 349 if (self.$_changes == null) { |
351 self.$_changes = []; | 350 self.$_changes = []; |
352 _changedObjects.add(self); | 351 _changedObjects.add(self); |
353 } | 352 } |
354 self.$_changes.add(new ChangeRecord(type, key, oldValue, newValue)); | 353 self.$_changes.add(new ChangeRecord(type, key, oldValue, newValue)); |
355 } | 354 } |
356 | 355 |
357 // Optimizations to avoid extra work if observing const/final data. | 356 // Optimizations to avoid extra work if observing const/final data. |
358 void _doNothing() {} | 357 void _doNothing() {} |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 /** | 686 /** |
688 * The type of the `@observable` annotation. | 687 * The type of the `@observable` annotation. |
689 * | 688 * |
690 * Library private because you should be able to use the [observable] field | 689 * Library private because you should be able to use the [observable] field |
691 * to get the one and only instance. We could make it public though, if anyone | 690 * to get the one and only instance. We could make it public though, if anyone |
692 * needs it for some reason. | 691 * needs it for some reason. |
693 */ | 692 */ |
694 class _ObservableAnnotation { | 693 class _ObservableAnnotation { |
695 const _ObservableAnnotation(); | 694 const _ObservableAnnotation(); |
696 } | 695 } |
OLD | NEW |