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

Side by Side Diff: pkg/mdv/lib/src/template.dart

Issue 19663011: Custom Syntax's are now enabled via template.bindingDelegate = (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: restore @Experimental Created 7 years, 5 months 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/mdv/lib/mdv.dart ('k') | pkg/mdv/lib/src/template_iterator.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 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 BindingDelegate _bindingDelegate;
10 _TemplateIterator _templateIterator; 11 _TemplateIterator _templateIterator;
12 bool _scheduled = false;
11 13
12 _TemplateExtension(Element node) : super(node); 14 _TemplateExtension(Element node) : super(node);
13 15
14 void bind(String name, model, String path) { 16 void bind(String name, model, String path) {
15 switch (name) { 17 switch (name) {
16 case 'bind': 18 case 'bind':
17 case 'repeat': 19 case 'repeat':
18 case 'if': 20 case 'if':
19 if (_templateIterator == null) { 21 if (_templateIterator == null) {
20 _templateIterator = new _TemplateIterator(node); 22 _templateIterator = new _TemplateIterator(node);
(...skipping 22 matching lines...) Expand all
43 void unbindAll() { 45 void unbindAll() {
44 unbind('bind'); 46 unbind('bind');
45 unbind('repeat'); 47 unbind('repeat');
46 unbind('if'); 48 unbind('if');
47 super.unbindAll(); 49 super.unbindAll();
48 } 50 }
49 51
50 /** 52 /**
51 * Creates an instance of the template. 53 * Creates an instance of the template.
52 */ 54 */
53 DocumentFragment createInstance(model, String syntax) { 55 DocumentFragment createInstance(model, BindingDelegate delegate) {
54 var template = node.ref; 56 var template = node.ref;
55 if (template == null) template = node; 57 if (template == null) template = node;
56 58
57 var instance = _createDeepCloneAndDecorateTemplates( 59 var instance = _createDeepCloneAndDecorateTemplates(
58 template.content, syntax); 60 template.content, delegate);
59 61
60 if (_instanceCreated != null) _instanceCreated.add(instance); 62 if (_instanceCreated != null) _instanceCreated.add(instance);
61 63
62 _addBindings(instance, model, TemplateElement.syntax[syntax]); 64 _addBindings(instance, model, delegate);
63 _addTemplateInstanceRecord(instance, model); 65 _addTemplateInstanceRecord(instance, model);
64 return instance; 66 return instance;
65 } 67 }
66 68
67 /** 69 /**
68 * The data model which is inherited through the tree. 70 * The data model which is inherited through the tree.
69 */ 71 */
70 get model => _model; 72 get model => _model;
71 73
72 void set model(value) { 74 void set model(value) {
73 var syntax = TemplateElement.syntax[node.attributes['syntax']];
74 _model = value; 75 _model = value;
75 _addBindings(node, model, syntax); 76 _ensureSetModelScheduled();
77 }
78
79 /**
80 * The binding delegate which is inherited through the tree. It can be used
81 * to configure custom syntax for `{{bindings}}` inside this template.
82 */
83 BindingDelegate get bindingDelegate => _bindingDelegate;
84
85 void set bindingDelegate(BindingDelegate value) {
86 _bindingDelegate = value;
87 _ensureSetModelScheduled();
88 }
89
90 _ensureSetModelScheduled() {
91 if (_scheduled) return;
92 _scheduled = true;
93 runAsync(_setModel);
94 }
95
96 void _setModel() {
97 _scheduled = false;
98 _addBindings(node, _model, _bindingDelegate);
76 } 99 }
77 } 100 }
OLDNEW
« no previous file with comments | « pkg/mdv/lib/mdv.dart ('k') | pkg/mdv/lib/src/template_iterator.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698