Using mixins makes sharing code simple at first, but add significant complexity as a project developes and grows larger.
For more details and examples of how mixins create problems down-the-line, see these excellent blog posts:
// GOOD
// my-utils.js
export function isValidClassName(classname) {
return !!className.match('-class');
}
export function hideModal(obj, value) {
set(obj, 'isHidden', value);
}
// my-component.js
import { isValidClassName } from 'my-utils';
export default Component.extend({
aComputedProperty: computed('obj', function() {
return isValidClassName(get(obj, 'className'));
}),
});
===========================================================
// BAD
// my-mixin.js
export default Mixin.create({
isValidClassName(classname) {
return !!className.match('-class');
},
hideModal(value) {
this.set('isHidden', value);
}
});
// my-component.js
import myMixin from 'my-mixin';
export default Component.extend(myMixin, {
aComputedProperty: computed('obj', function() {
return this.isValidClassName(get(obj, 'className'));
}),
});