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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: pkg/mdv/lib/src/template.dart
diff --git a/pkg/mdv/lib/src/template.dart b/pkg/mdv/lib/src/template.dart
new file mode 100644
index 0000000000000000000000000000000000000000..0e1f560c12f08fc4ed137cdb1c2864e53d62f3dc
--- /dev/null
+++ b/pkg/mdv/lib/src/template.dart
@@ -0,0 +1,81 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of mdv;
+
+/** Extensions to [Element]s that behave as templates. */
+class _TemplateExtension extends _ElementExtension {
+ var _model;
+ _TemplateIterator _templateIterator;
+
+ _TemplateExtension(Element node) : super(node);
+
+ void bind(String name, model, String path) {
+ switch (name) {
+ case 'bind':
+ case 'repeat':
+ case 'if':
+ if (_templateIterator == null) {
+ _templateIterator = new _TemplateIterator(node);
+ }
+ _templateIterator.inputs.bind(name, model, path);
+ return;
+ default:
+ super.bind(name, model, path);
+ }
+ }
+
+ void unbind(String name) {
+ switch (name) {
+ case 'bind':
+ case 'repeat':
+ case 'if':
+ if (_templateIterator != null) {
+ _templateIterator.inputs.unbind(name);
+ }
+ return;
+ default:
+ super.unbind(name);
+ }
+ }
+
+ void unbindAll() {
+ unbind('bind');
+ unbind('repeat');
+ unbind('if');
+ super.unbindAll();
+ }
+
+ /**
+ * Creates an instance of the template.
+ */
+ DocumentFragment createInstance() {
+ var template = node.ref;
+ if (template == null) template = node;
+
+ var instance = _Bindings._createDeepCloneAndDecorateTemplates(
+ template.content, node.attributes['syntax']);
+
+ if (_instanceCreated != null) {
+ _instanceCreated.add(instance);
+ }
+ return instance;
+ }
+
+ /**
+ * The data model which is inherited through the tree.
+ *
+ * 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
+ * and reinstantiate all of the nodes expanded by this template.
+ *
+ * Currently this does not support propagation through Shadow DOMs.
+ */
+ get model => _model;
+
+ void set model(value) {
+ var syntax = TemplateElement.syntax[node.attributes['syntax']];
+ _model = value;
+ _Bindings._addBindings(node, model, syntax);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698