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

Side by Side Diff: tools/dom/src/PathObserver.dart

Issue 16125005: Make new StreamController be async by default. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments Created 7 years, 6 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) 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 html; 5 part of html;
6 6
7 // This code is inspired by ChangeSummary: 7 // This code is inspired by ChangeSummary:
8 // https://github.com/rafaelw/ChangeSummary/blob/master/change_summary.js 8 // https://github.com/rafaelw/ChangeSummary/blob/master/change_summary.js
9 // ...which underlies MDV. Since we don't need the functionality of 9 // ...which underlies MDV. Since we don't need the functionality of
10 // ChangeSummary, we just implement what we need for data bindings. 10 // ChangeSummary, we just implement what we need for data bindings.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 * Observes [path] on [object] for changes. This returns an object that can be 65 * Observes [path] on [object] for changes. This returns an object that can be
66 * used to get the changes and get/set the value at this path. 66 * used to get the changes and get/set the value at this path.
67 * See [PathObserver.values] and [PathObserver.value]. 67 * See [PathObserver.values] and [PathObserver.value].
68 */ 68 */
69 PathObserver(this.object, String path) 69 PathObserver(this.object, String path)
70 : path = path, _isValid = _isPathValid(path) { 70 : path = path, _isValid = _isPathValid(path) {
71 71
72 // TODO(jmesserly): if the path is empty, or the object is! Observable, we 72 // TODO(jmesserly): if the path is empty, or the object is! Observable, we
73 // can optimize the PathObserver to be more lightweight. 73 // can optimize the PathObserver to be more lightweight.
74 74
75 _values = new StreamController.broadcast(onListen: _observe, 75 _values = new StreamController.broadcast(sync: true,
76 onListen: _observe,
76 onCancel: _unobserve); 77 onCancel: _unobserve);
77 78
78 if (_isValid) { 79 if (_isValid) {
79 var segments = []; 80 var segments = [];
80 for (var segment in path.trim().split('.')) { 81 for (var segment in path.trim().split('.')) {
81 if (segment == '') continue; 82 if (segment == '') continue;
82 var index = int.parse(segment, onError: (_) {}); 83 var index = int.parse(segment, onError: (_) {});
83 segments.add(index != null ? index : new Symbol(segment)); 84 segments.add(index != null ? index : new Symbol(segment));
84 } 85 }
85 86
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 279
279 final _spacesRegExp = new RegExp(r'\s'); 280 final _spacesRegExp = new RegExp(r'\s');
280 281
281 bool _isPathValid(String s) { 282 bool _isPathValid(String s) {
282 s = s.replaceAll(_spacesRegExp, ''); 283 s = s.replaceAll(_spacesRegExp, '');
283 284
284 if (s == '') return true; 285 if (s == '') return true;
285 if (s[0] == '.') return false; 286 if (s[0] == '.') return false;
286 return _pathRegExp.hasMatch(s); 287 return _pathRegExp.hasMatch(s);
287 } 288 }
OLDNEW
« no previous file with comments | « tools/dom/src/KeyboardEventStream.dart ('k') | tools/dom/templates/html/impl/impl_Geolocation.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698