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

Side by Side Diff: pkg/observe/lib/src/observable.dart

Issue 20886002: add custom_element package (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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
« no previous file with comments | « pkg/mdv/test/analyzer_test.dart ('k') | pkg/observe/lib/src/observable_map.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 part of observe; 5 part of observe;
6 6
7 /** 7 /**
8 * Use `@observable` to make a field automatically observable. 8 * Use `@observable` to make a field automatically observable.
9 */ 9 */
10 const Object observable = const _ObservableAnnotation(); 10 const Object observable = const _ObservableAnnotation();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 /** 56 /**
57 * Notify observers of a change. 57 * Notify observers of a change.
58 * 58 *
59 * For most objects [ObservableMixin.notifyPropertyChange] is more 59 * For most objects [ObservableMixin.notifyPropertyChange] is more
60 * convenient, but collections sometimes deliver other types of changes such 60 * convenient, but collections sometimes deliver other types of changes such
61 * as a [ListChangeRecord]. 61 * as a [ListChangeRecord].
62 */ 62 */
63 void notifyChange(ChangeRecord record); 63 void notifyChange(ChangeRecord record);
64 64
65 /** 65 /**
66 * True if this object has any observers, and should call
67 * [notifyChange] for changes.
68 */
69 bool get hasObservers;
70
71 /**
66 * Performs dirty checking of objects that inherit from [ObservableMixin]. 72 * Performs dirty checking of objects that inherit from [ObservableMixin].
67 * This scans all observed objects using mirrors and determines if any fields 73 * This scans all observed objects using mirrors and determines if any fields
68 * have changed. If they have, it delivers the changes for the object. 74 * have changed. If they have, it delivers the changes for the object.
69 */ 75 */
70 static void dirtyCheck() => dirtyCheckObservables(); 76 static void dirtyCheck() => dirtyCheckObservables();
71 } 77 }
72 78
73 /** 79 /**
74 * Base class implementing [Observable]. 80 * Base class implementing [Observable].
75 * 81 *
(...skipping 16 matching lines...) Expand all
92 List<ChangeRecord> _records; 98 List<ChangeRecord> _records;
93 99
94 Stream<List<ChangeRecord>> get changes { 100 Stream<List<ChangeRecord>> get changes {
95 if (_changes == null) { 101 if (_changes == null) {
96 _changes = new StreamController.broadcast(sync: true, 102 _changes = new StreamController.broadcast(sync: true,
97 onListen: _observed, onCancel: _unobserved); 103 onListen: _observed, onCancel: _unobserved);
98 } 104 }
99 return _changes.stream; 105 return _changes.stream;
100 } 106 }
101 107
102 /**
103 * True if this object has any observers, and should call
104 * [notifyPropertyChange] for changes.
105 */
106 bool get hasObservers => _changes != null && _changes.hasListener; 108 bool get hasObservers => _changes != null && _changes.hasListener;
107 109
108 void _observed() { 110 void _observed() {
109 // Register this object for dirty checking purposes. 111 // Register this object for dirty checking purposes.
110 registerObservable(this); 112 registerObservable(this);
111 113
112 var mirror = reflect(this); 114 var mirror = reflect(this);
113 var values = new Map<Symbol, Object>(); 115 var values = new Map<Symbol, Object>();
114 116
115 // TODO(jmesserly): this should consider the superclass. Unfortunately 117 // TODO(jmesserly): this should consider the superclass. Unfortunately
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 /** 209 /**
208 * The type of the `@observable` annotation. 210 * The type of the `@observable` annotation.
209 * 211 *
210 * Library private because you should be able to use the [observable] field 212 * Library private because you should be able to use the [observable] field
211 * to get the one and only instance. We could make it public though, if anyone 213 * to get the one and only instance. We could make it public though, if anyone
212 * needs it for some reason. 214 * needs it for some reason.
213 */ 215 */
214 class _ObservableAnnotation { 216 class _ObservableAnnotation {
215 const _ObservableAnnotation(); 217 const _ObservableAnnotation();
216 } 218 }
OLDNEW
« no previous file with comments | « pkg/mdv/test/analyzer_test.dart ('k') | pkg/observe/lib/src/observable_map.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698