github.com/manicqin/nomad@v0.9.5/ui/app/components/list-accordion.js (about)

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