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

Side by Side Diff: pkg/polymer_expressions/lib/polymer_expressions.dart

Issue 50203004: port TemplateBinding to ed3266266e751b5ab1f75f8e0509d0d5f0ef35d8 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 /** 5 /**
6 * A binding delegate used with Polymer elements that 6 * A binding delegate used with Polymer elements that
7 * allows for complex binding expressions, including 7 * allows for complex binding expressions, including
8 * property access, function invocation, 8 * property access, function invocation,
9 * list/map indexing, and two-way filtering. 9 * list/map indexing, and two-way filtering.
10 * 10 *
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 /** 61 /**
62 * Creates a new binding delegate for Polymer expressions, with the provided 62 * Creates a new binding delegate for Polymer expressions, with the provided
63 * variables used as [globals]. If no globals are supplied, a copy of the 63 * variables used as [globals]. If no globals are supplied, a copy of the
64 * [DEFAULT_GLOBALS] will be used. 64 * [DEFAULT_GLOBALS] will be used.
65 */ 65 */
66 PolymerExpressions({Map<String, Object> globals}) 66 PolymerExpressions({Map<String, Object> globals})
67 : globals = (globals == null) ? 67 : globals = (globals == null) ?
68 new Map<String, Object>.from(DEFAULT_GLOBALS) : globals; 68 new Map<String, Object>.from(DEFAULT_GLOBALS) : globals;
69 69
70 _Binding getBinding(model, String path, name, node) { 70 prepareBinding(String path, name, node) {
71 if (path == null) return null; 71 if (path == null) return null;
72 var expr = new Parser(path).parse(); 72 var expr = new Parser(path).parse();
73 if (model is! Scope) { 73 return (model, node) {
74 model = new Scope(model: model, variables: globals); 74 if (model is! Scope) {
75 } 75 model = new Scope(model: model, variables: globals);
76 if (node is Element && name == "class") { 76 }
77 return new _Binding(expr, model, _classAttributeConverter); 77 if (node is Element && name == "class") {
78 } 78 return new _Binding(expr, model, _classAttributeConverter);
79 if (node is Element && name == "style") { 79 }
80 return new _Binding(expr, model, _styleAttributeConverter); 80 if (node is Element && name == "style") {
81 } 81 return new _Binding(expr, model, _styleAttributeConverter);
82 return new _Binding(expr, model); 82 }
83 return new _Binding(expr, model);
84 };
83 } 85 }
84 86
85 getInstanceModel(Element template, model) { 87 prepareInstanceModel(Element template) => (model) =>
86 if (model is! Scope) { 88 model is Scope ? model : new Scope(model: model, variables: globals);
87 var _scope = new Scope(model: model, variables: globals);
88 return _scope;
89 }
90 return model;
91 }
92 } 89 }
93 90
94 class _Binding extends ChangeNotifier { 91 class _Binding extends ChangeNotifier {
95 final Scope _scope; 92 final Scope _scope;
96 final ExpressionObserver _expr; 93 final ExpressionObserver _expr;
97 final _converter; 94 final _converter;
98 var _value; 95 var _value;
99 96
100 _Binding(Expression expr, Scope scope, [this._converter]) 97 _Binding(Expression expr, Scope scope, [this._converter])
101 : _expr = observe(expr, scope), 98 : _expr = observe(expr, scope),
(...skipping 29 matching lines...) Expand all
131 @reflectable get value => _value; 128 @reflectable get value => _value;
132 129
133 @reflectable set value(v) { 130 @reflectable set value(v) {
134 try { 131 try {
135 assign(_expr, v, _scope); 132 assign(_expr, v, _scope);
136 } on EvalException catch (e) { 133 } on EvalException catch (e) {
137 _logger.warning("Error evaluating expression '$_expr': ${e.message}"); 134 _logger.warning("Error evaluating expression '$_expr': ${e.message}");
138 } 135 }
139 } 136 }
140 } 137 }
OLDNEW
« no previous file with comments | « pkg/polymer/test/event_handlers_test.dart ('k') | pkg/polymer_expressions/test/bindings_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698