{"action":"created","comment":{"url":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/comments/87886592","pull_request_review_id":8476337,"id":87886592,"diff_hunk":"@@ -7,38 +7,100 @@\n getEmitter.isStar = true;\n module.exports = getEmitter;\n \n+function isEmiting(subscriber) {\n+    if (Object.keys(subscriber)[2] === 'frequency') {\n+        var currentFrequency = subscriber.frequency[1];\n+        subscriber.frequency[1]++;\n+\n+        return currentFrequency % subscriber.frequency[0] === 0;\n+    }\n+    if (Object.keys(subscriber)[2] === 'times') {\n+        subscriber.times--;\n+\n+        return subscriber.times >= 0;\n+    }\n+\n+    return true;\n+}\n+\n /**\n  * Возвращает новый emitter\n  * @returns {Object}\n  */\n function getEmitter() {\n+    var events = {};\n+\n     return {\n \n         /**\n          * Подписаться на событие\n          * @param {String} event\n          * @param {Object} context\n          * @param {Function} handler\n+         * @returns {Object}\n          */\n         on: function (event, context, handler) {\n-            console.info(event, context, handler);\n+            if (!(event in events)) {\n+                events[event] = [];\n+            }\n+            events[event].push({\n+                context: context,\n+                handler: handler.bind(context)\n+            });\n+            if (arguments[3]) {\n+                var nameParams = Object.keys(arguments[3]);\n+                var extraParam = arguments[3][nameParams];\n+                var numberOfLastSubscriber = events[event].length - 1;\n+                events[event][numberOfLastSubscriber][nameParams] = extraParam;\n+            }\n+\n+            return this;\n         },\n \n         /**\n          * Отписаться от события\n          * @param {String} event\n          * @param {Object} context\n+         * @returns {Object}\n          */\n         off: function (event, context) {\n-            console.info(event, context);\n+            var eventsForDelete = Object.keys(events).filter(function (storedEvent) {\n+                return storedEvent.indexOf(event + '.') === 0 || event === storedEvent;\n+            });\n+            eventsForDelete.forEach(function (eventForDelete) {\n+                events[eventForDelete] = events[eventForDelete].filter(function (subscriber) {\n+                    return subscriber.context !== context;\n+                });\n+            }, this);\n+\n+            return this;\n         },\n \n         /**\n          * Уведомить о событии\n          * @param {String} event\n+         * @returns {Object}\n          */\n         emit: function (event) {\n-            console.info(event);\n+            var nameEvents = event.split('.');\n+            nameEvents[0] = event;\n+            nameEvents.reduce(function (prev, curr, i) {\n+                nameEvents[i] = prev.slice(0, prev.lastIndexOf('.'));\n+\n+                return nameEvents[i];\n+            });\n+            var filteredNames = nameEvents.filter(function (eventForCheck) {\n+                return (eventForCheck in events);\n+            }, this);\n+            filteredNames.forEach(function (eventForCall) {\n+                events[eventForCall].forEach(function (subscriber) {\n+                    if (isEmiting(subscriber)) {\n+                        subscriber.handler.call();","path":"emitter.js","position":95,"original_position":95,"commit_id":"9f70087cac6d3a2747264c1ea803a6de7d25cba8","original_commit_id":"9f70087cac6d3a2747264c1ea803a6de7d25cba8","user":{"login":"sameoldmadness","id":1537724,"avatar_url":"https://avatars.githubusercontent.com/u/1537724?v=3","gravatar_id":"","url":"https://api.github.com/users/sameoldmadness","html_url":"https://github.com/sameoldmadness","followers_url":"https://api.github.com/users/sameoldmadness/followers","following_url":"https://api.github.com/users/sameoldmadness/following{/other_user}","gists_url":"https://api.github.com/users/sameoldmadness/gists{/gist_id}","starred_url":"https://api.github.com/users/sameoldmadness/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sameoldmadness/subscriptions","organizations_url":"https://api.github.com/users/sameoldmadness/orgs","repos_url":"https://api.github.com/users/sameoldmadness/repos","events_url":"https://api.github.com/users/sameoldmadness/events{/privacy}","received_events_url":"https://api.github.com/users/sameoldmadness/received_events","type":"User","site_admin":false},"body":"Зачем `call`?","created_at":"2016-11-14T20:33:52Z","updated_at":"2016-11-14T20:37:55Z","html_url":"https://github.com/urfu-2016/javascript-task-5/pull/45#discussion_r87886592","pull_request_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/45","_links":{"self":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/comments/87886592"},"html":{"href":"https://github.com/urfu-2016/javascript-task-5/pull/45#discussion_r87886592"},"pull_request":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/45"}}},"pull_request":{"url":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/45","id":93011836,"html_url":"https://github.com/urfu-2016/javascript-task-5/pull/45","diff_url":"https://github.com/urfu-2016/javascript-task-5/pull/45.diff","patch_url":"https://github.com/urfu-2016/javascript-task-5/pull/45.patch","issue_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/issues/45","number":45,"state":"open","locked":false,"title":"Дружинин Алексей","user":{"login":"ADruzhinin","id":22199035,"avatar_url":"https://avatars.githubusercontent.com/u/22199035?v=3","gravatar_id":"","url":"https://api.github.com/users/ADruzhinin","html_url":"https://github.com/ADruzhinin","followers_url":"https://api.github.com/users/ADruzhinin/followers","following_url":"https://api.github.com/users/ADruzhinin/following{/other_user}","gists_url":"https://api.github.com/users/ADruzhinin/gists{/gist_id}","starred_url":"https://api.github.com/users/ADruzhinin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ADruzhinin/subscriptions","organizations_url":"https://api.github.com/users/ADruzhinin/orgs","repos_url":"https://api.github.com/users/ADruzhinin/repos","events_url":"https://api.github.com/users/ADruzhinin/events{/privacy}","received_events_url":"https://api.github.com/users/ADruzhinin/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-11-09T18:13:20Z","updated_at":"2016-11-14T20:37:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"82cce9fb820738e715045158a89211c6d56822f6","assignee":{"login":"sameoldmadness","id":1537724,"avatar_url":"https://avatars.githubusercontent.com/u/1537724?v=3","gravatar_id":"","url":"https://api.github.com/users/sameoldmadness","html_url":"https://github.com/sameoldmadness","followers_url":"https://api.github.com/users/sameoldmadness/followers","following_url":"https://api.github.com/users/sameoldmadness/following{/other_user}","gists_url":"https://api.github.com/users/sameoldmadness/gists{/gist_id}","starred_url":"https://api.github.com/users/sameoldmadness/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sameoldmadness/subscriptions","organizations_url":"https://api.github.com/users/sameoldmadness/orgs","repos_url":"https://api.github.com/users/sameoldmadness/repos","events_url":"https://api.github.com/users/sameoldmadness/events{/privacy}","received_events_url":"https://api.github.com/users/sameoldmadness/received_events","type":"User","site_admin":false},"assignees":[{"login":"sameoldmadness","id":1537724,"avatar_url":"https://avatars.githubusercontent.com/u/1537724?v=3","gravatar_id":"","url":"https://api.github.com/users/sameoldmadness","html_url":"https://github.com/sameoldmadness","followers_url":"https://api.github.com/users/sameoldmadness/followers","following_url":"https://api.github.com/users/sameoldmadness/following{/other_user}","gists_url":"https://api.github.com/users/sameoldmadness/gists{/gist_id}","starred_url":"https://api.github.com/users/sameoldmadness/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sameoldmadness/subscriptions","organizations_url":"https://api.github.com/users/sameoldmadness/orgs","repos_url":"https://api.github.com/users/sameoldmadness/repos","events_url":"https://api.github.com/users/sameoldmadness/events{/privacy}","received_events_url":"https://api.github.com/users/sameoldmadness/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/45/commits","review_comments_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/45/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/45/comments","statuses_url":"https://api.github.com/repos/urfu-2016/javascript-task-5/statuses/9f70087cac6d3a2747264c1ea803a6de7d25cba8","head":{"label":"ADruzhinin:master","ref":"master","sha":"9f70087cac6d3a2747264c1ea803a6de7d25cba8","user":{"login":"ADruzhinin","id":22199035,"avatar_url":"https://avatars.githubusercontent.com/u/22199035?v=3","gravatar_id":"","url":"https://api.github.com/users/ADruzhinin","html_url":"https://github.com/ADruzhinin","followers_url":"https://api.github.com/users/ADruzhinin/followers","following_url":"https://api.github.com/users/ADruzhinin/following{/other_user}","gists_url":"https://api.github.com/users/ADruzhinin/gists{/gist_id}","starred_url":"https://api.github.com/users/ADruzhinin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ADruzhinin/subscriptions","organizations_url":"https://api.github.com/users/ADruzhinin/orgs","repos_url":"https://api.github.com/users/ADruzhinin/repos","events_url":"https://api.github.com/users/ADruzhinin/events{/privacy}","received_events_url":"https://api.github.com/users/ADruzhinin/received_events","type":"User","site_admin":false},"repo":{"id":73209417,"name":"javascript-task-5","full_name":"ADruzhinin/javascript-task-5","owner":{"login":"ADruzhinin","id":22199035,"avatar_url":"https://avatars.githubusercontent.com/u/22199035?v=3","gravatar_id":"","url":"https://api.github.com/users/ADruzhinin","html_url":"https://github.com/ADruzhinin","followers_url":"https://api.github.com/users/ADruzhinin/followers","following_url":"https://api.github.com/users/ADruzhinin/following{/other_user}","gists_url":"https://api.github.com/users/ADruzhinin/gists{/gist_id}","starred_url":"https://api.github.com/users/ADruzhinin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ADruzhinin/subscriptions","organizations_url":"https://api.github.com/users/ADruzhinin/orgs","repos_url":"https://api.github.com/users/ADruzhinin/repos","events_url":"https://api.github.com/users/ADruzhinin/events{/privacy}","received_events_url":"https://api.github.com/users/ADruzhinin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ADruzhinin/javascript-task-5","description":"Задача «Пора на лекцию»","fork":true,"url":"https://api.github.com/repos/ADruzhinin/javascript-task-5","forks_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/forks","keys_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/teams","hooks_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/hooks","issue_events_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/issues/events{/number}","events_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/events","assignees_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/assignees{/user}","branches_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/branches{/branch}","tags_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/tags","blobs_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/git/refs{/sha}","trees_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/statuses/{sha}","languages_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/languages","stargazers_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/stargazers","contributors_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/contributors","subscribers_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/subscribers","subscription_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/subscription","commits_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/commits{/sha}","git_commits_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/git/commits{/sha}","comments_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/comments{/number}","issue_comment_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/issues/comments{/number}","contents_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/contents/{+path}","compare_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/merges","archive_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/downloads","issues_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/issues{/number}","pulls_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/pulls{/number}","milestones_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/milestones{/number}","notifications_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/labels{/name}","releases_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/releases{/id}","deployments_url":"https://api.github.com/repos/ADruzhinin/javascript-task-5/deployments","created_at":"2016-11-08T17:18:11Z","updated_at":"2016-11-08T17:18:12Z","pushed_at":"2016-11-13T11:49:35Z","git_url":"git://github.com/ADruzhinin/javascript-task-5.git","ssh_url":"git@github.com:ADruzhinin/javascript-task-5.git","clone_url":"https://github.com/ADruzhinin/javascript-task-5.git","svn_url":"https://github.com/ADruzhinin/javascript-task-5","homepage":"","size":11,"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":"72e36b67d3dab11e0968ba743a23cf77652ec2c1","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-14T20:19:09Z","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":71,"mirror_url":null,"open_issues_count":31,"forks":71,"open_issues":31,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/45"},"html":{"href":"https://github.com/urfu-2016/javascript-task-5/pull/45"},"issue":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-5/issues/45"},"comments":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-5/issues/45/comments"},"review_comments":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-5/pulls/45/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/45/commits"},"statuses":{"href":"https://api.github.com/repos/urfu-2016/javascript-task-5/statuses/9f70087cac6d3a2747264c1ea803a6de7d25cba8"}}}}
{"actor":{"display_login":"sameoldmadness"}}