| 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 library observe.src.bindable; | 5 library observe.src.bindable; |
| 6 | 6 |
| 7 /// An object that can be data bound. | 7 /// An object that can be data bound. |
| 8 // Normally this is used with 'package:template_binding'. | 8 // Normally this is used with 'package:template_binding'. |
| 9 // TODO(jmesserly): Node.bind polyfill calls this "observable" | 9 // TODO(jmesserly): Node.bind polyfill calls this "observable" |
| 10 abstract class Bindable { | 10 abstract class Bindable { |
| 11 // TODO(jmesserly): since we have "value", should open be a void method? | 11 // TODO(jmesserly): since we have "value", should open be a void method? |
| 12 // TODO(jmesserly): not sure how I feel about open taking a variable number | 12 // Dart note: changed setValue to be "set value" and discardChanges() to |
| 13 // of arguments, but it's the easiest way to make CompoundObserver work. | 13 // be "get value". Also "set value" implies discard changes. |
| 14 // TOOD(jmesserly): is this change too subtle? Is there any other way to |
| 15 // make Bindable friendly in a world with getters/setters? |
| 14 | 16 |
| 15 /// Initiates observation and returns the initial value. | 17 /// Initiates observation and returns the initial value. |
| 16 /// The callback will be called with the updated [value]. | 18 /// The callback will be called with the updated [value]. |
| 17 /// | 19 /// |
| 18 /// Some subtypes may chose to provide additional arguments, such as | 20 /// Some subtypes may chose to provide additional arguments, such as |
| 19 /// [PathObserver] providing the old value as the second argument. | 21 /// [PathObserver] providing the old value as the second argument. |
| 20 /// However, they must support callbacks with as few as 0 or 1 argument. | 22 /// However, they must support callbacks with as few as 0 or 1 argument. |
| 21 /// This can be implemented by performing an "is" type test on the callback. | 23 /// This can be implemented by performing an "is" type test on the callback. |
| 22 open(callback); | 24 open(callback); |
| 23 | 25 |
| 24 /// Stops future notifications and frees the reference to the callback passed | 26 /// Stops future notifications and frees the reference to the callback passed |
| 25 /// to [open], so its memory can be collected even if this Bindable is alive. | 27 /// to [open], so its memory can be collected even if this Bindable is alive. |
| 26 void close(); | 28 void close(); |
| 27 | 29 |
| 28 /// Gets the current value of the bindings. | 30 /// Gets the current value of the bindings. |
| 29 get value; | 31 get value; |
| 30 | 32 |
| 31 /// This can be implemented for two-way bindings. By default does nothing. | 33 /// This can be implemented for two-way bindings. By default does nothing. |
| 32 /// Note: setting the value of a [Bindable] must not call the [callback] with | 34 /// Note: setting the value of a [Bindable] must not call the [callback] with |
| 33 /// the new value. Any pending change notifications must be discarded. | 35 /// the new value. Any pending change notifications must be discarded. |
| 34 set value(newValue) {} | 36 set value(newValue) {} |
| 35 } | 37 } |
| OLD | NEW |