Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tusharmath opened this issue Aug 23, 2016 · 1 comment
Open

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

tusharmath opened this issue Aug 23, 2016 · 1 comment

Comments

@tusharmath
Copy link
Contributor

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 —

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.

@tusharmath tusharmath changed the title [Feature Request] Helpful to add and clear the last one [Feature Request] Helpful util to add and clear the last one Aug 23, 2016
@tusharmath tusharmath changed the title [Feature Request] Helpful util to add and clear the last one [Feature Request] Helpful util to add and clear the last task Aug 23, 2016
@oppianmatt
Copy link

Do you need fastdom to clear? When a touchmove event happens grab the coords (or whatever you need) and save it. Then queue up a raf to process it if it's not queued already. In your processing part that's where you use mutate/measure or whatever. And you won't need to cancel anything.

Like in here https://developers.google.com/web/fundamentals/performance/rendering/debounce-your-input-handlers

Basically you want your scroll/move handlers to be as fast as possible and finish quick. Less work the better. So the most they should do is save some variables and queue up a tick if not already queued. In the tick is where you do you work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants