💼 This rule is enabled in the ✅ recommended
config.
The following functions keep track of the function references they have been passed:
debounce
once
scheduleOnce
To use them, make sure you are passing the same function reference each time. When an inline function is passed as an argument, the function reference will be different each time.
This rule disallows using inline anonymous functions with the debounce
, once
, and scheduleOnce
methods when imported from @ember/runloop
.
Examples of incorrect code for this rule:
import { scheduleOnce, once, debounce } from '@ember/runloop';
export default Component.extend({
didInsertElement() {
this.doWork();
this.doWork();
},
doWork() {
debounce(() => {
/* this will run twice */
}, 300);
once(() => {
/* this will run twice */
});
scheduleOnce('afterRender', function () {
/* this will run twice */
});
}
});
Examples of correct code for this rule:
import { scheduleOnce } from '@ember/runloop';
export default Component.extend({
didInsertElement() {
this.doWork();
this.doWork();
},
doWork() {
scheduleOnce('afterRender', this, this.deferredWork);
},
deferredWork() {
/* this will only run once */
}
});