wilsonpage / fastdom

Eliminates layout thrashing by batching DOM measurement and mutation tasks
6.85k stars 240 forks source link

clear method on promise doesn't clear the tasks map #102

Closed jasonmacdonald closed 7 years ago

jasonmacdonald commented 7 years ago

Looking at the clear method on fastdom-promised, the task.delete is called using the "task" function instead of the "promise" object, which is what was used for the key in the map. The method clears the task from fastdom itself, but it leaves the promise in the _tasks(map). You can verify this by checking map.size after calling clear.

let promise = fastdom.measure(()=>{}, this);

// tries to delete the function, not the promise form _tasks.map
fastdom.clear(promise); 

 // fails with size equal to 1
expect(fastdom._tasks.size).toBe(0);

I found this while trying to write a unit test on my clear method.

line 42 in fastdom-promised should be

tasks.delete(promise);