open-nomad/ui/app/helpers/bind.js
2023-04-10 15:36:59 +00:00

26 lines
582 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { helper } from '@ember/component/helper';
import { assert } from '@ember/debug';
/**
* bind
*
* Usage: {{bind this.function}}
*
* Returns a version of a function bound to the template target (e.g., component or controller)
*/
export function bind([func, target]) {
assert(
'A function is required as the first argument',
typeof func === 'function'
);
assert('A context is required as the second argument', target);
return func.bind(target);
}
export default helper(bind);