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

Side by Side Diff: runtime/observatory/lib/src/elements/shims/binding.dart

Issue 2119733003: Wrapping leaf nodes in non polymer elements (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Converted error-ref tag Created 4 years, 5 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
OLDNEW
(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])
16 : attribute = attribute,
17 property = property == null ? attribute : property;
18 }
19
20 class Binder<T> {
rmacnak 2016/07/11 17:54:01 Assuming I've understood this, add a comment menti
cbernaschina 2016/07/11 18:14:11 Done.
21 final List<Binding> attributes;
22 final callback;
23
24 Binder(List<Binding> attributes)
25 : 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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698