| 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 template_binding; | 5 part of template_binding; |
| 6 | 6 |
| 7 /** Extensions to the [Node] API. */ | 7 /** Extensions to the [Node] API. */ |
| 8 class NodeBindExtension { | 8 class NodeBindExtension { |
| 9 final Node _node; | 9 final Node _node; |
| 10 | 10 |
| 11 /** | 11 /** |
| 12 * Gets the data bindings that are associated with this node, if any. | 12 * Gets the data bindings that are associated with this node, if any. |
| 13 * | 13 * |
| 14 * This starts out null, and if [enableBindingsReflection] is enabled, calls | 14 * This starts out null, and if [enableBindingsReflection] is enabled, calls |
| 15 * to [bind] will initialize this field and the binding. | 15 * to [bind] will initialize this field and the binding. |
| 16 */ | 16 */ |
| 17 // Dart note: in JS this has a trailing underscore, meaning "private". | 17 // Dart note: in JS this has a trailing underscore, meaning "private". |
| 18 // But in dart if we made it _bindings, it wouldn't be accessible at all. | 18 // But in dart if we made it _bindings, it wouldn't be accessible at all. |
| 19 // It is unfortunately needed to implement Node.bind correctly. | 19 // It is unfortunately needed to implement Node.bind correctly. |
| 20 Map<String, Bindable> bindings; | 20 Map<String, Bindable> bindings; |
| 21 | 21 |
| 22 NodeBindExtension._(this._node); | 22 NodeBindExtension._(this._node); |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * Binds the attribute [name] to the [path] of the [model]. | 25 * Binds the attribute [name] to [value]. [value] can be a simple value when |
| 26 * Path is a String of accessors such as `foo.bar.baz`. | 26 * [oneTime] is true, or a [Bindable] like [PathObserver]. |
| 27 * Returns the [Bindable] instance. | 27 * Returns the [Bindable] instance. |
| 28 */ | 28 */ |
| 29 Bindable bind(String name, value, {bool oneTime: false}) { | 29 Bindable bind(String name, value, {bool oneTime: false}) { |
| 30 // TODO(jmesserly): in Dart we could deliver an async error, which would | 30 // TODO(jmesserly): in Dart we could deliver an async error, which would |
| 31 // have a similar affect but be reported as a test failure. Should we? | 31 // have a similar affect but be reported as a test failure. Should we? |
| 32 window.console.error('Unhandled binding to Node: ' | 32 window.console.error('Unhandled binding to Node: ' |
| 33 '$this $name $value $oneTime'); | 33 '$this $name $value $oneTime'); |
| 34 return null; | 34 return null; |
| 35 } | 35 } |
| 36 | 36 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 */ | 87 */ |
| 88 Node get lastNode => _lastNode; | 88 Node get lastNode => _lastNode; |
| 89 | 89 |
| 90 /** The model used to instantiate the template. */ | 90 /** The model used to instantiate the template. */ |
| 91 final model; | 91 final model; |
| 92 | 92 |
| 93 Node _firstNode, _lastNode; | 93 Node _firstNode, _lastNode; |
| 94 | 94 |
| 95 TemplateInstance(this.model); | 95 TemplateInstance(this.model); |
| 96 } | 96 } |
| OLD | NEW |