Chromium Code Reviews| Index: pkg/template_binding/lib/src/instance_binding_map.dart |
| diff --git a/pkg/template_binding/lib/src/instance_binding_map.dart b/pkg/template_binding/lib/src/instance_binding_map.dart |
| index 9b1bf6d53221897e5ea75bcca8a76bfbdecaf946..71b0c12aac11962901cbbf56fbfb11be84eff1b7 100644 |
| --- a/pkg/template_binding/lib/src/instance_binding_map.dart |
| +++ b/pkg/template_binding/lib/src/instance_binding_map.dart |
| @@ -6,30 +6,39 @@ part of template_binding; |
| class _InstanceBindingMap { |
| final List bindings; |
| - final List<_InstanceBindingMap> children; |
| + 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
|
| final Node templateRef; |
| - _InstanceBindingMap._(this.bindings, this.children, this.templateRef); |
| + // Workaround for: |
| + // https://github.com/Polymer/TemplateBinding/issues/150 |
| + final int numChildren; |
| - factory _InstanceBindingMap(Node node, BindingDelegate delegate) { |
| - var bindings = _getBindings(node, delegate); |
| - Node templateRef = null; |
| + _InstanceBindingMap._(this.bindings, this.children, this.templateRef, |
| + this.numChildren); |
| +} |
| - if (isSemanticTemplate(node)) templateRef = node; |
| +_InstanceBindingMap _createInstanceBindingMap(Node node, |
| + BindingDelegate delegate) { |
| - List children = null; |
| - for (var c = node.firstChild, i = 0; c != null; c = c.nextNode, i++) { |
| - var childMap = new _InstanceBindingMap(c, delegate); |
| - if (childMap == null) continue; |
| + var bindings = _getBindings(node, delegate); |
| + Node templateRef = null; |
| - if (children == null) children = new List(node.nodes.length); |
| - children[i] = childMap; |
| - } |
| + if (isSemanticTemplate(node)) templateRef = node; |
| - return new _InstanceBindingMap._(bindings, children, templateRef); |
| + Map children = null; |
| + int i = 0; |
| + for (var c = node.firstChild; c != null; c = c.nextNode, i++) { |
| + var childMap = _createInstanceBindingMap(c, delegate); |
| + if (childMap == null) continue; |
| + |
| + if (children == null) children = new HashMap(); |
| + children[i] = childMap; |
| } |
| -} |
| + if (bindings == null && children == null && templateRef == null) return null; |
|
Jennifer Messerly
2013/12/09 23:49:22
we were missing this important optimization.
|
| + |
| + return new _InstanceBindingMap._(bindings, children, templateRef, i); |
| +} |
| void _addMapBindings(Node node, _InstanceBindingMap map, model, |
| BindingDelegate delegate, List bound) { |
| @@ -48,8 +57,15 @@ void _addMapBindings(Node node, _InstanceBindingMap map, model, |
| if (map.children == null) return; |
| - int i = 0; |
| - for (var c = node.firstChild; c != null; c = c.nextNode) { |
| - _addMapBindings(c, map.children[i++], model, delegate, bound); |
| + // 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
|
| + // we try and detect cases where creating a custom element resulted in extra |
| + // children compared to what we expected. We assume these new children are all |
| + // at the beginning, because _deepCloneIgnoreTemplateContent creates the |
| + // element then appends the template content's children to the end. |
| + |
| + int i = map.numChildren - node.nodes.length; |
| + for (var c = node.firstChild; c != null; c = c.nextNode, i++) { |
| + if (i < 0) continue; |
| + _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
|
| } |
| } |