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

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

Issue 27618002: package:observe fix various api issues (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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/observe/lib/observe.dart ('k') | pkg/observe/lib/src/change_notifier.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 * Forwards an observable property from one object to another. For example: 8 * Forwards an observable property from one object to another. For example:
9 * 9 *
10 * class MyModel extends ObservableBase { 10 * class MyModel extends Observable {
11 * StreamSubscription _sub; 11 * StreamSubscription _sub;
12 * MyOtherModel _otherModel; 12 * MyOtherModel _otherModel;
13 * 13 *
14 * MyModel() { 14 * MyModel() {
15 * ... 15 * ...
16 * _sub = onPropertyChange(_otherModel, #value, 16 * _sub = onPropertyChange(_otherModel, #value,
17 * () => notifyProperty(this, #prop); 17 * () => notifyProperty(this, #prop);
18 * } 18 * }
19 * 19 *
20 * String get prop => _otherModel.value; 20 * String get prop => _otherModel.value;
21 * set prop(String value) { _otherModel.value = value; } 21 * set prop(String value) { _otherModel.value = value; }
22 * } 22 * }
23 * 23 *
24 * See also [notifyProperty]. 24 * See also [notifyProperty].
25 */ 25 */
26 // TODO(jmesserly): make this an instance method? 26 // TODO(jmesserly): make this an instance method?
27 StreamSubscription onPropertyChange(Observable source, Symbol sourceName, 27 StreamSubscription onPropertyChange(Observable source, Symbol sourceName,
28 void callback()) { 28 void callback()) {
29 return source.changes.listen((records) { 29 return source.changes.listen((records) {
30 for (var record in records) { 30 for (var record in records) {
31 if (record.changes(sourceName)) { 31 if (record is PropertyChangeRecord &&
32 (record as PropertyChangeRecord).name == sourceName) {
32 callback(); 33 callback();
34 break;
33 } 35 }
34 } 36 }
35 }); 37 });
36 } 38 }
OLDNEW
« no previous file with comments | « pkg/observe/lib/observe.dart ('k') | pkg/observe/lib/src/change_notifier.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698