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

Side by Side Diff: packages/polymer/lib/src/property_accessor.dart

Issue 2312183003: Removed Polymer from Observatory deps (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « packages/polymer/lib/src/loader.dart ('k') | packages/polymer/lib/transformer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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, newValue, oldValue);
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 // Dart Note: The js side makes computed properties read only, and bails
55 // out right here for them (ignoreWrites). For us they are automatically
56 // read only unless you define a setter for them, so we left that out.
57 if (bindable != null) {
58 bindable.value = newValue;
59 } else {
60 updateValue(newValue);
61 }
62 }
63
64 toString() {
65 var name = smoke.symbolToName(_name);
66 var hasBinding = bindable == null ? '(no-binding)' : '(with-binding)';
67 return "[$runtimeType: $_target.$name: $_value $hasBinding]";
68 }
69 }
OLDNEW
« no previous file with comments | « packages/polymer/lib/src/loader.dart ('k') | packages/polymer/lib/transformer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698