(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "../core/AtomBinder", "../services/NavigationService"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const AtomBinder_1 = require("../core/AtomBinder");
    const NavigationService_1 = require("../services/NavigationService");
    /**
     * Use this method to create an object/array that will refresh
     * when promise is resolved
     */
    function bindPromise(vm, p, value, displayError = true) {
        p.then((v) => {
            if (Array.isArray(v)) {
                const a = value;
                a.replace(v);
            }
            else {
                for (const key in v) {
                    if (v.hasOwnProperty(key)) {
                        const element = v[key];
                        value[key] = element;
                        AtomBinder_1.AtomBinder.refreshValue(value, key);
                    }
                }
            }
        }).catch((e) => {
            if (displayError) {
                if (typeof displayError === "function") {
                    displayError(e);
                }
                else {
                    const n = vm.app.resolve(NavigationService_1.NavigationService);
                    n.notify(e, "Error", NavigationService_1.NotifyType.Error);
                }
            }
        });
        return value;
    }
    exports.default = bindPromise;
});
//# sourceMappingURL=bindPromise.js.map