@fleetbase/ember-ui
Version:
Fleetbase UI provides all the interface components, helpers, services and utilities for building a Fleetbase extension into the Console.
24 lines (21 loc) • 619 B
JavaScript
import { helper } from '@ember/component/helper';
/**
* Usage:
* @onChange={{set-model-attr @model "attrName"}}
* @onChange={{set-model-attr @issue "type" prop="code"}}
*
* The selected object will be passed to the callback, and we set model[attr] = selected[prop].
*/
export default helper(function setModelAttr([model, attr], { prop = 'value' } = {}) {
if (!model || !attr) {
return () => {};
}
return (selected) => {
if (!selected) {
model.set(attr, null);
return;
}
const val = selected[prop];
model.set(attr, val);
};
});