OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 /// Code for property accessors from declaration/properties.js | |
6 part of polymer; | |
7 | |
8 // Dart note: this matches the property defined by createPropertyAccessor in | |
9 // polymer-dev/src/declarations/properties.js. Unlike Javascript, we can't | |
10 // override the original property, so we instead ask users to write properties | |
11 // using this pattern: | |
12 // | |
13 // class Foo extends PolymerElement { | |
14 // ... | |
15 // @published | |
16 // get foo => readValue(#foo); | |
17 // set foo(v) { writeValue(#foo, v); } | |
18 // | |
19 // and internally readValue/writeValue use an instance of this type to | |
20 // implement the semantics in createPropertyAccessor. | |
21 class _PropertyAccessor<T> { | |
22 // Name of the property, in order to properly fire change notification events. | |
23 final Symbol _name; | |
24 | |
25 /// The underlying value of the property. | |
26 T _value; | |
27 | |
28 // Polymer element that contains this property, where change notifications are | |
29 // expected to be fired from. | |
30 final Polymer _target; | |
31 | |
32 /// Non-null when the property is bound. | |
33 Bindable bindable; | |
34 | |
35 _PropertyAccessor(this._name, this._target, this._value); | |
36 | |
37 /// Updates the underlyling value and fires the expected notifications. | |
38 void updateValue(T newValue) { | |
39 var oldValue = _value; | |
40 _value = _target.notifyPropertyChange(_name, oldValue, newValue); | |
41 _target.emitPropertyChangeRecord(_name, oldValue, newValue); | |
jakemac
2014/07/25 16:40:33
I noticed that newValue and oldValue are swapped h
Siggi Cherem (dart-lang)
2014/07/25 17:45:12
good catch! I swapped them subconsciously because
| |
42 } | |
43 | |
44 /// The current value of the property. If the property is bound, reading this | |
45 /// property ensures that the changes are first propagated in order to return | |
46 /// the latest value. Similarly, when setting this property the binding (if | |
47 /// any) will be updated too. | |
48 T get value { | |
49 if (bindable != null) bindable.deliver(); | |
50 return _value; | |
51 } | |
52 | |
53 set value(T newValue) { | |
54 if (bindable != null) { | |
55 bindable.value = newValue; | |
56 } else { | |
57 updateValue(newValue); | |
58 } | |
59 } | |
60 | |
61 toString() { | |
62 var name = smoke.symbolToName(_name); | |
63 var hasBinding = bindable == null ? '(no-binding)' : '(with-binding)'; | |
64 return "[$runtimeType: $_target.$name: $_value $hasBinding]"; | |
65 } | |
66 } | |
OLD | NEW |