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

Side by Side Diff: pkg/polymer/lib/src/instance.dart

Issue 42433002: port Node.bind to bd0a0591920da9091b326627a46a104a92c7efe7 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
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 polymer; 5 part of polymer;
6 6
7 /** 7 /**
8 * Use this annotation to publish a field as an attribute. For example: 8 * Use this annotation to publish a field as an attribute. For example:
9 * 9 *
10 * class MyPlaybackElement extends PolymerElement { 10 * class MyPlaybackElement extends PolymerElement {
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 * Where polymerSyntax is a singleton `PolymerExpressions` instance from the 415 * Where polymerSyntax is a singleton `PolymerExpressions` instance from the
416 * [polymer_expressions](https://pub.dartlang.org/packages/polymer_expressions ) 416 * [polymer_expressions](https://pub.dartlang.org/packages/polymer_expressions )
417 * package. 417 * package.
418 * 418 *
419 * You can override this method to change the instantiation behavior of the 419 * You can override this method to change the instantiation behavior of the
420 * template, for example to use a different data-binding syntax. 420 * template, for example to use a different data-binding syntax.
421 */ 421 */
422 DocumentFragment instanceTemplate(Element template) => 422 DocumentFragment instanceTemplate(Element template) =>
423 templateBind(template).createInstance(this, _polymerSyntax); 423 templateBind(template).createInstance(this, _polymerSyntax);
424 424
425 NodeBinding createBinding(String name, model, String path) => 425 NodeBinding bind(String name, model, [String path]) {
426 nodeBindFallback(this).createBinding(name, model, path);
427
428 NodeBinding bind(String name, model, String path) {
429 // note: binding is a prepare signal. This allows us to be sure that any 426 // note: binding is a prepare signal. This allows us to be sure that any
430 // property changes that occur as a result of binding will be observed. 427 // property changes that occur as a result of binding will be observed.
431 if (!_elementPrepared) prepareElement(); 428 if (!_elementPrepared) prepareElement();
432 429
433 var property = propertyForAttribute(name); 430 var property = propertyForAttribute(name);
434 if (property != null) { 431 if (property != null) {
435 unbind(name); 432 unbind(name);
436 // use n-way Polymer binding 433 // use n-way Polymer binding
437 var observer = bindProperty(property.simpleName, model, path); 434 var observer = bindProperty(property.simpleName, model, path);
438 // reflect bound property to attribute when binding 435 // reflect bound property to attribute when binding
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 * 626 *
630 * var myProperty; 627 * var myProperty;
631 * 628 *
632 * created() { 629 * created() {
633 * super.created(); 630 * super.created();
634 * bindProperty(#myProperty, this, 'myModel.path.to.otherProp'); 631 * bindProperty(#myProperty, this, 'myModel.path.to.otherProp');
635 * } 632 * }
636 */ 633 */
637 // TODO(jmesserly): replace with something more localized, like: 634 // TODO(jmesserly): replace with something more localized, like:
638 // @ComputedField('myModel.path.to.otherProp'); 635 // @ComputedField('myModel.path.to.otherProp');
639 NodeBinding bindProperty(Symbol name, Object model, String path) => 636 NodeBinding bindProperty(Symbol name, Object model, [String path]) =>
640 // apply Polymer two-way reference binding 637 // apply Polymer two-way reference binding
641 _bindProperties(this, name, model, path); 638 _bindProperties(this, name, model, path);
642 639
643 /** 640 /**
644 * bind a property in A to a path in B by converting A[property] to a 641 * bind a property in A to a path in B by converting A[property] to a
645 * getter/setter pair that accesses B[...path...] 642 * getter/setter pair that accesses B[...path...]
646 */ 643 */
647 static NodeBinding _bindProperties(Polymer inA, Symbol inProperty, 644 static NodeBinding _bindProperties(Polymer inA, Symbol inProperty,
648 Object inB, String inPath) { 645 Object inB, String inPath) {
649 646
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 1061
1065 _sub = node.changes.listen(_propertyValueChanged); 1062 _sub = node.changes.listen(_propertyValueChanged);
1066 } 1063 }
1067 1064
1068 void close() { 1065 void close() {
1069 if (closed) return; 1066 if (closed) return;
1070 _sub.cancel(); 1067 _sub.cancel();
1071 super.close(); 1068 super.close();
1072 } 1069 }
1073 1070
1074 void boundValueChanged(newValue) { 1071 void valueChanged(newValue) {
1075 _lastValue = newValue; 1072 _lastValue = newValue;
1076 _target.setField(_property, newValue); 1073 _target.setField(_property, newValue);
1077 } 1074 }
1078 1075
1079 void _propertyValueChanged(List<ChangeRecord> records) { 1076 void _propertyValueChanged(List<ChangeRecord> records) {
1080 for (var record in records) { 1077 for (var record in records) {
1081 if (record is PropertyChangeRecord && record.name == _property) { 1078 if (record is PropertyChangeRecord && record.name == _property) {
1082 final newValue = _target.getField(_property).reflectee; 1079 final newValue = _target.getField(_property).reflectee;
1083 if (!identical(_lastValue, newValue)) { 1080 if (!identical(_lastValue, newValue)) {
1084 value = newValue; 1081 value = newValue;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 class PolymerElement extends HtmlElement with Polymer, Observable { 1135 class PolymerElement extends HtmlElement with Polymer, Observable {
1139 PolymerElement.created() : super.created() { 1136 PolymerElement.created() : super.created() {
1140 polymerCreated(); 1137 polymerCreated();
1141 } 1138 }
1142 } 1139 }
1143 1140
1144 class _PropertyValue { 1141 class _PropertyValue {
1145 Object oldValue, newValue; 1142 Object oldValue, newValue;
1146 _PropertyValue(this.oldValue); 1143 _PropertyValue(this.oldValue);
1147 } 1144 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698