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

Unified Diff: sky/framework/sky-element/sky-binder.sky

Issue 856693002: Combine element registries from sky-binder and sky-element. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « sky/framework/sky-element/element-registry.sky ('k') | sky/framework/sky-element/sky-element.sky » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/sky-element/sky-binder.sky
diff --git a/sky/framework/sky-element/sky-binder.sky b/sky/framework/sky-element/sky-binder.sky
index aca84a3e8393e32a92a279bb29163e234e32bb65..b7ae88cabb650ace061f231dcaff2dbf27cadc8a 100644
--- a/sky/framework/sky-element/sky-binder.sky
+++ b/sky/framework/sky-element/sky-binder.sky
@@ -4,6 +4,7 @@
// found in the LICENSE file.
-->
<import src="observe.sky" as="observe" />
+<import src="element-registry.sky" as="registry" />
<script>
var stagingDocument = new Document();
@@ -26,45 +27,11 @@ class TemplateInstance {
var emptyInstance = new TemplateInstance();
var directiveCache = new WeakMap();
-// TODO(esprehn): It would be nice if these were exposed by the platform so
-// the framework didn't need to hard code a list.
-var defaultAttributesNames = new Set([
- 'accesskey',
- 'alt',
- 'as',
- 'async',
- 'class',
- 'contenteditable',
- 'crossorigin',
- 'dir',
- 'height',
- 'href',
- 'id',
- 'is',
- 'lang',
- 'media',
- 'name',
- 'rel',
- 'select',
- 'sizes',
- 'spellcheck',
- 'src',
- 'srcset',
- 'style',
- 'tabindex',
- 'title',
- 'type',
- 'width',
-]);
-var elementAttributeNames = new Map();
-
-function registerElement(name, options) {
- elementAttributeNames.set(name, new Set(options.attributeNames));
-}
-
-registerElement('template', {
- attributeNames: ['if', 'repeat'],
-});
+(function() {
+ var templateRegistration = registry.registerElement('template');
+ templateRegistration.defineAttribute('if', 'string');
+ templateRegistration.defineAttribute('repeat', 'string');
+})();
function createInstance(template, model) {
var content = template.content;
@@ -196,20 +163,9 @@ function parsePropertyDirective(value, property) {
return result;
}
-function checkAttribute(name, allowedAttributeNames) {
- if (name.startsWith('data-'))
- return true;
- if (defaultAttributesNames.has(name))
- return true;
- if (allowedAttributeNames && allowedAttributeNames.has(name))
- return true;
- return false;
-}
-
function parseAttributeDirectives(element, directives) {
var attributes = element.getAttributes();
-
- var allowedAttributeNames = elementAttributeNames.get(element.tagName);
+ var tagName = element.tagName;
for (var i = 0; i < attributes.length; i++) {
var attr = attributes[i];
@@ -221,8 +177,8 @@ function parseAttributeDirectives(element, directives) {
continue;
}
- if (!checkAttribute(name, allowedAttributeNames)) {
- console.error('Element "'+ element.tagName +
+ if (!registry.checkAttribute(tagName, name)) {
+ console.error('Element "'+ tagName +
'" has unknown attribute "' + name + '".');
}
@@ -526,6 +482,5 @@ class TemplateIterator {
module.exports = {
createInstance: createInstance,
- registerElement: registerElement,
};
</script>
« no previous file with comments | « sky/framework/sky-element/element-registry.sky ('k') | sky/framework/sky-element/sky-element.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698