github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/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.get('stateCache'); 15 const key = this.get('key'); 16 const deepKey = `item.${key}`; 17 const startExpanded = this.get('startExpanded'); 18 19 const decoratedSource = this.get('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 });