Skip to content

Latest commit

 

History

History
84 lines (61 loc) · 2.77 KB

no-runloop.md

File metadata and controls

84 lines (61 loc) · 2.77 KB

ember/no-runloop

💼 This rule is enabled in the ✅ recommended config.

Ember's runloop functions are not lifecycle-aware and don't ensure that an object's async is cleaned up. It is recommended to use ember-lifeline, ember-concurrency, or @ember/destroyable instead.

Rule Details

This rule disallows usage of @ember/runloop functions.

Examples

Example of incorrect code for this rule:

import Component from '@glimmer/component';
import { run } from '@ember/runloop';

export default class MyComponent extends Component {
  constructor(...args) {
    super(...args);

    run.later(() => {
      this.set('date', new Date());
    }, 500);
  }
}

Example of correct code for this rule using ember-lifeline:

import Component from '@glimmer/component';
import { runTask, runDisposables } from 'ember-lifeline';

export default class MyComponent extends Component {
  constructor(...args) {
    super(...args);

    runTask(
      this,
      () => {
        this.set('date', new Date());
      },
      500
    );
  }

  willDestroy(...args) {
    super.willDestroy(...args);

    runDisposables(this);
  }
}

Configuration

Name Description Type
allowList If you have @ember/runloop functions that you wish to allow, you can configure this rule to allow specific methods. The configuration takes an object with the allowList property, which is an array of strings where the strings must be names of runloop functions. String[]
module.exports = {
  rules: {
    'ember/no-runloop': [
      'error',
      {
        allowList: ['debounce', 'begin', 'end'],
      },
    ],
  },
};

References

  • require-lifeline - a rule that was originally implemented in eslint-plugin-ember-best-practices