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

Unified Diff: sdk/lib/html/dart2js/html_dart2js.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: 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/html/dart2js/html_dart2js.dart
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
index 2870931c48a5e8e8b2d82acc62f5573727bfa9d1..887b4dc2ada4263a1a17c3edad9ecc8025e1c9dc 100644
--- a/sdk/lib/html/dart2js/html_dart2js.dart
+++ b/sdk/lib/html/dart2js/html_dart2js.dart
@@ -8614,13 +8614,15 @@ abstract class Element extends Node implements ElementTraversal native "Element"
}
/**
- * Creates an instance of the template.
+ * Creates an instance of the template, using the provided model and binding
+ * delegate.
+ *
* This is only supported if [isTemplate] is true.
*/
@Experimental()
- DocumentFragment createInstance(model, String syntax) {
+ DocumentFragment createInstance(model, BindingDelegate delegate) {
_ensureTemplate();
- return TemplateElement.mdvPackage(this).createInstance(model, syntax);
+ return TemplateElement.mdvPackage(this).createInstance(model, delegate);
}
/**
@@ -8636,6 +8638,22 @@ abstract class Element extends Node implements ElementTraversal native "Element"
TemplateElement.mdvPackage(this).model = value;
}
+ /**
+ * The binding delegate which is inherited through the tree. It can be used
+ * to configure custom syntax for `{{bindings}}` inside this template.
+ *
+ * This is only supported if [isTemplate] is true.
+ */
+ @Experimental()
+ BindingDelegate get bindingDelegate =>
+ TemplateElement.mdvPackage(this).bindingDelegate;
+
+ @Experimental()
+ void set bindingDelegate(BindingDelegate value) {
+ _ensureTemplate();
+ TemplateElement.mdvPackage(this).bindingDelegate = value;
+ }
+
// TODO(jmesserly): const set would be better
static const _TABLE_TAGS = const {
'caption': null,
@@ -21393,7 +21411,6 @@ class TableSectionElement extends _HTMLElement native "HTMLTableSectionElement"
// WARNING: Do not edit - generated code.
-
/**
* Model-Driven Views (MDV)'s native features enables a wide-range of use cases,
* but (by design) don't attempt to implement a wide array of specialized
@@ -21402,32 +21419,31 @@ class TableSectionElement extends _HTMLElement native "HTMLTableSectionElement"
* Enabling these features in MDV is a matter of implementing and registering an
* MDV Custom Syntax. A Custom Syntax is an object which contains one or more
* delegation functions which implement specialized behavior. This object is
- * registered with MDV via [TemplateElement.syntax]:
+ * registered with MDV via [Element.bindingDelegate]:
*
*
* HTML:
- * <template bind syntax="MySyntax">
+ * <template bind>
* {{ What!Ever('crazy')->thing^^^I+Want(data) }}
* </template>
*
* Dart:
- * class MySyntax extends CustomBindingSyntax {
+ * class MySyntax extends BindingDelegate {
* getBinding(model, path, name, node) {
* // The magic happens here!
* }
* }
- *
* ...
- *
- * TemplateElement.syntax['MySyntax'] = new MySyntax();
+ * query('template').bindingDelegate = new MySyntax();
+ * query('template').model = new MyModel();
*
* See <https://github.com/polymer-project/mdv/blob/master/docs/syntax.md> for
* more information about Custom Syntax.
*/
-// TODO(jmesserly): if this is just one method, a function type would make it
-// more Dart-friendly.
-@Experimental()
-abstract class CustomBindingSyntax {
+// TODO(jmesserly): move this type to the MDV package? Two issues: we'd lose
+// type annotation on [Element.bindingDelegate], and "mdv" is normally imported
+// with a prefix.
+abstract class BindingDelegate {
/**
* This syntax method allows for a custom interpretation of the contents of
* mustaches (`{{` ... `}}`).
@@ -21476,7 +21492,6 @@ abstract class CustomBindingSyntax {
getInstanceModel(Element template, model) => model;
}
-
@Experimental()
@DomName('HTMLTemplateElement')
@SupportedBrowser(SupportedBrowser.CHROME)
@@ -21696,13 +21711,6 @@ option[template] {
}''';
document.head.append(style);
}
-
- /**
- * A mapping of names to Custom Syntax objects. See [CustomBindingSyntax] for
- * more information.
- */
- @Experimental()
- static Map<String, CustomBindingSyntax> syntax = {};
}
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a

Powered by Google App Engine
This is Rietveld 408576698