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

Commit 9d77270

Browse files
committed
Use explicit properties to avoid for-in loops
1 parent 587288a commit 9d77270

File tree

2 files changed

+89
-15
lines changed

2 files changed

+89
-15
lines changed

src/PointerGestureEvent.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,17 @@ function PointerGestureEvent(inType, inDict) {
1919
var dict = inDict || {};
2020
var e = document.createEvent('Event');
2121
var props = {
22-
bubbles: true,
23-
cancelable: true,
22+
bubbles: Boolean(dict.bubbles) === dict.bubbles || true,
23+
cancelable: Boolean(dict.cancelable) === dict.cancelable || true
2424
};
25-
Object.keys(props).forEach(function(k) {
26-
if (k in dict) {
27-
props[k] = dict[k];
28-
}
29-
});
3025

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

33-
Object.keys(dict).forEach(function(k) {
34-
e[k] = inDict[k];
35-
});
28+
var keys = Object.keys(dict), k;
29+
for (var i = 0; i < keys.length; i++) {
30+
k = keys[i];
31+
e[k] = dict[k];
32+
}
3633

3734
e.preventTap = this.preventTap;
3835

src/dispatcher.js

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,85 @@
55
*/
66

77
(function(scope) {
8+
var CLONE_PROPS = [
9+
// MouseEvent
10+
'bubbles',
11+
'cancelable',
12+
'view',
13+
'detail',
14+
'screenX',
15+
'screenY',
16+
'clientX',
17+
'clientY',
18+
'ctrlKey',
19+
'altKey',
20+
'shiftKey',
21+
'metaKey',
22+
'button',
23+
'relatedTarget',
24+
// DOM Level 3
25+
'buttons',
26+
// PointerEvent
27+
'pointerId',
28+
'width',
29+
'height',
30+
'pressure',
31+
'tiltX',
32+
'tiltY',
33+
'pointerType',
34+
'hwTimestamp',
35+
'isPrimary',
36+
// event instance
37+
'type',
38+
'target',
39+
'currentTarget',
40+
'screenX',
41+
'screenY',
42+
'pageX',
43+
'pageY',
44+
];
45+
46+
var CLONE_DEFAULTS = [
47+
// MouseEvent
48+
false,
49+
false,
50+
null,
51+
null,
52+
0,
53+
0,
54+
0,
55+
0,
56+
false,
57+
false,
58+
false,
59+
false,
60+
0,
61+
null,
62+
// DOM Level 3
63+
0,
64+
// PointerEvent
65+
0,
66+
0,
67+
0,
68+
0,
69+
0,
70+
0,
71+
'',
72+
0,
73+
false,
74+
// event instance
75+
'',
76+
null,
77+
null,
78+
0,
79+
0,
80+
0,
81+
0
82+
];
83+
884
var dispatcher = {
9-
handledEvents: new WeakMap,
10-
targets: new WeakMap,
85+
handledEvents: new WeakMap(),
86+
targets: new WeakMap(),
1187
handlers: {},
1288
recognizers: {},
1389
events: {},
@@ -98,9 +174,10 @@
98174
* properties.
99175
*/
100176
cloneEvent: function(inEvent) {
101-
var eventCopy = {};
102-
for (var n in inEvent) {
103-
eventCopy[n] = inEvent[n];
177+
var eventCopy = {}, p;
178+
for (var i = 0; i < CLONE_PROPS.length; i++) {
179+
p = CLONE_PROPS[i];
180+
eventCopy[p] = inEvent[p] || CLONE_DEFAULTS[i];
104181
}
105182
return eventCopy;
106183
},

0 commit comments

Comments
 (0)