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

Unified Diff: pkg/template_binding/lib/src/template_iterator.dart

Issue 507653004: update polymer to 0.3.5 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review updates Created 6 years, 4 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/template_binding/lib/src/template.dart ('k') | pkg/template_binding/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/template_binding/lib/src/template_iterator.dart
diff --git a/pkg/template_binding/lib/src/template_iterator.dart b/pkg/template_binding/lib/src/template_iterator.dart
index a2839eaaa0b10bf097e5b3e786634c268ba85e53..71004867b9f16fbf768fb95412d475dfe0a52348 100644
--- a/pkg/template_binding/lib/src/template_iterator.dart
+++ b/pkg/template_binding/lib/src/template_iterator.dart
@@ -257,18 +257,20 @@ class _TemplateIterator extends Bindable {
_hasIf = directives._if != null;
_hasRepeat = directives._repeat != null;
+ var ifValue = true;
if (_hasIf) {
_ifOneTime = directives._if.onlyOneTime;
_ifValue = _processBinding('if', directives._if, template, model);
+ ifValue = _ifValue;
// oneTime if & predicate is false. nothing else to do.
- if (_ifOneTime) {
- if (!_toBoolean(_ifValue)) {
- _updateIteratedValue(null);
- return;
- }
- } else {
- (_ifValue as Bindable).open(_updateIteratedValue);
+ if (_ifOneTime && !_toBoolean(ifValue)) {
+ _valueChanged(null);
+ return;
+ }
+
+ if (!_ifOneTime) {
+ ifValue = (ifValue as Bindable).open(_updateIfValue);
}
}
@@ -280,12 +282,38 @@ class _TemplateIterator extends Bindable {
_value = _processBinding('bind', directives._bind, template, model);
}
- if (!_oneTime) _value.open(_updateIteratedValue);
+ var value = _value;
+ if (!_oneTime) {
+ value = _value.open(_updateIteratedValue);
+ }
+
+ if (!_toBoolean(ifValue)) {
+ _valueChanged(null);
+ return;
+ }
+
+ _updateValue(value);
+ }
+
+ /// Gets the updated value of the bind/repeat. This can potentially call
+ /// user code (if a bindingDelegate is set up) so we try to avoid it if we
+ /// already have the value in hand (from Observer.open).
+ Object _getUpdatedValue() {
+ var value = _value;
+ // Dart note: x.discardChanges() is x.value in Dart.
+ if (!_toBoolean(_oneTime)) value = value.value;
+ return value;
+ }
- _updateIteratedValue(null);
+ void _updateIfValue(ifValue) {
+ if (!_toBoolean(ifValue)) {
+ _valueChanged(null);
+ return;
+ }
+ _updateValue(_getUpdatedValue());
}
- void _updateIteratedValue(_) {
+ void _updateIteratedValue(value) {
if (_hasIf) {
var ifValue = _ifValue;
if (!_ifOneTime) ifValue = (ifValue as Bindable).value;
@@ -295,8 +323,10 @@ class _TemplateIterator extends Bindable {
}
}
- var value = _value;
- if (!_oneTime) value = (value as Bindable).value;
+ _updateValue(value);
+ }
+
+ void _updateValue(Object value) {
if (!_hasRepeat) value = [value];
_valueChanged(value);
}
« no previous file with comments | « pkg/template_binding/lib/src/template.dart ('k') | pkg/template_binding/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698