github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/ui/app/components/json-viewer.js (about)

     1  import Ember from 'ember';
     2  import JSONFormatterPkg from 'npm:json-formatter-js';
     3  
     4  const { Component, computed, run } = Ember;
     5  
     6  // json-formatter-js is packaged in a funny way that ember-cli-browserify
     7  // doesn't unwrap properly.
     8  const { default: JSONFormatter } = JSONFormatterPkg;
     9  
    10  export default Component.extend({
    11    classNames: ['json-viewer'],
    12  
    13    json: null,
    14    expandDepth: Infinity,
    15  
    16    formatter: computed('json', 'expandDepth', function() {
    17      return new JSONFormatter(this.get('json'), this.get('expandDepth'), {
    18        theme: 'nomad',
    19      });
    20    }),
    21  
    22    didReceiveAttrs() {
    23      const json = this.get('json');
    24      if (!json) {
    25        return;
    26      }
    27  
    28      run.scheduleOnce('afterRender', this, embedViewer);
    29    },
    30  });
    31  
    32  function embedViewer() {
    33    this.$()
    34      .empty()
    35      .append(this.get('formatter').render());
    36  }