github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/ui/app/components/list-accordion.js (about) 1 import Component from '@ember/component'; 2 import { computed, get } from '@ember/object'; 3 4 export default Component.extend({ 5 classNames: ['accordion'], 6 7 key: 'id', 8 source: computed(() => []), 9 10 onToggle(/* item, isOpen */) {}, 11 startExpanded: false, 12 13 decoratedSource: computed('source.[]', function() { 14 const stateCache = this.stateCache; 15 const key = this.key; 16 const deepKey = `item.${key}`; 17 const startExpanded = this.startExpanded; 18 19 const decoratedSource = this.source.map(item => { 20 const cacheItem = stateCache.findBy(deepKey, get(item, key)); 21 return { 22 item, 23 isOpen: cacheItem ? !!cacheItem.isOpen : startExpanded, 24 }; 25 }); 26 27 this.set('stateCache', decoratedSource); 28 return decoratedSource; 29 }), 30 31 // When source updates come in, the state cache is used to preserve 32 // open/close state. 33 stateCache: computed(() => []), 34 });