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

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

Issue 812713005: Add declarataive event handlers. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Add tests and fix binding Created 6 years 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/examples/widgets/index.sky ('k') | sky/tests/framework/templates.sky » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/sky-element/TemplateBinding.sky
diff --git a/sky/framework/sky-element/TemplateBinding.sky b/sky/framework/sky-element/TemplateBinding.sky
index 65d9bb5d3667a33e59b649ff83040507f8130be1..1000094526302b2a835bbffbed705aa243337670 100644
--- a/sky/framework/sky-element/TemplateBinding.sky
+++ b/sky/framework/sky-element/TemplateBinding.sky
@@ -14,7 +14,7 @@ Node.prototype.bind = function(name, observable, oneTime) {
return;
}
- observable.open(function(value) {
+ this[name] = observable.open(function(value) {
self[name] = value;
});
@@ -544,6 +544,16 @@ function parseWithDefault(el, name, prepareBindingFn) {
return parseMustaches(v == '' ? '{{}}' : v, name, el, prepareBindingFn);
}
+function addEventHandler(element, name, method) {
+ element.addEventListener(name, function(event) {
+ var scope = element.ownerScope;
+ var host = scope.host;
+ var handler = host && host[method];
+ if (handler instanceof Function)
+ return handler.call(host, event);
+ });
+}
+
function parseAttributeBindings(element, prepareBindingFn) {
var bindings = [];
var ifFound = false;
@@ -560,6 +570,13 @@ function parseAttributeBindings(element, prepareBindingFn) {
continue;
}
+ if (name.startsWith('on-')) {
+ if (!bindings.eventHandlers)
+ bindings.eventHandlers = new Map();
+ bindings.eventHandlers.set(name.substring(3), value);
+ continue;
+ }
+
var tokens = parseMustaches(value, name, element,
prepareBindingFn);
if (!tokens)
@@ -618,6 +635,12 @@ function cloneAndBindInstance(node, parent, stagingDocument, bindings, model,
clone.setDelegate_(delegate);
}
+ if (bindings.eventHandlers) {
+ bindings.eventHandlers.forEach(function(handler, eventName) {
+ addEventHandler(clone, eventName, handler);
+ });
+ }
+
processBindings(clone, bindings, model, instanceBindings);
return clone;
}
« no previous file with comments | « sky/examples/widgets/index.sky ('k') | sky/tests/framework/templates.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698