| 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 /** Extensions to [Element]s that behave as templates. */ | 7 /** Extensions to [Element]s that behave as templates. */ |
| 8 class _TemplateExtension extends _ElementExtension { | 8 class _TemplateExtension extends _ElementExtension { |
| 9 var _model; | 9 var _model; |
| 10 _TemplateIterator _templateIterator; | 10 _TemplateIterator _templateIterator; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 void unbindAll() { | 43 void unbindAll() { |
| 44 unbind('bind'); | 44 unbind('bind'); |
| 45 unbind('repeat'); | 45 unbind('repeat'); |
| 46 unbind('if'); | 46 unbind('if'); |
| 47 super.unbindAll(); | 47 super.unbindAll(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 /** | 50 /** |
| 51 * Creates an instance of the template. | 51 * Creates an instance of the template. |
| 52 */ | 52 */ |
| 53 DocumentFragment createInstance() { | 53 DocumentFragment createInstance(model, String syntax) { |
| 54 var template = node.ref; | 54 var template = node.ref; |
| 55 if (template == null) template = node; | 55 if (template == null) template = node; |
| 56 | 56 |
| 57 var instance = _Bindings._createDeepCloneAndDecorateTemplates( | 57 var instance = _createDeepCloneAndDecorateTemplates( |
| 58 template.content, node.attributes['syntax']); | 58 template.content, syntax); |
| 59 | 59 |
| 60 if (_instanceCreated != null) { | 60 if (_instanceCreated != null) _instanceCreated.add(instance); |
| 61 _instanceCreated.add(instance); | 61 |
| 62 } | 62 _addBindings(instance, model, TemplateElement.syntax[syntax]); |
| 63 _addTemplateInstanceRecord(instance, model); |
| 63 return instance; | 64 return instance; |
| 64 } | 65 } |
| 65 | 66 |
| 66 /** | 67 /** |
| 67 * The data model which is inherited through the tree. | 68 * The data model which is inherited through the tree. |
| 68 */ | 69 */ |
| 69 get model => _model; | 70 get model => _model; |
| 70 | 71 |
| 71 void set model(value) { | 72 void set model(value) { |
| 72 var syntax = TemplateElement.syntax[node.attributes['syntax']]; | 73 var syntax = TemplateElement.syntax[node.attributes['syntax']]; |
| 73 _model = value; | 74 _model = value; |
| 74 _Bindings._addBindings(node, model, syntax); | 75 _addBindings(node, model, syntax); |
| 75 } | 76 } |
| 76 } | 77 } |
| OLD | NEW |