/*
 * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import axios from 'axios'

class ConfigManager {

    constructor() {
    }

    /**
     * get configurations from server: deployment.yaml
     * @returns {Object}: configuration object
     */
    static getConfigs() {
        return {
            'environments': ConfigRequestMethods.promised_environments()
        };
    }
}

/**
 * @type {{ConstPath: StringPath}} ConfigRequestPaths: Configuration requesting url paths
 */
const ConfigRequestPaths = {
    ENVIRONMENT_CONFIG_PATH: "/configService/environments"
};

/**
 * @type {{'ConstRequestString': (function Request_Method())}} ConfigRequestMethods: Configuration requesting methods
 */
const ConfigRequestMethods = {
    promised_environments() {
        if (ConfigManager._promised_environments) {
            return ConfigManager._promised_environments;
        }
        let origin = window.location.origin;
        let requestUrl = origin + ConfigRequestPaths.ENVIRONMENT_CONFIG_PATH;

        ConfigManager._promised_environments = axios.get(requestUrl);
        return ConfigManager._promised_environments;
    }
};

//List of private promised class variables to preserve single instance
ConfigManager._promised_environments = null;

export default ConfigManager;
@@ -722,23 +722,633 @@
     
-constructor() %7B
+/**%0A     * get promised config and update the configMap%0A     * @param configPath: Path to read configs from%0A     * @returns %7BPromise Object%7D: promised config%0A     * @private%0A     */%0A    static _getPromisedConfigs(configPath) %7B%0A        let promisedConfig = ConfigManager._promisedConfigMap.get(configPath);%0A        if (promisedConfig) %7B%0A            return promisedConfig;%0A        %7D%0A        let origin = window.location.origin;%0A        let requestUrl = origin + configPath;%0A%0A        promisedConfig = axios.get(requestUrl);%0A        ConfigManager._promisedConfigMap.set(configPath, promisedConfig);%0A        return promisedConfig;
 %0A   
@@ -1550,45 +1550,78 @@
 nfig
-RequestMethods.promised_environments(
+Manager._getPromisedConfigs(ConfigRequestPaths.ENVIRONMENT_CONFIG_PATH
 )%0A  
@@ -1839,634 +1839,147 @@
 %0A * 
-@type %7B%7B'ConstRequestString': (function Request_Method())%7D%7D ConfigRequestMethods: Configuration requesting methods%0A */%0Aconst ConfigRequestMethods = %7B%0A    promised_environments() %7B%0A        if (ConfigManager._promised_environments) %7B%0A            return ConfigManager._promised_environments;%0A        %7D%0A        let origin = window.location.origin;%0A        let requestUrl = origin + ConfigRequestPaths.ENVIRONMENT_CONFIG_PATH;%0A%0A        ConfigManager._promised_environments = axios.get(requestUrl);%0A        return ConfigManager._promised_environments;%0A    %7D%0A%7D;%0A%0A//List of private promised class variables to preserve single instance
+The map of single instance promised configs objects%0A * %7Bkey%7D: ConfigRequestPaths%0A * %7Bvalue%7D: promised config%0A * @type %7BMap%7D%0A * @private%0A */
 %0ACon
@@ -2002,28 +2002,29 @@
 ised
-_environments = null
+ConfigMap = new Map()
 ;%0A%0Ae

Refactor configManager.js in publisher