<commit_before>// @flow
import { createAction, handleActions } from 'redux-actions'
import { Map, Record } from 'immutable'

import type { Action } from 'redux-actions'

import Page from 'entities/Page'
import wrapStateWith from 'utils/wrapStateWith'

import type { Position } from 'types'

/* ======= Types ======= */

export type PagesStateConfig = {
  pageByUid: Map<string, Page>,
  topByUid: Map<string, number>,
}

const defaultValue: PagesStateConfig = {
  pageByUid: Map(),
  topByUid: Map(),
}

export class PagesState extends Record(defaultValue) {
  constructor (values: $Shape<PagesStateConfig> = defaultValue) {
    const { pageByUid, topByUid } = values
    if (pageByUid instanceof Map) {
      values.pageByUid = Map(pageByUid).map(v => v instanceof Page ? v : new Page(v))
    }
    if (!(topByUid instanceof Map)) {
      values.topByUid = Map(topByUid)
    }
    super(values)
    assert(this.pageByUid instanceof Map)
    assert(this.pageByUid.every(p => p instanceof Page))
    assert(this.topByUid instanceof Map)
  }

  // HACK: for typecheck<commit_msg>Fix condition<commit_after>// @flow
import { createAction, handleActions } from 'redux-actions'
import { Map, Record } from 'immutable'

import type { Action } from 'redux-actions'

import Page from 'entities/Page'
import wrapStateWith from 'utils/wrapStateWith'

import type { Position } from 'types'

/* ======= Types ======= */

export type PagesStateConfig = {
  pageByUid: Map<string, Page>,
  topByUid: Map<string, number>,
}

const defaultValue: PagesStateConfig = {
  pageByUid: Map(),
  topByUid: Map(),
}

export class PagesState extends Record(defaultValue) {
  constructor (values: $Shape<PagesStateConfig> = defaultValue) {
    const { pageByUid, topByUid } = values
    if (!(pageByUid instanceof Map)) {
      values.pageByUid = Map(pageByUid).map(v => v instanceof Page ? v : new Page(v))
    }
    if (!(topByUid instanceof Map)) {
      values.topByUid = Map(topByUid)
    }
    super(values)
    assert(this.pageByUid instanceof Map)
    assert(this.pageByUid.every(p => p instanceof Page))
    assert(this.topByUid instanceof Map)
  }

  // HACK: for typecheck
{'fraction_non_alphanumeric': 0.12934631432545202, 'fraction_numerical': 0.0, 'mean_word_length': 4.018604651162791, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '6327004', 'n_tokens_mistral': 716, 'n_tokens_neox': 707, 'n_words': 184}