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:js'; | |
| 7 import 'dart:mirrors'; | |
| 8 import 'package:js/js.dart'; | |
| 9 import 'package:js_util/js_util.dart'; | |
| 10 import 'package:polymer/polymer.dart'; | |
| 11 | |
| 12 class Binding { | |
| 13 final String attribute; | |
| 14 final String property; | |
| 15 const Binding (attribute, [String property]): | |
|
Cutch
2016/07/07 19:50:57
space between ) and :
the following lines should
cbernaschina
2016/07/07 22:08:13
updated to https://www.dartlang.org/effective-dart
| |
| 16 attribute = attribute, | |
| 17 property = property == null ? attribute : property; | |
| 18 } | |
| 19 | |
| 20 class Binder<T> { | |
| 21 final List<Binding> attributes; | |
| 22 final callback; | |
| 23 | |
| 24 Binder(List<Binding> attributes) : | |
| 25 this.attributes = attributes, | |
| 26 callback = _createCallback(T, attributes); | |
| 27 | |
| 28 registerCallback(T t) { | |
| 29 setValue(t, 'bind', callback); | |
| 30 } | |
| 31 | |
| 32 static _createCallback(Type T, List<Binding> attributes){ | |
| 33 ClassMirror target = reflectClass(T); | |
| 34 final Map<String, Symbol> setters = new Map<String, Symbol>(); | |
| 35 for (Binding binding in attributes){ | |
| 36 MethodMirror member = target.instanceMembers[ | |
| 37 new Symbol(binding.property + '=')]; | |
| 38 if (!member.isSetter) | |
| 39 throw new ArgumentError( | |
| 40 '${binding.property} is not a Setter for class $T'); | |
| 41 setters[binding.attribute] = new Symbol(binding.property); | |
| 42 } | |
| 43 return allowInteropCaptureThis((_this, name, value, [other]) { | |
| 44 Symbol setter = setters[name]; | |
| 45 if (setter == null) return; | |
| 46 Bindable bindable; | |
| 47 if (identical(1, 1.0)) { | |
| 48 bindable = getValue(getValue(value, '__dartBindable'), 'o') as Bindable; | |
| 49 } else { | |
| 50 bindable = getValue(value, '__dartBindable'); | |
| 51 } | |
| 52 var obj = reflect(_this); | |
| 53 obj.setField(setter, bindable.value); | |
| 54 }); | |
| 55 } | |
| 56 } | |
| OLD | NEW |