<commit_before>import eventEmitter from 'event-emitter';
import Vue from 'vue';

let singletonInstance = null;

export default class GlobalApi {
    constructor() {
        eventEmitter(this);
        this.state = null;
        this.themes = null;
        this.controlInputPlugins = [];
        this.stateBrowserPlugins = [];
        this.channelHeaderPlugins = [];
        this.queryHeaderPlugins = [];
        this.tabs = Object.create(null);
    }

    static singleton() {
        singletonInstance = singletonInstance || new GlobalApi();
        return singletonInstance;
    }

    setState(state) {
        this.state = state;
    }

    setThemeManager(themeManager) {
        this.themes = themeManager;
    }

    /**
     * addUi('input', domElement)
     * addUi('browser', domElement)
     * addUi('header_channel', domElement)
     * addUi('header_query', domElement)<commit_msg>Proving a kiwi.onready() for custom runtime plugins<commit_after>import eventEmitter from 'event-emitter';
import Vue from 'vue';

let singletonInstance = null;
let callbacksOnReady = [];

export default class GlobalApi {
    constructor() {
        eventEmitter(this);
        this.state = null;
        this.themes = null;
        this.controlInputPlugins = [];
        this.stateBrowserPlugins = [];
        this.channelHeaderPlugins = [];
        this.queryHeaderPlugins = [];
        this.tabs = Object.create(null);
    }

    static singleton() {
        singletonInstance = singletonInstance || new GlobalApi();
        return singletonInstance;
    }

    onready(fn) {
        if (singletonInstance) {
            fn(this);
        } else {
            callbacksOnReady.push(fn);
        }
    }

    // Init any plugins that were added before we were ready
    initPlugins() {
        callbacksOnReady.forEach(fn => {
            try {
                fn(this);
            } catch (err) {
                window.error(err);
            }
        });

        callbacksOnReady = [];
    }

    setState(state) {
        this.state = state;
        state.$once('init', () => {
            this.initPlugins();
        });
    }

    setThemeManager(themeManager) {
        this.themes = themeManager;
    }

    /**
     * addUi('input', domElement)
     * addUi('browser', domElement)
     * addUi('header_channel', domElement)
     * addUi('header_query', domElement)
{'fraction_non_alphanumeric': 0.11851539434837621, 'fraction_numerical': 0.0, 'mean_word_length': 2.145888594164456, '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': '5248201', 'n_tokens_mistral': 678, 'n_tokens_neox': 653, 'n_words': 131}