(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 });
    var AtomBinder_1 = require("../core/AtomBinder");
    var 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) {
        if (displayError === void 0) { displayError = true; }
        p.then(function (v) {
            if (Array.isArray(v)) {
                var a = value;
                a.replace(v);
            }
            else {
                for (var key in v) {
                    if (v.hasOwnProperty(key)) {
                        var element = v[key];
                        value[key] = element;
                        AtomBinder_1.AtomBinder.refreshValue(value, key);
                    }
                }
            }
        }).catch(function (e) {
            if (displayError) {
                if (typeof displayError === "function") {
                    displayError(e);
                }
                else {
                    var n = vm.app.resolve(NavigationService_1.NavigationService);
                    n.notify(e, "Error", NavigationService_1.NotifyType.Error);
                }
            }
        });
        return value;
    }
    exports.default = bindPromise;
});
//# sourceMappingURL=bindPromise.js.map