- From: Jacob Rossi <Jacob.Rossi@microsoft.com>
- Date: Fri, 22 Mar 2013 22:49:02 +0000
- To: Jacob Rossi <Jacob.Rossi@microsoft.com>, Matt Brubeck <mbrubeck@mozilla.com>, Konstantinov Sergey <twirl@yandex-team.ru>, "public-pointer-events@w3.org" <public-pointer-events@w3.org>
On Fri, Mar 22, 2013 at 3:04 PM, Matt Brubeck <mbrubeck@mozilla.com> wrote: > > On 3/22/2013 2:33 PM, Jacob Rossi wrote: >> >> var pointerList = []; //Array off all active pointers, indexed by >> pointer ID, that has all the latest info about each >> >> window.addEventListener("pointerdown", addPointer, true); >> window.addEventListener("pointermove", addPointer, true); >> window.addEventListener("pointerup", remPointer, true); >> window.addEventListener("pointercancel", remPointer, true); >> >> function updatePointer(e) { pointerList[e.pointerId] = e; } function >> remPointer(e) { delete pointerList[e.pointerId]; } > > I wouldn't recommend this exact code: Since pointerId can be an arbitrary integer, looping through this array could take a very long time (for example if the UA decided to use pointerIds starting at 1,000,000). And getting the number of pointers is *not* as simple as pointerList.length. > > However, if you replace the Array with an ES6 Map object, then the basic approach should work fine. Fair point. In lieu of interoperable ES6 Maps, you can work use for-in iteration. If you want the count of pointers, then that could be maintained fairly easy since you have explicit add/delete points. [Update:] Or, you could do Object.keys(pointerList).length for the count.
Received on Friday, 22 March 2013 22:52:16 UTC