mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 02:15:43 +03:00
Simple bind helper
This binds a function to a target before passing it along to another component. It's normal to expect to get to use `this` within functions on components and controllers, but (sans actions) that doesn't happen automatically.
This commit is contained in:
17
ui/app/helpers/bind.js
Normal file
17
ui/app/helpers/bind.js
Normal file
@@ -0,0 +1,17 @@
|
||||
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);
|
||||
Reference in New Issue
Block a user