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

Commit

Permalink
Merge pull request #14 from azakus/faster-clone
Browse files Browse the repository at this point in the history
Faster clone
  • Loading branch information
dfreedm committed Oct 9, 2013
2 parents 587288a + 1626b3a commit 6bfae8a
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 17 deletions.
3 changes: 1 addition & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ module.exports = function(karma) {
files: [
'PointerGestures/node_modules/chai/chai.js',
'PointerGestures/node_modules/chai-spies/chai-spies.js',
'WeakMap/weakmap.js',
'PointerEvents/src/boot.js',
'PointerEvents/src/PointerEvent.js',
'PointerEvents/src/pointermap.js',
'PointerEvents/src/sidetable.js',
'PointerEvents/src/dispatcher.js',
'PointerEvents/src/installer.js',
'PointerEvents/src/mouse.js',
Expand All @@ -21,7 +21,6 @@ module.exports = function(karma) {
'PointerEvents/src/capture.js',
'PointerGestures/src/PointerGestureEvent.js',
'PointerGestures/src/initialize.js',
'WeakMap/weakmap.js',
'PointerGestures/src/pointermap.js',
'PointerGestures/src/dispatcher.js',
'PointerGestures/src/hold.js',
Expand Down
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 6bfae8a

Please sign in to comment.