Opened 5 years ago

Closed 5 years ago

#17615 closed enhancement (fixed)

[CLA][PATCH] Add debounce/throttle to dojo/on

Reported by: iDo Owned by: bpayton
Priority: high Milestone: 1.10
Component: Events Version: 1.9.1
Keywords: Cc:
Blocked By: Blocking:

Description

Hi, We are all used to debounce repeated event (like mousemove). I usually debounce the callback of a dojo/on :

on('div', 'mousemove', debounce(function(e) {/*...*/}));

However, dojo code is still running in the background. For instance:

on('body', '.myDiv:mousemove', debounce(function(e) {/*...*/}));

This will fire the on.selector and check if the event match the requirements at every mouse move. And only in case of a match, the callback will be debounced.

I wanted to optimize this by debouncing the on.selector instead of the callback. So I came with the attached patch. It allow to debounce any dojo/on, even a on.once (which may be usefull)

Of course, all the previous apply to throttle.

The use is:

x = on('div', 'mousemove', function(e) { /*...*/ });
x.debounce(200); //in ms

Regards, Ben

Attachments (3)

on.patch (6.1 KB) - added by iDo 5 years ago.
patch for dojo/on.js
demo.html (4.1 KB) - added by iDo 5 years ago.
demo file
on.js (26.4 KB) - added by iDo 5 years ago.
complete on.js file (comming from git hub - 05-dec-13)

Download all attachments as: .zip

Change History (6)

Changed 5 years ago by iDo

Attachment: on.patch added

patch for dojo/on.js

Changed 5 years ago by iDo

Attachment: demo.html added

demo file

Changed 5 years ago by iDo

Attachment: on.js added

complete on.js file (comming from git hub - 05-dec-13)

comment:2 Changed 5 years ago by dylan

Milestone: tbd1.10
Owner: set to bpayton
Priority: undecidedhigh
Status: newassigned

comment:3 Changed 5 years ago by Brandon Payton <brandon@…>

Resolution: fixed
Status: assignedclosed

In d42c7974bf21fd4598132fc3adb81efbaf6b8747/dojo:

Error: Processor CommitTicketReference failed
Unsupported version control system "git": Can't find an appropriate component, maybe the corresponding plugin was not enabled? 
Note: See TracTickets for help on using tickets.