Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Replace PointerMap with polyfill for regular Map
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartpb committed May 18, 2015
1 parent 43ce883 commit 7b87104
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/dispatcher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PointerMap from 'pointermap';
import Map from 'map';

var CLONE_PROPS = [

Expand Down Expand Up @@ -99,7 +99,7 @@ var HAS_SVG_INSTANCE = (typeof SVGElementInstance !== 'undefined');
* - pointercancel: a pointer will no longer generate events
*/
var dispatcher = {
pointermap: new PointerMap(),
pointermap: new Map(),
eventMap: Object.create(null),
captureInfo: Object.create(null),

Expand Down
17 changes: 7 additions & 10 deletions src/pointermap.js → src/map.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
/**
* This module implements an map of pointer states
*/
var USE_MAP = window.Map && window.Map.prototype.forEach;
var POINTERS_FN = function() { return this.size; };
function PointerMap() {
if (USE_MAP) {
var m = new Map();
m.pointers = POINTERS_FN;
return m;
var USE_EXISTING_MAP = window.Map && window.Map.prototype.forEach;
function Map() {
if (USE_EXISTING_MAP) {
return new Map();
} else {
this.keys = [];
this.values = [];
}
}

PointerMap.prototype = {
Map.prototype = {
set: function(inId, inEvent) {
var i = this.keys.indexOf(inId);
if (i > -1) {
Expand Down Expand Up @@ -49,9 +46,9 @@ PointerMap.prototype = {
callback.call(thisArg, v, this.keys[i], this);
}, this);
},
pointers: function() {
get size() {
return this.keys.length;
}
};

export default PointerMap;
export default Map;
6 changes: 3 additions & 3 deletions src/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var touchEvents = {
setPrimaryTouch: function(inTouch) {

// set primary touch if there no pointers, or the only pointer is the mouse
if (pointermap.pointers() === 0 || (pointermap.pointers() === 1 && pointermap.has(1))) {
if (pointermap.size() === 0 || (pointermap.size() === 1 && pointermap.has(1))) {
this.firstTouch = inTouch.identifier;
this.firstXY = { X: inTouch.clientX, Y: inTouch.clientY };
this.scrolling = false;
Expand Down Expand Up @@ -233,9 +233,9 @@ var touchEvents = {
vacuumTouches: function(inEvent) {
var tl = inEvent.touches;

// pointermap.pointers() should be < tl.length here, as the touchstart has not
// pointermap.size() should be < tl.length here, as the touchstart has not
// been processed yet.
if (pointermap.pointers() >= tl.length) {
if (pointermap.size() >= tl.length) {
var d = [];
pointermap.forEach(function(value, key) {

Expand Down

0 comments on commit 7b87104

Please sign in to comment.