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 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 Loading... |
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.multiplex(onListen: _observe, | 75 _values = new StreamController(onListen: _observe, onCancel: _unobserve); |
76 onCancel: _unobserve); | |
77 | 76 |
78 if (_isValid) { | 77 if (_isValid) { |
79 var segments = []; | 78 var segments = []; |
80 for (var segment in path.trim().split('.')) { | 79 for (var segment in path.trim().split('.')) { |
81 if (segment == '') continue; | 80 if (segment == '') continue; |
82 var index = int.parse(segment, onError: (_) {}); | 81 var index = int.parse(segment, onError: (_) {}); |
83 segments.add(index != null ? index : new Symbol(segment)); | 82 segments.add(index != null ? index : new Symbol(segment)); |
84 } | 83 } |
85 | 84 |
86 // Create the property observer linked list. | 85 // Create the property observer linked list. |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 277 |
279 final _spacesRegExp = new RegExp(r'\s'); | 278 final _spacesRegExp = new RegExp(r'\s'); |
280 | 279 |
281 bool _isPathValid(String s) { | 280 bool _isPathValid(String s) { |
282 s = s.replaceAll(_spacesRegExp, ''); | 281 s = s.replaceAll(_spacesRegExp, ''); |
283 | 282 |
284 if (s == '') return true; | 283 if (s == '') return true; |
285 if (s[0] == '.') return false; | 284 if (s[0] == '.') return false; |
286 return _pathRegExp.hasMatch(s); | 285 return _pathRegExp.hasMatch(s); |
287 } | 286 } |
OLD | NEW |