<commit_before>import DS from 'ember-data';
import Ember from 'ember';

const { computed, RSVP } = Ember;
const { not } = computed;
const { Promise, all } = RSVP;
const { Model, attr, belongsTo, hasMany } = DS;

const inflector = Ember.Inflector.inflector;
inflector.uncountable('aamc-pcrs');

export default Model.extend({
  title: attr('string'),
  school: belongsTo('school', {async: true}),
  objectives: hasMany('objective', {async: true}),
  parent: belongsTo('competency', {async: true, inverse: 'children'}),
  children: hasMany('competency', {async: true, inverse: 'parent'}),
  aamcPcrses: hasMany('aamc-pcrs', {async: true}),
  programYears: hasMany('program-year', {async: true}),
  isDomain: computed('parent', function(){
    const parentId = this.belongsTo('parent').id();
    return !parentId;
  }),
  isNotDomain: not('isDomain'),

  domain: computed('parent', 'parent.domain', function() {
    return new Promise(resolve => {
      this.get('parent').then(parent => {
        if (!parent) {
          resolve(this);
        } else {
          parent.get('domain').then(domain => resolve(domain));
        }
      });
    });
  }),

  treeChildren: computed('children.[]', function(){
    return new Promise(resolve => {
      let rhett = [];
      this.get('children').then(children => {
        rhett.pushObjects(children.toArray());
        all(children.mapBy('treeChildren')).then(trees => {
          let competencies = trees.reduce(function(array, set){
            return array.pushObjects(set.toArray());
          }, []);
          rhett.pushObjects(competencies);
          rhett = rhett.uniq().filter(function(item){
            return item != null;
          });
          resolve(rhett);
        });
      });
    });
  }),
  childCount: computed('children.[]', function(){
    const childrenIds = this.hasMany('children').ids();
    return childrenIds.length;
  }),
});<commit_msg>async/await syntax for domain CP.<commit_after>import DS from 'ember-data';
import Ember from 'ember';

const { computed, RSVP } = Ember;
const { not } = computed;
const { Promise, all } = RSVP;
const { Model, attr, belongsTo, hasMany } = DS;

const inflector = Ember.Inflector.inflector;
inflector.uncountable('aamc-pcrs');

export default Model.extend({
  title: attr('string'),
  school: belongsTo('school', {async: true}),
  objectives: hasMany('objective', {async: true}),
  parent: belongsTo('competency', {async: true, inverse: 'children'}),
  children: hasMany('competency', {async: true, inverse: 'parent'}),
  aamcPcrses: hasMany('aamc-pcrs', {async: true}),
  programYears: hasMany('program-year', {async: true}),
  isDomain: computed('parent', function(){
    const parentId = this.belongsTo('parent').id();
    return !parentId;
  }),
  isNotDomain: not('isDomain'),

  domain: computed('parent', 'parent.domain', async function() {
    const parent = await this.get('parent');
    if (!parent) {
      return this;
    }
    return await parent.get('domain');
  }),

  treeChildren: computed('children.[]', function(){
    return new Promise(resolve => {
      let rhett = [];
      this.get('children').then(children => {
        rhett.pushObjects(children.toArray());
        all(children.mapBy('treeChildren')).then(trees => {
          let competencies = trees.reduce(function(array, set){
            return array.pushObjects(set.toArray());
          }, []);
          rhett.pushObjects(competencies);
          rhett = rhett.uniq().filter(function(item){
            return item != null;
          });
          resolve(rhett);
        });
      });
    });
  }),
  childCount: computed('children.[]', function(){
    const childrenIds = this.hasMany('children').ids();
    return childrenIds.length;
  }),
});
{'fraction_non_alphanumeric': 0.17526048624098317, 'fraction_numerical': 0.0, 'mean_word_length': 3.3789473684210525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '327258', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1142, 'n_words': 242}