"use strict";
/**
 * Copyright (c) Haiku 2016-2018. All rights reserved.
 */
Object.defineProperty(exports, "__esModule", { value: true });
var enhance_1 = require("./reflection/enhance");
var inject_1 = require("./reflection/inject");
function buildRoot() {
    // We need a global harness so we can...
    // - have a single rAF loop even if we've got multiple Haiku Contexts on the same page
    // - expose some global APIs that we hope to make available for all components
    var ROOT = {};
    // Window gets highest precedence since most likely we're running in DOM
    if (typeof window !== 'undefined') {
        ROOT = window;
    }
    else if (typeof global !== 'undefined') {
        ROOT = global;
    }
    else {
        // On the off-chance there is no real global, just use the orig object
    }
    if (!ROOT.haiku) {
        ROOT.haiku = {};
    }
    if (!ROOT.haiku.cache) {
        ROOT.haiku.cache = {};
    }
    if (!ROOT.haiku.models) {
        ROOT.haiku.models = {};
    }
    if (!ROOT.haiku.idCounter) {
        // Legacy: we start the ID counter at 1000 to avoid edge case ID collisions when there are copies of Haiku
        // sitting on the same page.
        ROOT.haiku.idCounter = 1000;
    }
    if (!ROOT.haiku.report) {
        ROOT.haiku.report = function () { return Object.keys(ROOT.haiku.models).forEach(function (modelName) {
            console.warn(modelName + ":\n  count: " + ROOT.haiku.models[modelName].length + "\n  ids: " + ROOT.haiku.models[modelName].map(function (instance) { return instance.$id; }).join(', ') + "\n");
        }); };
    }
    if (!ROOT.haiku.enhance) {
        /**
         * @function enhance
         * @description Given a function, decorate it with a .specification property that
         * contains a descriptor of the serialized form of the function, including its params.
         * This is used by the renderer as part of its automatic dependency injection mechanism.
         */
        ROOT.haiku.enhance = enhance_1.default;
    }
    if (!ROOT.haiku.inject) {
        /**
         * @function inject
         * @description Variadic function that takes a function as the first argument and
         * a collection of injection parameters as the remaining arguments, which are in turn
         * used to 'enhance' (see above) the function, specifying the parameters it wants injected.
         */
        ROOT.haiku.inject = inject_1.default;
    }
    return ROOT.haiku;
}
var haiku = buildRoot();
exports.default = haiku;
//# sourceMappingURL=HaikuGlobal.js.map