W3cubDocs

/Ember.js

Ember.Helper (public)

Defined in: packages/ember-glimmer/lib/helper.js:12
Module: ember

compute (params, hash) public

params
Array
The positional arguments to the helper
hash
Object
The named arguments to the helper

Override this function when writing a class-based helper.

helper (helper) public

helper
Function
The helper function

In many cases, the ceremony of a full Ember.Helper class is not required. The helper method create pure-function helpers without instances. For example:

// app/helpers/format-currency.js
export default Ember.Helper.helper(function(params, hash) {
  let cents = params[0];
  let currency = hash.currency;
  return `${currency}${cents * 0.01}`;
});

recompute public

On a class-based helper, it may be useful to force a recomputation of that helpers value. This is akin to rerender on a component.

For example, this component will rerender when the currentUser on a session service changes:

// app/helpers/current-user-email.js
export default Ember.Helper.extend({
  session: Ember.inject.service(),
  onNewUser: Ember.observer('session.currentUser', function() {
    this.recompute();
  }),
  compute() {
    return this.get('session.currentUser.email');
  }
});

© 2017 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://emberjs.com/api/ember/2.15/classes/Ember.Helper/methods