github.com/anuvu/nomad@v0.8.7-atom1/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    decoratedSource: computed('source.[]', function() {
    11      const stateCache = this.get('stateCache');
    12      const key = this.get('key');
    13      const deepKey = `item.${key}`;
    14  
    15      const decoratedSource = this.get('source').map(item => {
    16        const cacheItem = stateCache.findBy(deepKey, get(item, key));
    17        return {
    18          item,
    19          isOpen: cacheItem ? !!cacheItem.isOpen : false,
    20        };
    21      });
    22  
    23      this.set('stateCache', decoratedSource);
    24      return decoratedSource;
    25    }),
    26  
    27    // When source updates come in, the state cache is used to preserve
    28    // open/close state.
    29    stateCache: computed(() => []),
    30  });