{"action":"created","comment":{"url":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/comments/88776223","pull_request_review_id":9342466,"id":88776223,"diff_hunk":"@@ -7,38 +7,148 @@\n getEmitter.isStar = true;\n module.exports = getEmitter;\n \n+function getLastEvent(context, event) {\n+    var splittedEvent = event.split('.');\n+    splittedEvent.forEach(function (miniEvent) {\n+        if (context.hasOwnProperty(miniEvent)) {\n+            context = context[miniEvent];\n+        }\n+    });\n+\n+    return context;\n+}\n+\n+/**\n+ * @this {Object}\n+ * @param {Object} context\n+ * @returns {Function}\n+ */\n+function wrapFunction(context) {\n+    return {\n+        eventFuncs: [],\n+\n+        func: function () {\n+            this.eventFuncs.forEach(function (eventFunc) {\n+                execEventFunc(eventFunc);\n+            });\n+            if (context.hasOwnProperty('func')) {\n+                context.func();\n+            }\n+        }\n+    };\n+}\n+\n+function execEventFunc(eventFunc) {\n+    if (eventFunc.count > 0 && eventFunc.callCounter % eventFunc.mod === 0) {\n+        eventFunc.func();\n+        eventFunc.count--;\n+    }\n+    eventFunc.callCounter++;\n+}\n+\n+function execLastEvent(student, event) {\n+    var lastEvent = getLastEvent(student, event);\n+    if (lastEvent.func) {\n+        lastEvent.func();\n+    }\n+}\n+\n+function createEventFunc(func, params) {\n+    return {\n+        func: func,\n+        count: params ? params.count || Infinity : Infinity,\n+        callCounter: 0,\n+        mod: params ? params.mod || 1 : 1\n+    };\n+}\n+\n+function addEventHandler(event, context, eventFunc) {\n+    var splittedEvent = event.split('.');\n+    var miniContext = context;\n+    var length = splittedEvent.length;\n+    for (var i = 0; i < length; i++) {\n+        var miniEvent = splittedEvent[i];\n+        if (miniContext.hasOwnProperty(miniEvent)) {\n+            miniContext = i === length - 1 ? miniContext : miniContext[miniEvent];\n+        } else {\n+            miniContext[miniEvent] = wrapFunction(miniContext);\n+        }\n+        if (i === length - 1) {\n+            miniContext[miniEvent].eventFuncs.push(eventFunc);\n+        }\n+    }\n+}\n+\n /**\n  * Возвращает новый emitter\n  * @returns {Object}\n  */\n function getEmitter() {\n+    var students = [];\n+    var subscriptions = [];\n+    function on(event, context, handler, eventFuncParams) {\n+        if (students.indexOf(context) === -1) {\n+            students.push(context);\n+            subscriptions.push({});\n+        }\n+        var subscription = subscriptions[students.indexOf(context)];\n+        handler = handler.bind(context);\n+        addEventHandler(event, subscription, createEventFunc(handler, eventFuncParams));\n+    }\n+\n     return {\n \n         /**\n          * Подписаться на событие\n          * @param {String} event\n          * @param {Object} context\n          * @param {Function} handler\n+         * @param {Object} eventFuncParams\n+         * @returns {Object} this\n          */\n         on: function (event, context, handler) {\n-            console.info(event, context, handler);\n+            on(event, context, handler);\n+\n+            return this;\n         },\n \n         /**\n          * Отписаться от события\n          * @param {String} event\n          * @param {Object} context\n+         * @returns {Object} this\n          */\n         off: function (event, context) {\n-            console.info(event, context);\n+            context = subscriptions[students.indexOf(context)];\n+            var splittedEvent = event.split('.');\n+            splittedEvent.every(function (miniEvent, index) {\n+                if (context.hasOwnProperty(miniEvent)) {\n+                    if (index === splittedEvent.length - 1) {\n+                        delete context[miniEvent];\n+                    } else {\n+                        context = context[miniEvent];\n+                    }\n+\n+                    return true;\n+                }\n+\n+                return false;\n+            });","path":"emitter.js","position":132,"original_position":132,"commit_id":"af205a387c538299543f50dbce3b2d5cc60268f7","original_commit_id":"af205a387c538299543f50dbce3b2d5cc60268f7","user":{"login":"askeip","id":12084987,"avatar_url":"https://avatars.githubusercontent.com/u/12084987?v=3","gravatar_id":"","url":"https://api.github.com/users/askeip","html_url":"https://github.com/askeip","followers_url":"https://api.github.com/users/askeip/followers","following_url":"https://api.github.com/users/askeip/following{/other_user}","gists_url":"https://api.github.com/users/askeip/gists{/gist_id}","starred_url":"https://api.github.com/users/askeip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/askeip/subscriptions","organizations_url":"https://api.github.com/users/askeip/orgs","repos_url":"https://api.github.com/users/askeip/repos","events_url":"https://api.github.com/users/askeip/events{/privacy}","received_events_url":"https://api.github.com/users/askeip/received_events","type":"User","site_admin":false},"body":"Допустим есть событие slide.funny.test1. Если в off придет что-то типа slide.funny.test2.test1 (учитывая, что test2 не существует), то getLastEvent вернет slide.funny и удалив test1 я удалю slide.funny.test1, что неверно. По той же причине в новом коммите будет изменен и getLastEvent. Если не нравится через every могу сделать через for (var i=0; i < length; i++), потому что мне нужен break.","created_at":"2016-11-19T09:24:22Z","updated_at":"2016-11-19T09:24:22Z","html_url":"https://github.com/urfu-2016/javascript-task-5/pull/2#discussion_r88776223","pull_request_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/comments/88776223"},"html":{"href":"https://github.com/urfu-2016/javascript-task-5/pull/2#discussion_r88776223"},"pull_request":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/2","id":92201352,"html_url":"https://github.com/urfu-2016/javascript-task-5/pull/2","diff_url":"https://github.com/urfu-2016/javascript-task-5/pull/2.diff","patch_url":"https://github.com/urfu-2016/javascript-task-5/pull/2.patch","issue_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/issues/2","number":2,"state":"open","locked":false,"title":"Кужелев Евгений","user":{"login":"askeip","id":12084987,"avatar_url":"https://avatars.githubusercontent.com/u/12084987?v=3","gravatar_id":"","url":"https://api.github.com/users/askeip","html_url":"https://github.com/askeip","followers_url":"https://api.github.com/users/askeip/followers","following_url":"https://api.github.com/users/askeip/following{/other_user}","gists_url":"https://api.github.com/users/askeip/gists{/gist_id}","starred_url":"https://api.github.com/users/askeip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/askeip/subscriptions","organizations_url":"https://api.github.com/users/askeip/orgs","repos_url":"https://api.github.com/users/askeip/repos","events_url":"https://api.github.com/users/askeip/events{/privacy}","received_events_url":"https://api.github.com/users/askeip/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-11-03T17:24:06Z","updated_at":"2016-11-19T09:24:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4320c743cafaa1b6a18ae926d21cc675d17adea7","assignee":{"login":"Vittly","id":1221916,"avatar_url":"https://avatars.githubusercontent.com/u/1221916?v=3","gravatar_id":"","url":"https://api.github.com/users/Vittly","html_url":"https://github.com/Vittly","followers_url":"https://api.github.com/users/Vittly/followers","following_url":"https://api.github.com/users/Vittly/following{/other_user}","gists_url":"https://api.github.com/users/Vittly/gists{/gist_id}","starred_url":"https://api.github.com/users/Vittly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Vittly/subscriptions","organizations_url":"https://api.github.com/users/Vittly/orgs","repos_url":"https://api.github.com/users/Vittly/repos","events_url":"https://api.github.com/users/Vittly/events{/privacy}","received_events_url":"https://api.github.com/users/Vittly/received_events","type":"User","site_admin":false},"assignees":[{"login":"Vittly","id":1221916,"avatar_url":"https://avatars.githubusercontent.com/u/1221916?v=3","gravatar_id":"","url":"https://api.github.com/users/Vittly","html_url":"https://github.com/Vittly","followers_url":"https://api.github.com/users/Vittly/followers","following_url":"https://api.github.com/users/Vittly/following{/other_user}","gists_url":"https://api.github.com/users/Vittly/gists{/gist_id}","starred_url":"https://api.github.com/users/Vittly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Vittly/subscriptions","organizations_url":"https://api.github.com/users/Vittly/orgs","repos_url":"https://api.github.com/users/Vittly/repos","events_url":"https://api.github.com/users/Vittly/events{/privacy}","received_events_url":"https://api.github.com/users/Vittly/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/2/commits","review_comments_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/2/comments","review_comment_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/comments{/number}","comments_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/issues/2/comments","statuses_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/statuses/af205a387c538299543f50dbce3b2d5cc60268f7","head":{"label":"askeip:master","ref":"master","sha":"af205a387c538299543f50dbce3b2d5cc60268f7","user":{"login":"askeip","id":12084987,"avatar_url":"https://avatars.githubusercontent.com/u/12084987?v=3","gravatar_id":"","url":"https://api.github.com/users/askeip","html_url":"https://github.com/askeip","followers_url":"https://api.github.com/users/askeip/followers","following_url":"https://api.github.com/users/askeip/following{/other_user}","gists_url":"https://api.github.com/users/askeip/gists{/gist_id}","starred_url":"https://api.github.com/users/askeip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/askeip/subscriptions","organizations_url":"https://api.github.com/users/askeip/orgs","repos_url":"https://api.github.com/users/askeip/repos","events_url":"https://api.github.com/users/askeip/events{/privacy}","received_events_url":"https://api.github.com/users/askeip/received_events","type":"User","site_admin":false},"repo":{"id":72760825,"name":"javascript-task-5","full_name":"askeip/javascript-task-5","owner":{"login":"askeip","id":12084987,"avatar_url":"https://avatars.githubusercontent.com/u/12084987?v=3","gravatar_id":"","url":"https://api.github.com/users/askeip","html_url":"https://github.com/askeip","followers_url":"https://api.github.com/users/askeip/followers","following_url":"https://api.github.com/users/askeip/following{/other_user}","gists_url":"https://api.github.com/users/askeip/gists{/gist_id}","starred_url":"https://api.github.com/users/askeip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/askeip/subscriptions","organizations_url":"https://api.github.com/users/askeip/orgs","repos_url":"https://api.github.com/users/askeip/repos","events_url":"https://api.github.com/users/askeip/events{/privacy}","received_events_url":"https://api.github.com/users/askeip/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/askeip/javascript-task-5","description":"Задача «Пора на лекцию»","fork":true,"url":"https://api.github.com/repos/askeip/javascript-task-5","forks_url":"https://api.github.com/repos/askeip/javascript-task-5/forks","keys_url":"https://api.github.com/repos/askeip/javascript-task-5/keys{/key_id}","collaborators_url":"https://api.github.com/repos/askeip/javascript-task-5/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/askeip/javascript-task-5/teams","hooks_url":"https://api.github.com/repos/askeip/javascript-task-5/hooks","issue_events_url":"https://api.github.com/repos/askeip/javascript-task-5/issues/events{/number}","events_url":"https://api.github.com/repos/askeip/javascript-task-5/events","assignees_url":"https://api.github.com/repos/askeip/javascript-task-5/assignees{/user}","branches_url":"https://api.github.com/repos/askeip/javascript-task-5/branches{/branch}","tags_url":"https://api.github.com/repos/askeip/javascript-task-5/tags","blobs_url":"https://api.github.com/repos/askeip/javascript-task-5/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/askeip/javascript-task-5/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/askeip/javascript-task-5/git/refs{/sha}","trees_url":"https://api.github.com/repos/askeip/javascript-task-5/git/trees{/sha}","statuses_url":"https://api.github.com/repos/askeip/javascript-task-5/statuses/{sha}","languages_url":"https://api.github.com/repos/askeip/javascript-task-5/languages","stargazers_url":"https://api.github.com/repos/askeip/javascript-task-5/stargazers","contributors_url":"https://api.github.com/repos/askeip/javascript-task-5/contributors","subscribers_url":"https://api.github.com/repos/askeip/javascript-task-5/subscribers","subscription_url":"https://api.github.com/repos/askeip/javascript-task-5/subscription","commits_url":"https://api.github.com/repos/askeip/javascript-task-5/commits{/sha}","git_commits_url":"https://api.github.com/repos/askeip/javascript-task-5/git/commits{/sha}","comments_url":"https://api.github.com/repos/askeip/javascript-task-5/comments{/number}","issue_comment_url":"https://api.github.com/repos/askeip/javascript-task-5/issues/comments{/number}","contents_url":"https://api.github.com/repos/askeip/javascript-task-5/contents/{+path}","compare_url":"https://api.github.com/repos/askeip/javascript-task-5/compare/{base}...{head}","merges_url":"https://api.github.com/repos/askeip/javascript-task-5/merges","archive_url":"https://api.github.com/repos/askeip/javascript-task-5/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/askeip/javascript-task-5/downloads","issues_url":"https://api.github.com/repos/askeip/javascript-task-5/issues{/number}","pulls_url":"https://api.github.com/repos/askeip/javascript-task-5/pulls{/number}","milestones_url":"https://api.github.com/repos/askeip/javascript-task-5/milestones{/number}","notifications_url":"https://api.github.com/repos/askeip/javascript-task-5/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/askeip/javascript-task-5/labels{/name}","releases_url":"https://api.github.com/repos/askeip/javascript-task-5/releases{/id}","deployments_url":"https://api.github.com/repos/askeip/javascript-task-5/deployments","created_at":"2016-11-03T15:44:16Z","updated_at":"2016-11-03T15:44:17Z","pushed_at":"2016-11-16T10:58:23Z","git_url":"git://github.com/askeip/javascript-task-5.git","ssh_url":"git@github.com:askeip/javascript-task-5.git","clone_url":"https://github.com/askeip/javascript-task-5.git","svn_url":"https://github.com/askeip/javascript-task-5","homepage":"","size":20,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"urfu-2016:master","ref":"master","sha":"563654f35c98e52f1903ca1d4781372abdfb400e","user":{"login":"urfu-2016","id":22170529,"avatar_url":"https://avatars.githubusercontent.com/u/22170529?v=3","gravatar_id":"","url":"https://api.github.com/users/urfu-2016","html_url":"https://github.com/urfu-2016","followers_url":"https://api.github.com/users/urfu-2016/followers","following_url":"https://api.github.com/users/urfu-2016/following{/other_user}","gists_url":"https://api.github.com/users/urfu-2016/gists{/gist_id}","starred_url":"https://api.github.com/users/urfu-2016/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urfu-2016/subscriptions","organizations_url":"https://api.github.com/users/urfu-2016/orgs","repos_url":"https://api.github.com/users/urfu-2016/repos","events_url":"https://api.github.com/users/urfu-2016/events{/privacy}","received_events_url":"https://api.github.com/users/urfu-2016/received_events","type":"Organization","site_admin":false},"repo":{"id":72473952,"name":"javascript-task-5","full_name":"urfu-2016/javascript-task-5","owner":{"login":"urfu-2016","id":22170529,"avatar_url":"https://avatars.githubusercontent.com/u/22170529?v=3","gravatar_id":"","url":"https://api.github.com/users/urfu-2016","html_url":"https://github.com/urfu-2016","followers_url":"https://api.github.com/users/urfu-2016/followers","following_url":"https://api.github.com/users/urfu-2016/following{/other_user}","gists_url":"https://api.github.com/users/urfu-2016/gists{/gist_id}","starred_url":"https://api.github.com/users/urfu-2016/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urfu-2016/subscriptions","organizations_url":"https://api.github.com/users/urfu-2016/orgs","repos_url":"https://api.github.com/users/urfu-2016/repos","events_url":"https://api.github.com/users/urfu-2016/events{/privacy}","received_events_url":"https://api.github.com/users/urfu-2016/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/urfu-2016/javascript-task-5","description":"Задача «Пора на лекцию»","fork":false,"url":"https://api.github.com/repos/urfu-2016/javascript-task-5","forks_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/forks","keys_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/keys{/key_id}","collaborators_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/teams","hooks_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/hooks","issue_events_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/issues/events{/number}","events_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/events","assignees_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/assignees{/user}","branches_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/branches{/branch}","tags_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/tags","blobs_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/git/refs{/sha}","trees_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/git/trees{/sha}","statuses_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/statuses/{sha}","languages_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/languages","stargazers_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/stargazers","contributors_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/contributors","subscribers_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/subscribers","subscription_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/subscription","commits_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/commits{/sha}","git_commits_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/git/commits{/sha}","comments_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/comments{/number}","issue_comment_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/issues/comments{/number}","contents_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/contents/{+path}","compare_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/compare/{base}...{head}","merges_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/merges","archive_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/downloads","issues_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/issues{/number}","pulls_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls{/number}","milestones_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/milestones{/number}","notifications_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/labels{/name}","releases_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/releases{/id}","deployments_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/deployments","created_at":"2016-10-31T20:11:32Z","updated_at":"2016-11-03T13:58:41Z","pushed_at":"2016-11-17T06:18:35Z","git_url":"git://github.com/urfu-2016/javascript-task-5.git","ssh_url":"git@github.com:urfu-2016/javascript-task-5.git","clone_url":"https://github.com/urfu-2016/javascript-task-5.git","svn_url":"https://github.com/urfu-2016/javascript-task-5","homepage":"","size":158,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":72,"mirror_url":null,"open_issues_count":13,"forks":72,"open_issues":13,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/2"},"html":{"href":"https://github.com/urfu-2016/javascript-task-5/pull/2"},"issue":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-5/issues/2"},"comments":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-5/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-5/statuses/af205a387c538299543f50dbce3b2d5cc60268f7"}}}}
{"actor":{"display_login":"askeip"}}