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

Unified Diff: pkg/polymer_expressions/lib/polymer_expressions.dart

Issue 420673002: Roll polymer packages to version 0.3.4 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/polymer_expressions/CHANGELOG.md ('k') | pkg/template_binding/CHANGELOG.md » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/polymer_expressions/lib/polymer_expressions.dart
diff --git a/pkg/polymer_expressions/lib/polymer_expressions.dart b/pkg/polymer_expressions/lib/polymer_expressions.dart
index a6defbe807ade69b464c2be53d5d60931f93e7f4..332e3a1ae9c2b8e8fa63b20e455718b44926847e 100644
--- a/pkg/polymer_expressions/lib/polymer_expressions.dart
+++ b/pkg/polymer_expressions/lib/polymer_expressions.dart
@@ -97,7 +97,7 @@ class PolymerExpressions extends BindingDelegate {
? model
: _scopeFactory.modelScope(model: model, variables: globals);
if (oneTime) {
- return _Binding._oneTime(expr, scope, null);
+ return _Binding._oneTime(expr, scope);
}
return new _Binding(expr, scope);
};
@@ -250,6 +250,23 @@ class PolymerExpressions extends BindingDelegate {
}
}
+ /// Parse the expression string and return an expression tree.
+ static Expression getExpression(String exprString) =>
+ new Parser(exprString).parse();
+
+ /// Determines the value of evaluating [expr] on the given [model] and returns
+ /// either its value or a binding for it. If [oneTime] is true, it direclty
+ /// returns the value. Otherwise, when [oneTime] is false, it returns a
+ /// [Bindable] that besides evaluating the expression, it will also react to
+ /// observable changes from the model and update the value accordingly.
+ static getBinding(Expression expr, model, {Map<String, Object> globals,
+ oneTime: false}) {
+ if (globals == null) globals = new Map.from(DEFAULT_GLOBALS);
+ var scope = model is Scope ? model
+ : new Scope(model: model, variables: globals);
+ return oneTime ? _Binding._oneTime(expr, scope)
+ : new _Binding(expr, scope);
+ }
}
typedef Object _Converter(Object);
@@ -264,10 +281,9 @@ class _Binding extends Bindable {
ExpressionObserver _observer;
var _value;
- _Binding(this._expr, this._scope, [converter])
- : _converter = converter == null ? _identity : converter;
+ _Binding(this._expr, this._scope, [this._converter]);
- static Object _oneTime(Expression expr, Scope scope, _Converter converter) {
+ static Object _oneTime(Expression expr, Scope scope, [_Converter converter]) {
try {
var value = eval(expr, scope);
return (converter == null) ? value : converter(value);
@@ -280,7 +296,7 @@ class _Binding extends Bindable {
bool _convertAndCheck(newValue, {bool skipChanges: false}) {
var oldValue = _value;
- _value = _converter(newValue);
+ _value = _converter == null ? newValue : _converter(newValue);
if (!skipChanges && _callback != null && oldValue != _value) {
_callback(_value);
@@ -296,7 +312,7 @@ class _Binding extends Bindable {
_check(skipChanges: true);
return _value;
}
- return _oneTime(_expr, _scope, _converter);
+ return _Binding._oneTime(_expr, _scope, _converter);
}
set value(v) {
« no previous file with comments | « pkg/polymer_expressions/CHANGELOG.md ('k') | pkg/template_binding/CHANGELOG.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698