<commit_before>import t from 'tcomb';
import EventEmitter3 from 'eventemitter3';
import { AvengerInput, State, CacheState, Command, EmitMeta, PromiseType } from './types';
import AvengerCache from './AvengerCache';
import build from './build';
import { runLocal } from './run';
import { invalidateLocal } from './invalidate';

export default class Avenger {
  constructor(allQueries: AvengerInput, initialCacheState: CacheState = {}) {
    this.allQueries = allQueries;
    this.currentInput = null;
    this.currentState = {};
    this.cache = new AvengerCache(initialCacheState);
    this.emitter = new EventEmitter3();
    this.result = {
      __meta: {}
    };
  }

  on(...args) {
    return this.emitter.on(...args);
  }

  off(...args) {
    return this.emitter.off(...args);
  }

  emit = (meta: EmitMeta, value: t.Any) => {
    const {
      id,
      loading = false,
      cache = false,
      error = false,
      multi = false,
      multiAll = false
    } = meta;
    const now = new Date().getTime();

    if (multi && !multiAll) { // swallow up!
      // not sure about this,
      // but seems easier to just emit once
      // with entire result change for multi queries<commit_msg>attach avenger instance to window.$av<commit_after>import t from 'tcomb';
import EventEmitter3 from 'eventemitter3';
import { AvengerInput, State, CacheState, Command, EmitMeta, PromiseType } from './types';
import AvengerCache from './AvengerCache';
import build from './build';
import { runLocal } from './run';
import { invalidateLocal } from './invalidate';

export default class Avenger {
  constructor(allQueries: AvengerInput, initialCacheState: CacheState = {}) {
    this.allQueries = allQueries;
    this.currentInput = null;
    this.currentState = {};
    this.cache = new AvengerCache(initialCacheState);
    this.emitter = new EventEmitter3();
    this.result = {
      __meta: {}
    };
    if (process.env.NODE_ENV === 'development') {
      if (typeof window !== 'undefined') {
        window.$av = this;
      }
    }
  }

  on(...args) {
    return this.emitter.on(...args);
  }

  off(...args) {
    return this.emitter.off(...args);
  }

  emit = (meta: EmitMeta, value: t.Any) => {
    const {
      id,
      loading = false,
      cache = false,
      error = false,
      multi = false,
      multiAll = false
    } = meta;
    const now = new Date().getTime();

    if (multi && !multiAll) { // swallow up!
      // not sure about this,
      // but seems easier to just emit once
      // with entire result change for multi queries
{'fraction_non_alphanumeric': 0.13671875, 'fraction_numerical': 0.00234375, 'mean_word_length': 2.6955266955266954, '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': '3571872', 'n_tokens_mistral': 780, 'n_tokens_neox': 780, 'n_words': 222}