| Index: runtime/observatory/lib/src/elements/shims/binding.dart
|
| diff --git a/runtime/observatory/lib/src/elements/shims/binding.dart b/runtime/observatory/lib/src/elements/shims/binding.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..63783bf7cdb6deaddd1bcec288b2f8dec7d9a3e3
|
| --- /dev/null
|
| +++ b/runtime/observatory/lib/src/elements/shims/binding.dart
|
| @@ -0,0 +1,56 @@
|
| +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +import 'dart:core';
|
| +import 'dart:js';
|
| +import 'dart:mirrors';
|
| +import 'package:js/js.dart';
|
| +import 'package:js_util/js_util.dart';
|
| +import 'package:polymer/polymer.dart';
|
| +
|
| +class Binding {
|
| + final String attribute;
|
| + final String property;
|
| + const Binding (attribute, [String property]):
|
| + attribute = attribute,
|
| + property = property == null ? attribute : property;
|
| +}
|
| +
|
| +class Binder<T> {
|
| + final List<Binding> attributes;
|
| + final callback;
|
| +
|
| + Binder(List<Binding> attributes) :
|
| + this.attributes = attributes,
|
| + callback = _createCallback(T, attributes);
|
| +
|
| + registerCallback(T t) {
|
| + setValue(t, 'bind', callback);
|
| + }
|
| +
|
| + static _createCallback(Type T, List<Binding> attributes){
|
| + ClassMirror target = reflectClass(T);
|
| + final Map<String, Symbol> setters = new Map<String, Symbol>();
|
| + for (Binding binding in attributes){
|
| + MethodMirror member = target.instanceMembers[
|
| + new Symbol(binding.property + '=')];
|
| + if (!member.isSetter)
|
| + throw new ArgumentError(
|
| + '${binding.property} is not a Setter for class $T');
|
| + setters[binding.attribute] = new Symbol(binding.property);
|
| + }
|
| + return allowInteropCaptureThis((_this, name, value, [other]) {
|
| + Symbol setter = setters[name];
|
| + if (setter == null) return;
|
| + Bindable bindable;
|
| + if (identical(1, 1.0)) {
|
| + bindable = getValue(getValue(value, '__dartBindable'), 'o') as Bindable;
|
| + } else {
|
| + bindable = getValue(value, '__dartBindable');
|
| + }
|
| + var obj = reflect(_this);
|
| + obj.setField(setter, bindable.value);
|
| + });
|
| + }
|
| +}
|
|
|