Skip to content

Commit

Permalink
optimize lookups when adding event listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed May 26, 2017
1 parent f05e97f commit 2509ffd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
18 changes: 10 additions & 8 deletions dist/moon.js
Original file line number Diff line number Diff line change
Expand Up @@ -2262,11 +2262,12 @@

// Final event listener code
var code = 'function(event) {' + modifiers + 'instance.callMethod("' + methodToCall + '", [' + params + '])}';
var eventListeners = vnode.meta.eventListeners[eventType];
if (eventListeners === undefined) {
vnode.meta.eventListeners[eventType] = [code];
var eventListeners = vnode.meta.eventListeners;
var eventHandlers = eventListeners[eventType];
if (eventHandlers === undefined) {
eventListeners[eventType] = [code];
} else {
eventListeners.push(code);
eventHandlers.push(code);
}
}
};
Expand Down Expand Up @@ -2328,11 +2329,12 @@
var code = 'function(event) {instance.set("' + keypath + '", event.target.' + valueProp + ')}';

// Push the listener to it's event listeners
var eventListeners = vnode.meta.eventListeners[eventType];
if (eventListeners === undefined) {
vnode.meta.eventListeners[eventType] = [code];
var eventListeners = vnode.meta.eventListeners;
var eventHandlers = eventListeners[eventType];
if (eventHandlers === undefined) {
eventListeners[eventType] = [code];
} else {
eventListeners.push(code);
eventHandlers.push(code);
}

// Setup a query used to get the value, and set the corresponding dom property
Expand Down
Loading

0 comments on commit 2509ffd

Please sign in to comment.