<commit_before>import EventEmitter from 'eventemitter3'
import Immutable from 'immutable'

export default class State extends EventEmitter {

  constructor(opt_json) {
    this._state = null
    this.load(opt_json || {})
  }

  load(json: Object) {
    this.set(Immutable.fromJS(json))
  }

  set(state) {
    if (this._state === state) return
    this._state = state
    this.emit('change', this._state)
  }

  get() {
    return this._state
  }

  save(): Object {
    return this._state.toJS()
  }

  toConsole() {
    console.log(JSON.stringify(this.save()))
  }

  cursor(path) {
    return (update) => {
      if (update) {
        this.set(this._state.updateIn(path, update))<commit_msg>Allow immutable for state load.<commit_after>import EventEmitter from 'eventemitter3'
import Immutable from 'immutable'

export default class State extends EventEmitter {

  constructor(state) {
    this._state = null
    this.load(state || {})
  }

  load(state: Object) {
    this.set(Immutable.Map.isMap(state) ? state : Immutable.fromJS(state))
  }

  set(state) {
    if (this._state === state) return
    this._state = state
    this.emit('change', this._state)
  }

  get() {
    return this._state
  }

  save(): Object {
    return this._state.toJS()
  }

  toConsole() {
    console.log(JSON.stringify(this.save()))
  }

  cursor(path) {
    return (update) => {
      if (update) {
        this.set(this._state.updateIn(path, update))
{'fraction_non_alphanumeric': 0.13968033356497567, 'fraction_numerical': 0.001389854065323141, 'mean_word_length': 3.044943820224719, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4286361', 'n_tokens_mistral': 485, 'n_tokens_neox': 476, 'n_words': 97}