#93·fastdom

[Feature Request] Helpful util to add and clear the last task

Author: tusharmathCreated Aug 23, 2016Updated Apr 11, 2017

The usecase is to throttle touchmove events in the dom. As of now we have to schedule it via mutate and then clear it when the next one comes. This can't be done easily and one needs to write a wrapper sort of like this —

javascript
function mutateLatest () {
  let id = null
  return function (task) {
   if(id) fastdom.clear(id)
   id = fastdom.mutate(task)
  }
}

The second problem is that it should be performing poorer because of the time complexity of n to remove an element from the queue.