e9e52e0dfe
This doesn’t include Ember Data, as we are still back on 3.12. Most changes are deprecation updates, linting fixes, and dependencies. It can be read commit-by-commit, though many of them are mechanical and skimmable. For the new linting exclusions, I’ve added them to the Tech Debt list. The decrease in test count is because linting is no longer included in ember test. There’s a new deprecation warning in the logs that can be fixed by updating Ember Power Select but when I tried that it caused it to render incorrectly, so I decided to ignore it for now and address it separately.
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
import Component from '@ember/component';
|
|
import { computed, get } from '@ember/object';
|
|
import { computed as overridable } from 'ember-overridable-computed';
|
|
import { classNames } from '@ember-decorators/component';
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
@classic
|
|
@classNames('accordion')
|
|
export default class ListAccordion extends Component {
|
|
key = 'id';
|
|
@overridable(() => []) source;
|
|
|
|
onToggle /* item, isOpen */() {}
|
|
startExpanded = false;
|
|
|
|
@computed('key', 'source.[]', 'startExpanded', 'stateCache')
|
|
get decoratedSource() {
|
|
const stateCache = this.stateCache;
|
|
const key = this.key;
|
|
const deepKey = `item.${key}`;
|
|
const startExpanded = this.startExpanded;
|
|
|
|
const decoratedSource = this.source.map(item => {
|
|
const cacheItem = stateCache.findBy(deepKey, get(item, key));
|
|
return {
|
|
item,
|
|
isOpen: cacheItem ? !!cacheItem.isOpen : startExpanded,
|
|
};
|
|
});
|
|
|
|
// eslint-disable-next-line ember/no-side-effects
|
|
this.set('stateCache', decoratedSource);
|
|
return decoratedSource;
|
|
}
|
|
|
|
// When source updates come in, the state cache is used to preserve
|
|
// open/close state.
|
|
@overridable(() => []) stateCache;
|
|
}
|