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

Side by Side Diff: samples/ui_lib/observable/ChangeEvent.dart

Issue 10943034: Issue 5162. Report error when initializing already initialized final field (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 /** A change to an observable instance. */ 5 /** A change to an observable instance. */
6 class ChangeEvent { 6 class ChangeEvent {
7 // TODO(sigmund): capture language issues around enums & create a cannonical 7 // TODO(sigmund): capture language issues around enums & create a cannonical
8 // Dart enum design. 8 // Dart enum design.
9 /** Type denoting an in-place update event. */ 9 /** Type denoting an in-place update event. */
10 static const UPDATE = 0; 10 static const UPDATE = 0;
(...skipping 10 matching lines...) Expand all
21 */ 21 */
22 static const GLOBAL = 3; 22 static const GLOBAL = 3;
23 23
24 /** The observable instance that changed. */ 24 /** The observable instance that changed. */
25 final Observable target; 25 final Observable target;
26 26
27 /** Whether the change was an [INSERT], [REMOVE], or [UPDATE]. */ 27 /** Whether the change was an [INSERT], [REMOVE], or [UPDATE]. */
28 final int type; 28 final int type;
29 29
30 /** The value after the change (or inserted value in a list). */ 30 /** The value after the change (or inserted value in a list). */
31 final newValue = null; 31 final newValue;
32 32
33 /** The value before the change (or removed value from a list). */ 33 /** The value before the change (or removed value from a list). */
34 final oldValue = null; 34 final oldValue;
35 35
36 /** Property that changed (null for list changes). */ 36 /** Property that changed (null for list changes). */
37 final String propertyName = null; 37 final String propertyName;
38 38
39 /** 39 /**
40 * Index of the list operation. Insertions prepend in front of the given 40 * Index of the list operation. Insertions prepend in front of the given
41 * index (insert at 0 means an insertion at the beginning of the list). 41 * index (insert at 0 means an insertion at the beginning of the list).
42 */ 42 */
43 final int index = null; 43 final int index;
44 44
45 /** Factory constructor for property change events. */ 45 /** Factory constructor for property change events. */
46 ChangeEvent.property( 46 ChangeEvent.property(
47 this.target, this.propertyName, this.newValue, this.oldValue) 47 this.target, this.propertyName, this.newValue, this.oldValue)
48 : type = UPDATE; 48 : type = UPDATE, index = null;
49 49
50 /** Factory constructor for list change events. */ 50 /** Factory constructor for list change events. */
51 ChangeEvent.list( 51 ChangeEvent.list(
52 this.target, this.type, this.index, this.newValue, this.oldValue); 52 this.target, this.type, this.index, this.newValue, this.oldValue)
53 : propertyName = null;
53 54
54 /** Factory constructor for [GLOBAL] change events. */ 55 /** Factory constructor for [GLOBAL] change events. */
55 ChangeEvent.global(this.target) : type = GLOBAL; 56 ChangeEvent.global(this.target)
57 : type = GLOBAL, newValue = null, oldValue = null, propertyName = null, inde x = null;
56 } 58 }
57 59
58 /** A collection of change events on a single observable instance. */ 60 /** A collection of change events on a single observable instance. */
59 class EventSummary { 61 class EventSummary {
60 final Observable target; 62 final Observable target;
61 63
62 // TODO(sigmund): evolve this to track changes per property. 64 // TODO(sigmund): evolve this to track changes per property.
63 List<ChangeEvent> events; 65 List<ChangeEvent> events;
64 66
65 EventSummary(this.target) : events = new List<ChangeEvent>(); 67 EventSummary(this.target) : events = new List<ChangeEvent>();
66 68
67 void addEvent(ChangeEvent e) { 69 void addEvent(ChangeEvent e) {
68 events.add(e); 70 events.add(e);
69 } 71 }
70 72
71 /** Notify listeners of [target] and parents of [target] about all changes. */ 73 /** Notify listeners of [target] and parents of [target] about all changes. */
72 void notify() { 74 void notify() {
73 if (!events.isEmpty()) { 75 if (!events.isEmpty()) {
74 for (Observable obj = target; obj != null; obj = obj.parent) { 76 for (Observable obj = target; obj != null; obj = obj.parent) {
75 for (final listener in obj.listeners) { 77 for (final listener in obj.listeners) {
76 listener(this); 78 listener(this);
77 } 79 }
78 } 80 }
79 } 81 }
80 } 82 }
81 } 83 }
82 84
83 /** A listener of change events. */ 85 /** A listener of change events. */
84 typedef void ChangeListener(EventSummary events); 86 typedef void ChangeListener(EventSummary events);
OLDNEW
« no previous file with comments | « compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java ('k') | tests/co19/co19-compiler.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698