Skip to content

Latest commit

 

History

History
68 lines (52 loc) · 1.79 KB

no-incorrect-calls-with-inline-anonymous-functions.md

File metadata and controls

68 lines (52 loc) · 1.79 KB

ember/no-incorrect-calls-with-inline-anonymous-functions

💼 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.

Rule Details

This rule disallows using inline anonymous functions with the debounce, once, and scheduleOnce methods when imported from @ember/runloop.

Examples

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 */
  }
});

References