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

Unified Diff: pkg/template_binding/test/template_binding_test.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/pubspec.yaml ('k') | pkg/web_components/CHANGELOG.md » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/template_binding/test/template_binding_test.dart
diff --git a/pkg/template_binding/test/template_binding_test.dart b/pkg/template_binding/test/template_binding_test.dart
index 375d3d64e8e8d0e59af191952daf8fc6f3a07a05..de7e8c37af7f783668f6f50f0c25fa84ef6a87c0 100644
--- a/pkg/template_binding/test/template_binding_test.dart
+++ b/pkg/template_binding/test/template_binding_test.dart
@@ -397,6 +397,59 @@ templateInstantiationTests() {
});
});
+ test('Bind If minimal discardChanges', () {
+ var div = createTestHtml(
+ '<template bind="{{bound}}" if="{{predicate}}">value:{{ value }}'
+ '</template>');
+ // Dart Note: bound changed from null->{}.
+ var m = toObservable({ 'bound': {}, 'predicate': null });
+ var template = div.firstChild;
+
+ var discardChangesCalled = { 'bound': 0, 'predicate': 0 };
+ templateBind(template)
+ ..model = m
+ ..bindingDelegate =
+ new BindIfMinimalDiscardChanges(discardChangesCalled);
+
+ return new Future(() {
+ expect(discardChangesCalled['bound'], 0);
+ expect(discardChangesCalled['predicate'], 0);
+ expect(div.childNodes.length, 1);
+ m['predicate'] = 1;
+ }).then(endOfMicrotask).then((_) {
+ expect(discardChangesCalled['bound'], 1);
+ expect(discardChangesCalled['predicate'], 0);
+
+ expect(div.nodes.length, 2);
+ expect(div.lastChild.text, 'value:');
+
+ m['bound'] = toObservable({'value': 2});
+ }).then(endOfMicrotask).then((_) {
+ expect(discardChangesCalled['bound'], 1);
+ expect(discardChangesCalled['predicate'], 1);
+
+ expect(div.nodes.length, 2);
+ expect(div.lastChild.text, 'value:2');
+
+ m['bound']['value'] = 3;
+
+ }).then(endOfMicrotask).then((_) {
+ expect(discardChangesCalled['bound'], 1);
+ expect(discardChangesCalled['predicate'], 1);
+
+ expect(div.nodes.length, 2);
+ expect(div.lastChild.text, 'value:3');
+
+ templateBind(template).model = null;
+ }).then(endOfMicrotask).then((_) {
+ expect(discardChangesCalled['bound'], 1);
+ expect(discardChangesCalled['predicate'], 1);
+
+ expect(div.nodes.length, 1);
+ });
+ });
+
+
test('Empty-If', () {
var div = createTestHtml('<template if>{{ value }}</template>');
var template = div.firstChild;
@@ -2643,6 +2696,29 @@ class Issue18Syntax extends BindingDelegate {
}
}
+class BindIfMinimalDiscardChanges extends BindingDelegate {
+ Map<String, int> discardChangesCalled;
+
+ BindIfMinimalDiscardChanges(this.discardChangesCalled) : super() {}
+
+ prepareBinding(path, name, node) {
+ return (model, node, oneTime) =>
+ new DiscardCountingPathObserver(discardChangesCalled, model, path);
+ }
+}
+
+class DiscardCountingPathObserver extends PathObserver {
+ Map<String, int> discardChangesCalled;
+
+ DiscardCountingPathObserver(this.discardChangesCalled, model, path)
+ : super(model, path) {}
+
+ get value {
+ discardChangesCalled[path.toString()]++;
+ return super.value;
+ }
+}
+
class TestAccessorModel extends Observable {
@observable var value = 1;
var count = 0;
« no previous file with comments | « pkg/template_binding/pubspec.yaml ('k') | pkg/web_components/CHANGELOG.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698