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

Side by Side Diff: pkg/template_binding/lib/src/instance_binding_map.dart

Issue 110763003: work around for https://github.com/Polymer/TemplateBinding/issues/150 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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
« no previous file with comments | « pkg/polymer/lib/src/instance.dart ('k') | pkg/template_binding/lib/src/template.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 part of template_binding; 5 part of template_binding;
6 6
7 class _InstanceBindingMap { 7 class _InstanceBindingMap {
8 final List bindings; 8 final List bindings;
9 final List<_InstanceBindingMap> children; 9 final Map<int, _InstanceBindingMap> children;
Jennifer Messerly 2013/12/09 23:49:22 I noticed the JavaScript version uses a Map too. I
Siggi Cherem (dart-lang) 2013/12/10 00:42:23 It seemed to me that they still used a [] for the
Jennifer Messerly 2013/12/10 02:15:43 yup. I like using a class for InstanceBindingMap t
10 final Node templateRef; 10 final Node templateRef;
11 11
12 _InstanceBindingMap._(this.bindings, this.children, this.templateRef); 12 // Workaround for:
13 // https://github.com/Polymer/TemplateBinding/issues/150
14 final int numChildren;
13 15
14 factory _InstanceBindingMap(Node node, BindingDelegate delegate) { 16 _InstanceBindingMap._(this.bindings, this.children, this.templateRef,
15 var bindings = _getBindings(node, delegate); 17 this.numChildren);
16 Node templateRef = null;
17
18 if (isSemanticTemplate(node)) templateRef = node;
19
20 List children = null;
21 for (var c = node.firstChild, i = 0; c != null; c = c.nextNode, i++) {
22 var childMap = new _InstanceBindingMap(c, delegate);
23 if (childMap == null) continue;
24
25 if (children == null) children = new List(node.nodes.length);
26 children[i] = childMap;
27 }
28
29 return new _InstanceBindingMap._(bindings, children, templateRef);
30 }
31 } 18 }
32 19
20 _InstanceBindingMap _createInstanceBindingMap(Node node,
21 BindingDelegate delegate) {
22
23 var bindings = _getBindings(node, delegate);
24 Node templateRef = null;
25
26 if (isSemanticTemplate(node)) templateRef = node;
27
28 Map children = null;
29 int i = 0;
30 for (var c = node.firstChild; c != null; c = c.nextNode, i++) {
31 var childMap = _createInstanceBindingMap(c, delegate);
32 if (childMap == null) continue;
33
34 if (children == null) children = new HashMap();
35 children[i] = childMap;
36 }
37
38 if (bindings == null && children == null && templateRef == null) return null;
Jennifer Messerly 2013/12/09 23:49:22 we were missing this important optimization.
39
40 return new _InstanceBindingMap._(bindings, children, templateRef, i);
41 }
33 42
34 void _addMapBindings(Node node, _InstanceBindingMap map, model, 43 void _addMapBindings(Node node, _InstanceBindingMap map, model,
35 BindingDelegate delegate, List bound) { 44 BindingDelegate delegate, List bound) {
36 if (map == null) return; 45 if (map == null) return;
37 46
38 if (map.templateRef != null) { 47 if (map.templateRef != null) {
39 TemplateBindExtension.decorate(node, map.templateRef); 48 TemplateBindExtension.decorate(node, map.templateRef);
40 if (delegate != null) { 49 if (delegate != null) {
41 templateBindFallback(node)._bindingDelegate = delegate; 50 templateBindFallback(node)._bindingDelegate = delegate;
42 } 51 }
43 } 52 }
44 53
45 if (map.bindings != null) { 54 if (map.bindings != null) {
46 _processBindings(map.bindings, node, model, bound); 55 _processBindings(map.bindings, node, model, bound);
47 } 56 }
48 57
49 if (map.children == null) return; 58 if (map.children == null) return;
50 59
51 int i = 0; 60 // To workaround https://github.com/Polymer/TemplateBinding/issues/150,
Jennifer Messerly 2013/12/09 23:49:22 I'm not sure how robust this workaround is, but it
Siggi Cherem (dart-lang) 2013/12/10 00:42:23 what would be more robust? a Map<Node, _InstanceBi
Jennifer Messerly 2013/12/10 02:15:43 the problem is, they aren't the same nodes. We're
52 for (var c = node.firstChild; c != null; c = c.nextNode) { 61 // we try and detect cases where creating a custom element resulted in extra
53 _addMapBindings(c, map.children[i++], model, delegate, bound); 62 // children compared to what we expected. We assume these new children are all
63 // at the beginning, because _deepCloneIgnoreTemplateContent creates the
64 // element then appends the template content's children to the end.
65
66 int i = map.numChildren - node.nodes.length;
67 for (var c = node.firstChild; c != null; c = c.nextNode, i++) {
68 if (i < 0) continue;
69 _addMapBindings(c, map.children[i], model, delegate, bound);
Siggi Cherem (dart-lang) 2013/12/10 00:42:23 I'm not sure I follow this yet. Doesn't this 'i' n
Jennifer Messerly 2013/12/10 02:15:43 we're adjusting because it starts negative. Let's
54 } 70 }
55 } 71 }
OLDNEW
« no previous file with comments | « pkg/polymer/lib/src/instance.dart ('k') | pkg/template_binding/lib/src/template.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698