<commit_before>import Q from "q";
import { makeEmitter } from "pubit-as-promised";
import iocSpecBuilder from "./iocSpecBuilder";
import AppDelegate from "./AppDelegate";

function throwNotImplemented(nameOfMethod) {
    console.warn(`[YepApp] ${nameOfMethod} not implemented!`);
}

class Components {
    constructor(...listOfComponents) {
        this._list = listOfComponents;
    }
    bootstrap(specs) {
        return Q.all(this._list.map(
            (component) => Q.when(component.bootstrap(specs))
        ));
    }
}

class Bootstrapper {
    constructor(components) {
        this._components = components;
        this._specs = iocSpecBuilder.define();

    }
    get actions() {
        return this._specs.actions;
    }
    bootstrap() {
        return this._components.bootstrap(this._specs)
            .then(() => this._specs.wire());
    }
    getComponent() {
        throwNotImplemented("getComponent");
    }
    bootstrapBefore() {
        throwNotImplemented("bootstrapBefore");
    }
    bootstrapAfter() {
        throwNotImplemented("bootstrapAfter");
    }
}

class Actions {
    constructor(actionMap) {
        this._map = actionMap;
    }
    dispatch(name, ...actionArgs) {
        var action = this._map[name];
        if (!action) {
            throw new Error("Action could not be dispatched: " + name);
        }
        var execAction = typeof action === "function" ? action : action.exec.bind(action);

        return Q.when(execAction(...actionArgs));
    }
}

var _instance = null;

export default class App {
    // private contructor
    constructor(components, delegate) {
        if (_instance) {
            throw new Error("App can only have one instance at a time. Try App.terminate() first.");
        }

        this._bootstrapper = new Bootstrapper(components);
        this._delegate = delegate;
        this._actions = null;
        this._events = this._createEventBus();
        // providers
        this._session = null;
        this._logger = null;
        this._localization = null;

        _instance = this;
        this._delegate.startup(this);
    }

    _createEventBus() {
        var eventBus = {};
        eventBus.publish = makeEmitter(eventBus);
        return eventBus;
    }

    bootstrap() {
        this._delegate.startup(this);
        return Q.when(this._delegate.onBeforeBootstrapped(this._bootstrapper))
            .then(() => this._bootstrapper.bootstrap())
            .then(this._bootstrapComplete.bind(this));
    }

    _bootstrapComplete(container) {
        this._actions = new Actions(this._bootstrapper.actions);
        this._initProviders();
        return this._delegate.onBootstrapped(container, this._bootstrapper);
    }

    _initProviders() {
        this._session = this._delegate.provideSession();
        this._logger = this._delegate.provideLogger();
        this._localization = this._delegate.provideLocalize();
    }

    static instance() {
        if (!_instance) {
            throw new Error("Can not return App.instance(). App.run must be invoked first.");
        }<commit_msg>Provide hooks should get container.<commit_after>import Q from "q";
import { makeEmitter } from "pubit-as-promised";
import iocSpecBuilder from "./iocSpecBuilder";
import AppDelegate from "./AppDelegate";

function throwNotImplemented(nameOfMethod) {
    console.warn(`[YepApp] ${nameOfMethod} not implemented!`);
}

class Components {
    constructor(...listOfComponents) {
        this._list = listOfComponents;
    }
    bootstrap(specs) {
        return Q.all(this._list.map(
            (component) => Q.when(component.bootstrap(specs))
        ));
    }
}

class Bootstrapper {
    constructor(components) {
        this._components = components;
        this._specs = iocSpecBuilder.define();

    }
    get actions() {
        return this._specs.actions;
    }
    bootstrap() {
        return this._components.bootstrap(this._specs)
            .then(() => this._specs.wire());
    }
    getComponent() {
        throwNotImplemented("getComponent");
    }
    bootstrapBefore() {
        throwNotImplemented("bootstrapBefore");
    }
    bootstrapAfter() {
        throwNotImplemented("bootstrapAfter");
    }
}

class Actions {
    constructor(actionMap) {
        this._map = actionMap;
    }
    dispatch(name, ...actionArgs) {
        var action = this._map[name];
        if (!action) {
            throw new Error("Action could not be dispatched: " + name);
        }
        var execAction = typeof action === "function" ? action : action.exec.bind(action);

        return Q.when(execAction(...actionArgs));
    }
}

var _instance = null;

export default class App {
    // private contructor
    constructor(components, delegate) {
        if (_instance) {
            throw new Error("App can only have one instance at a time. Try App.terminate() first.");
        }

        this._bootstrapper = new Bootstrapper(components);
        this._delegate = delegate;
        this._actions = null;
        this._events = this._createEventBus();
        // providers
        this._session = null;
        this._logger = null;
        this._localization = null;

        _instance = this;
        this._delegate.startup(this);
    }

    _createEventBus() {
        var eventBus = {};
        eventBus.publish = makeEmitter(eventBus);
        return eventBus;
    }

    bootstrap() {
        this._delegate.startup(this);
        return Q.when(this._delegate.onBeforeBootstrapped(this._bootstrapper))
            .then(() => this._bootstrapper.bootstrap())
            .then(this._bootstrapComplete.bind(this));
    }

    _bootstrapComplete(container) {
        this._actions = new Actions(this._bootstrapper.actions);
        this._initProviders(container);
        return this._delegate.onBootstrapped(container, this._bootstrapper);
    }

    _initProviders(container) {
        this._session = this._delegate.provideSession(container);
        this._logger = this._delegate.provideLogger(container);
        this._localization = this._delegate.provideLocalize(container);
    }

    static instance() {
        if (!_instance) {
            throw new Error("Can not return App.instance(). App.run must be invoked first.");
        }
{'fraction_non_alphanumeric': 0.12016685384245147, 'fraction_numerical': 0.0, 'mean_word_length': 2.451827242524917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6143271', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1700, 'n_words': 350}