{"size": 641, "ext": "js", "max_stars_repo_path": "markup/front/mvc/create-page/additions/emmiter.js", "max_stars_repo_name": "Dachtone/perspective-web-testing", "max_stars_repo_stars_event_min_datetime": "2019-01-11T15:44:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-30T20:59:03.000Z", "max_issues_repo_path": "public/frontend/front/mvc/emmiter/emmiter.js", "max_issues_repo_name": "Dachtone/perspective-web-testing", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "public/frontend/front/mvc/emmiter/emmiter.js", "max_forks_repo_name": "Dachtone/perspective-web-testing", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 4, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 33.7368421053, "max_line_length": 94, "alphanum_fraction": 0.6021840874}
export class eventEmmiter{
    constructor(){
        this.state = {}
    }
    // метод @on подписывает $callback-функию на событие $type
    on(type, callback){
        this.state[type] ? this.state[type] = this.state[type] : this.state[type] = []
        this.state[type].push(callback)
    }
    // метод @init вызывает $callback-функцию с аргументом $data по подписанному событию $type
    init(type, data){
        const event = this.state[type]
        if(event){
            Array.prototype.forEach.call(event, listener => listener(data))
        }else{
            console.error('error: init not recognized event')
        }
    }
}