ember/jquery-ember-run

November 8, 2022 · View on GitHub

💼 This rule is enabled in the ✅ recommended config.

Don’t use jQuery without the Ember Run Loop.

Using plain jQuery invokes actions outside of the Ember Run Loop. In order to have a control on all operations in Ember, it's good practice to trigger actions in a run loop (using one of the @ember/runloop functions).

Examples

Examples of incorrect code for this rule:

import $ from 'jquery';

$('#something-rendered-by-jquery-plugin').on('click', () => {
  this._handlerActionFromController();
});

Examples of correct code for this rule:

import $ from 'jquery';
import { bind } from '@ember/runloop';

$('#something-rendered-by-jquery-plugin').on(
  'click',
  bind(this, this._handlerActionFromController)
);