<commit_before>import { readonly } from 'core-decorators';
import { first, last, mapValues, omitBy } from 'lodash';
import { action, observable, computed } from 'mobx';
import {
  BaseModel, identifiedBy, belongsTo, identifier, field, session, hasMany,
} from 'shared/model';
import ChapterSection from './chapter-section';
import Chapter from './reference-book/chapter';

function mapPages(page, pages) {
  if (page.isPage) {
    const lastPage = last(pages.byId.values());
    if (lastPage) { lastPage.linkNextPage(page); }
    pages.byId.set(page.id, page);
    pages.byUUID.set(page.uuid, page);
    pages.byChapterSection.set(page.chapter_section.asString, page);
  }
  (page.children || []).forEach(child => {
    mapPages(child, pages);
  });
  return pages;
}

@identifiedBy('reference-book')
export default class ReferenceBook extends BaseModel {

  @identifier id;
  @field archive_url;
  @field webview_url;
  @field({ model: ChapterSection }) chapter_section;

  @computed get pages() {
    return mapPages(this, {
      byId: observable.map(),
      byUUID: observable.map(),
      byChapterSection: observable.map(),
    });
  }

  @hasMany({ model: Chapter, inverseOf: 'book' }) children;
  @field cnx_id;
  @field short_id;
  @field title;
  @field type;
  @field uuid;

  fetch() {
    return { id: this.id };
  }

  @action onApiRequestComplete({ data }) {
    this.update(omitBy(first(data), (val, key) => key == 'id')); // data is an array
  }

  // a simplified data structure suitable for passing into flux
  @computed get topicInfo() {
    return mapValues(this.pages.byId.toJS(), pg => pg.asTopic);
  }

}<commit_msg>Use omit instead of omitBy<commit_after>import { readonly } from 'core-decorators';
import { first, last, mapValues, omit } from 'lodash';
import { action, observable, computed } from 'mobx';
import {
  BaseModel, identifiedBy, belongsTo, identifier, field, session, hasMany,
} from 'shared/model';
import ChapterSection from './chapter-section';
import Chapter from './reference-book/chapter';

function mapPages(page, pages) {
  if (page.isPage) {
    const lastPage = last(pages.byId.values());
    if (lastPage) { lastPage.linkNextPage(page); }
    pages.byId.set(page.id, page);
    pages.byUUID.set(page.uuid, page);
    pages.byChapterSection.set(page.chapter_section.asString, page);
  }
  (page.children || []).forEach(child => {
    mapPages(child, pages);
  });
  return pages;
}

@identifiedBy('reference-book')
export default class ReferenceBook extends BaseModel {

  @identifier id;
  @field archive_url;
  @field webview_url;
  @field({ model: ChapterSection }) chapter_section;

  @computed get pages() {
    return mapPages(this, {
      byId: observable.map(),
      byUUID: observable.map(),
      byChapterSection: observable.map(),
    });
  }

  @hasMany({ model: Chapter, inverseOf: 'book' }) children;
  @field cnx_id;
  @field short_id;
  @field title;
  @field type;
  @field uuid;

  fetch() {
    return { id: this.id };
  }

  @action onApiRequestComplete({ data }) {
    this.update(omit(first(data), 'id')); // data is an array
  }

  // a simplified data structure suitable for passing into flux
  @computed get topicInfo() {
    return mapValues(this.pages.byId.toJS(), pg => pg.asTopic);
  }

}
{'fraction_non_alphanumeric': 0.1452599388379205, 'fraction_numerical': 0.0, 'mean_word_length': 3.8967065868263475, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '3812253', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1040, 'n_words': 269}