var eventArr = new Array();
var _enum = {
    chainChanged_wallet : "chainChanged_wallet",
    message_wallet :"message_wallet",
    disconnect_wallet :"disconnect_wallet",
    connectt_wallet : "connectt_wallet",
    accountsChanged_wallet : "accountsChanged_wallet",
    buyCatNft_wallet:"buyCatNft_wallet",                    
    createSaleCatNft_wallet:"createSaleCatNft_wallet",     
    saleSuccessful_wallet:"saleSuccessful_wallet",          
    saleCancelled_wallet:"saleCancelled_wallet",           
    tokenInvalid :"tokenInvalid",               
    loginOut:"loginOut",   
}
export default {
    Enum : _enum,
    Add(eventType, func) {
        if (eventArr[eventType] == null) {
            let events = new Array();
            events.push(func);
            eventArr[eventType] = events;
        } else {
            eventArr[eventType].push(func);
        }
    },
    Remove(eventType, func) {
        if (eventArr[eventType] == null)
            return;

        for (let index = 0; index < eventArr[eventType].length; index++) {
            const element = eventArr[eventType][index];
            if (element == func) {
                eventArr[eventType].splice(index);
                break;
            }
        }

        if (eventArr[eventType].length <= 0)
            eventArr[eventType] = null;

    },
    Dispatch(eventType, data = null) {
        if (eventArr[eventType] == null) {
            return;
        }
        for (let index = 0; index < eventArr[eventType].length; index++) {
            const fun = eventArr[eventType][index];
            if (fun != null) {
                if (data == null)
                    fun()
                else
                    fun(data);
            }
        }
    }
}