| OLD | NEW |
| 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 mdv; | 5 part of mdv; |
| 6 | 6 |
| 7 // This code is a port of Model-Driven-Views: | 7 // This code is a port of Model-Driven-Views: |
| 8 // https://github.com/polymer-project/mdv | 8 // https://github.com/polymer-project/mdv |
| 9 // The code mostly comes from src/template_element.js | 9 // The code mostly comes from src/template_element.js |
| 10 | 10 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 BindingDelegate delegate) { | 92 BindingDelegate delegate) { |
| 93 | 93 |
| 94 // If this is a custom element, give the .xtag a change to bind. | 94 // If this is a custom element, give the .xtag a change to bind. |
| 95 node = _nodeOrCustom(node); | 95 node = _nodeOrCustom(node); |
| 96 | 96 |
| 97 if (_isSimpleBinding(tokens)) { | 97 if (_isSimpleBinding(tokens)) { |
| 98 _bindOrDelegate(node, name, model, tokens[1], delegate); | 98 _bindOrDelegate(node, name, model, tokens[1], delegate); |
| 99 return; | 99 return; |
| 100 } | 100 } |
| 101 | 101 |
| 102 var replacementBinding = new CompoundBinding(); | 102 // TODO(jmesserly): MDV caches the closure on the tokens, but I'm not sure |
| 103 for (var i = 1; i < tokens.length; i += 2) { | 103 // why they do that instead of just caching the entire CompoundBinding object |
| 104 // TODO(jmesserly): not sure if this index is correct. See my comment here: | 104 // and unbindAll then bind to the new model. |
| 105 // https://github.com/Polymer/mdv/commit/f1af6fe683fd06eed2a7a7849f01c227db1
2cda3#L0L1035 | 105 var replacementBinding = new CompoundBinding() |
| 106 _bindOrDelegate(replacementBinding, i, model, tokens[i], delegate); | 106 ..scheduled = true |
| 107 } | 107 ..combinator = (values) { |
| 108 | |
| 109 replacementBinding.combinator = (values) { | |
| 110 var newValue = new StringBuffer(); | 108 var newValue = new StringBuffer(); |
| 111 | 109 |
| 112 for (var i = 0, text = true; i < tokens.length; i++, text = !text) { | 110 for (var i = 0, text = true; i < tokens.length; i++, text = !text) { |
| 113 if (text) { | 111 if (text) { |
| 114 newValue.write(tokens[i]); | 112 newValue.write(tokens[i]); |
| 115 } else { | 113 } else { |
| 116 var value = values[i]; | 114 var value = values[i]; |
| 117 if (value != null) { | 115 if (value != null) { |
| 118 newValue.write(value); | 116 newValue.write(value); |
| 119 } | 117 } |
| 120 } | 118 } |
| 121 } | 119 } |
| 122 | 120 |
| 123 return newValue.toString(); | 121 return newValue.toString(); |
| 124 }; | 122 }; |
| 125 | 123 |
| 124 for (var i = 1; i < tokens.length; i += 2) { |
| 125 // TODO(jmesserly): not sure if this index is correct. See my comment here: |
| 126 // https://github.com/Polymer/mdv/commit/f1af6fe683fd06eed2a7a7849f01c227db1
2cda3#L0L1035 |
| 127 _bindOrDelegate(replacementBinding, i, model, tokens[i], delegate); |
| 128 } |
| 129 |
| 130 replacementBinding.resolve(); |
| 131 |
| 126 node.bind(name, replacementBinding, 'value'); | 132 node.bind(name, replacementBinding, 'value'); |
| 127 } | 133 } |
| 128 | 134 |
| 129 void _bindOrDelegate(node, name, model, String path, | 135 void _bindOrDelegate(node, name, model, String path, |
| 130 BindingDelegate delegate) { | 136 BindingDelegate delegate) { |
| 131 | 137 |
| 132 if (delegate != null) { | 138 if (delegate != null) { |
| 133 var delegateBinding = delegate.getBinding(model, path, name, node); | 139 var delegateBinding = delegate.getBinding(model, path, name, node); |
| 134 if (delegateBinding != null) { | 140 if (delegateBinding != null) { |
| 135 model = delegateBinding; | 141 model = delegateBinding; |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 nodeExt._templateIterator = null; | 407 nodeExt._templateIterator = null; |
| 402 } | 408 } |
| 403 } | 409 } |
| 404 | 410 |
| 405 _nodeOrCustom(node).unbindAll(); | 411 _nodeOrCustom(node).unbindAll(); |
| 406 for (var c = node.firstChild; c != null; c = c.nextNode) { | 412 for (var c = node.firstChild; c != null; c = c.nextNode) { |
| 407 _unbindAllRecursively(c); | 413 _unbindAllRecursively(c); |
| 408 } | 414 } |
| 409 } | 415 } |
| 410 } | 416 } |
| OLD | NEW |