| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 part of mdv; |
| 6 |
| 7 /** Extensions to [Element]s that behave as templates. */ |
| 8 class _TemplateExtension extends _ElementExtension { |
| 9 var _model; |
| 10 _TemplateIterator _templateIterator; |
| 11 |
| 12 _TemplateExtension(Element node) : super(node); |
| 13 |
| 14 void bind(String name, model, String path) { |
| 15 switch (name) { |
| 16 case 'bind': |
| 17 case 'repeat': |
| 18 case 'if': |
| 19 if (_templateIterator == null) { |
| 20 _templateIterator = new _TemplateIterator(node); |
| 21 } |
| 22 _templateIterator.inputs.bind(name, model, path); |
| 23 return; |
| 24 default: |
| 25 super.bind(name, model, path); |
| 26 } |
| 27 } |
| 28 |
| 29 void unbind(String name) { |
| 30 switch (name) { |
| 31 case 'bind': |
| 32 case 'repeat': |
| 33 case 'if': |
| 34 if (_templateIterator != null) { |
| 35 _templateIterator.inputs.unbind(name); |
| 36 } |
| 37 return; |
| 38 default: |
| 39 super.unbind(name); |
| 40 } |
| 41 } |
| 42 |
| 43 void unbindAll() { |
| 44 unbind('bind'); |
| 45 unbind('repeat'); |
| 46 unbind('if'); |
| 47 super.unbindAll(); |
| 48 } |
| 49 |
| 50 /** |
| 51 * Creates an instance of the template. |
| 52 */ |
| 53 DocumentFragment createInstance() { |
| 54 var template = node.ref; |
| 55 if (template == null) template = node; |
| 56 |
| 57 var instance = _Bindings._createDeepCloneAndDecorateTemplates( |
| 58 template.content, node.attributes['syntax']); |
| 59 |
| 60 if (_instanceCreated != null) { |
| 61 _instanceCreated.add(instance); |
| 62 } |
| 63 return instance; |
| 64 } |
| 65 |
| 66 /** |
| 67 * The data model which is inherited through the tree. |
| 68 */ |
| 69 get model => _model; |
| 70 |
| 71 void set model(value) { |
| 72 var syntax = TemplateElement.syntax[node.attributes['syntax']]; |
| 73 _model = value; |
| 74 _Bindings._addBindings(node, model, syntax); |
| 75 } |
| 76 } |
| OLD | NEW |