Function

invokeHelper (context, definition, computeArgs) public

Module: @ember/helper
context
Object
The parent context of the helper
definition
Object
The helper definition
computeArgs
Function
An optional function that produces args
returns

The invokeHelper function can be used to create a helper instance in JavaScript.

// app/components/data-loader.js
import Component from '@glimmer/component';
import Helper from '@ember/component/helper';
import { invokeHelper } from '@ember/helper';

class PlusOne extends Helper {
  compute([num]) {
    return number + 1;
  }
}

export default class PlusOne extends Component {
  plusOne = invokeHelper(this, RemoteData, () => {
    return {
      positional: [this.args.number],
    };
  });
}
{{this.plusOne.value}}

It receives three arguments:

  • context: The parent context of the helper. When the parent is torn down and removed, the helper will be as well.
  • definition: The definition of the helper.
  • computeArgs: An optional function that produces the arguments to the helper. The function receives the parent context as an argument, and must return an object with a positional property that is an array and/or a named property that is an object.

And it returns a Cache instance that contains the most recent value of the helper. You can access the helper using getValue() like any other cache. The cache is also destroyable, and using the destroy() function on it will cause the helper to be torn down.

Note that using getValue() on helpers that have scheduled effects will not trigger the effect early. Effects will continue to run at their scheduled time.

© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/functions/@ember%2Fhelper/invokeHelper