Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016, 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 import 'dart:core'; | |
| 6 import 'dart:html'; | |
| 7 import 'dart:js'; | |
| 8 import 'dart:mirrors'; | |
| 9 import 'package:js/js.dart'; | |
| 10 import 'package:js_util/js_util.dart'; | |
| 11 import 'package:polymer/polymer.dart'; | |
| 12 | |
| 13 class Binding { | |
| 14 final String attribute; | |
| 15 final String property; | |
| 16 const Binding (attribute, [String property]) | |
| 17 : attribute = attribute, | |
| 18 property = property == null ? attribute : property; | |
| 19 } | |
| 20 | |
| 21 ///This is a temporary bridge between Polymer Bindings and the wrapper entities. | |
| 22 class Binder<T extends HtmlElement> { | |
| 23 final List<Binding> attributes; | |
| 24 final callback; | |
| 25 | |
| 26 Binder(List<Binding> attributes) | |
| 27 : attributes = attributes, | |
| 28 callback = _createCallback(T, attributes); | |
| 29 | |
| 30 registerCallback(T element) { | |
| 31 assert(element != null); | |
| 32 setValue(element, 'bind', callback); | |
| 33 } | |
| 34 | |
| 35 static _createCallback(Type T, List<Binding> attributes){ | |
| 36 final target = reflectClass(T); | |
| 37 final setters = <String, Symbol>{}; | |
| 38 for (Binding binding in attributes){ | |
| 39 var member = target.instanceMembers[new Symbol(binding.property + '=')]; | |
| 40 if (!member.isSetter) | |
| 41 throw new ArgumentError( | |
| 42 '${binding.property} is not a Setter for class $T'); | |
| 43 setters[binding.attribute] = new Symbol(binding.property); | |
| 44 } | |
| 45 return allowInteropCaptureThis((_this, name, value, [other]) { | |
| 46 final setter = setters[name]; | |
| 47 if (setter == null) return; | |
| 48 Bindable bindable; | |
| 49 if (identical(1, 1.0)) { | |
|
rmacnak
2016/07/18 17:58:19
// dart2js
| |
| 50 bindable = getValue(getValue(value, '__dartBindable'), 'o') as Bindable; | |
| 51 } else { | |
| 52 bindable = getValue(value, '__dartBindable'); | |
|
rmacnak
2016/07/18 17:58:19
// vm
| |
| 53 } | |
| 54 var obj = reflect(_this); | |
| 55 obj.setField(setter, bindable.value); | |
| 56 bindable.open((value) { | |
| 57 obj.setField(setter, value); | |
| 58 }); | |
| 59 }); | |
| 60 } | |
| 61 } | |
| OLD | NEW |