Hopefully a straight forward question: where should I put plain JavaScript that I can use between a few different components?
I have a couple of different component that have a isActive
property based on whether the current route maps to a route passed ot the component. Something like:
export default class MenuItemSimpleComponent extends Component {
@service router;
get isActive() {
const route = this.args.route.split('.');
const curr = this.router.currentRouteName.split('.');
// from here to the end is basically POJS and could be in a reusable function somewhere
const stripThese = ['new', 'edit', 'index', 'modal'];
if (stripThese.includes(curr[curr.length - 1])) { curr.pop(); }
return pluralize(route[route.length - 1]) == pluralize(curr[curr.length - 1]);
}
To rephrase: what is the best practices for extracting out a reusable chunk of POJS in Ember 4?