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

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

Issue 17552019: Reorganize mdv and observe packages (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: tests passing Created 7 years, 6 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
OLDNEW
(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 * Setting this will destructive propagate the value to all descendant nodes,
justinfagnani 2013/06/25 23:03:31 can we do an identity check to avoid churn in some
Jennifer Messerly 2013/06/26 23:09:12 fixed comment. it wasn't accurate (in light of fut
70 * and reinstantiate all of the nodes expanded by this template.
71 *
72 * Currently this does not support propagation through Shadow DOMs.
73 */
74 get model => _model;
75
76 void set model(value) {
77 var syntax = TemplateElement.syntax[node.attributes['syntax']];
78 _model = value;
79 _Bindings._addBindings(node, model, syntax);
80 }
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698