RE: Last Call comments

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