Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Use explicit properties to avoid for-in loops
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreedm committed Oct 9, 2013
1 parent 587288a commit 9d77270
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 15 deletions.
17 changes: 7 additions & 10 deletions src/PointerGestureEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,17 @@ function PointerGestureEvent(inType, inDict) {
var dict = inDict || {};
var e = document.createEvent('Event');
var props = {
bubbles: true,
cancelable: true,
bubbles: Boolean(dict.bubbles) === dict.bubbles || true,
cancelable: Boolean(dict.cancelable) === dict.cancelable || true
};
Object.keys(props).forEach(function(k) {
if (k in dict) {
props[k] = dict[k];
}
});

e.initEvent(inType, props.bubbles, props.cancelable);

Object.keys(dict).forEach(function(k) {
e[k] = inDict[k];
});
var keys = Object.keys(dict), k;
for (var i = 0; i < keys.length; i++) {
k = keys[i];
e[k] = dict[k];
}

e.preventTap = this.preventTap;

Expand Down
87 changes: 82 additions & 5 deletions src/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,85 @@
*/

(function(scope) {
var CLONE_PROPS = [
// MouseEvent
'bubbles',
'cancelable',
'view',
'detail',
'screenX',
'screenY',
'clientX',
'clientY',
'ctrlKey',
'altKey',
'shiftKey',
'metaKey',
'button',
'relatedTarget',
// DOM Level 3
'buttons',
// PointerEvent
'pointerId',
'width',
'height',
'pressure',
'tiltX',
'tiltY',
'pointerType',
'hwTimestamp',
'isPrimary',
// event instance
'type',
'target',
'currentTarget',
'screenX',
'screenY',
'pageX',
'pageY',
];

var CLONE_DEFAULTS = [
// MouseEvent
false,
false,
null,
null,
0,
0,
0,
0,
false,
false,
false,
false,
0,
null,
// DOM Level 3
0,
// PointerEvent
0,
0,
0,
0,
0,
0,
'',
0,
false,
// event instance
'',
null,
null,
0,
0,
0,
0
];

var dispatcher = {
handledEvents: new WeakMap,
targets: new WeakMap,
handledEvents: new WeakMap(),
targets: new WeakMap(),
handlers: {},
recognizers: {},
events: {},
Expand Down Expand Up @@ -98,9 +174,10 @@
* properties.
*/
cloneEvent: function(inEvent) {
var eventCopy = {};
for (var n in inEvent) {
eventCopy[n] = inEvent[n];
var eventCopy = {}, p;
for (var i = 0; i < CLONE_PROPS.length; i++) {
p = CLONE_PROPS[i];
eventCopy[p] = inEvent[p] || CLONE_DEFAULTS[i];
}
return eventCopy;
},
Expand Down

0 comments on commit 9d77270

Please sign in to comment.