<commit_before>import { EventEmitter2 } from 'eventemitter2';
import { Observable } from 'rxjs/Observable';
import { fromEvent } from 'rxjs/observable/fromEvent';
import Store from './store';
import { normalizePath } from './utils';

export default class State {

  constructor({
    store = new Store(),
    cursor = [],
    emitter = new EventEmitter2({
      wildcard: true,
      delimiter: '.',
      // FIXME: is it good?
      maxListeners: Infinity,
    }),
  } = {}) {
    this.__store = store;
    this.__cursor = cursor;
    this.__emitter = emitter;
  }

  cursor(subPath = '') {
    const { __store, __cursor, __emitter } = this;
    subPath = normalizePath(subPath);
    return new State({
      store: __store,
      cursor: __cursor.concat(subPath),
      emitter: __emitter,
    });
  }

  get(subPath = '') {
    const { length } = arguments;
    if (length !== 0) {
      return this.cursor(subPath).get();
    }
    return this.__store.read(this.__cursor);
  }

  set(subPath, value) {
    const { length } = arguments;
    if (length < 1) {
      throw new TypeError('value argument must be set');
    }
    if (length === 1) {
      value = subPath;
      subPath = undefined;
    }
    if (subPath !== undefined) {
      return this.cursor(subPath).set(value);
    }
    this.__store.write(this.__cursor, value);
    this.__emitter.emit(['change', ...this.__cursor], value);
  }

  currentCursor() {
    return this.__cursor.join('.');
  }

  listen(message) {
    let generatedMessage;
    switch (message) {
      case 'change':
        generatedMessage = ['change', ...this.__cursor, '**'].join('.');
        break;
      default:
        generatedMessage = message;
        break;
    }
    return Observable::fromEvent(this.__emitter, generatedMessage);
  }
}<commit_msg>a little change, great eventemitter2<commit_after>import { EventEmitter2 } from 'eventemitter2';
import { Observable } from 'rxjs/Observable';
import { fromEvent } from 'rxjs/observable/fromEvent';
import Store from './store';
import { normalizePath } from './utils';

export default class State {

  constructor({
    store = new Store(),
    cursor = [],
    emitter = new EventEmitter2({
      wildcard: true,
      delimiter: '.',
      // FIXME: is it good?
      maxListeners: Infinity,
    }),
  } = {}) {
    this.__store = store;
    this.__cursor = cursor;
    this.__emitter = emitter;
  }

  cursor(subPath = '') {
    const { __store, __cursor, __emitter } = this;
    subPath = normalizePath(subPath);
    return new State({
      store: __store,
      cursor: __cursor.concat(subPath),
      emitter: __emitter,
    });
  }

  get(subPath = '') {
    const { length } = arguments;
    if (length !== 0) {
      return this.cursor(subPath).get();
    }
    return this.__store.read(this.__cursor);
  }

  set(subPath, value) {
    const { length } = arguments;
    if (length < 1) {
      throw new TypeError('value argument must be set');
    }
    if (length === 1) {
      value = subPath;
      subPath = undefined;
    }
    if (subPath !== undefined) {
      return this.cursor(subPath).set(value);
    }
    this.__store.write(this.__cursor, value);
    this.__emitter.emit(['change', ...this.__cursor, '**'].join('.'), value);
  }

  currentCursor() {
    return this.__cursor.join('.');
  }

  listen(message) {
    let generatedMessage;
    switch (message) {
      case 'change':
        generatedMessage = ['change', ...this.__cursor, '**'].join('.');
        break;
      default:
        generatedMessage = message;
        break;
    }
    return Observable::fromEvent(this.__emitter, generatedMessage);
  }
}
{'fraction_non_alphanumeric': 0.14957382458069837, 'fraction_numerical': 0.0035743744844652188, 'mean_word_length': 2.601980198019802, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1245909', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1097, 'n_words': 263}