{"action":"created","comment":{"url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/pulls/comments/43925954","id":43925954,"diff_hunk":"@@ -1,23 +1,102 @@\n module.exports = function () {\n+    var students = [];\n+    var subscribedStudents = [];\n     return {\n         on: function (eventName, student, callback) {\n+            if (students.indexOf(student) === -1) {\n+                students.push(student);\n+                var studentEvents = {}; //словарь событий\n+                studentEvents[eventName] = {\n+                    func: callback,\n+                    period: 1,\n+                    counter: 1, // счетчик, на каком шаге вызываем функцию\n+                    max: Number.MAX_SAFE_INTEGER // максимальное число вызова функции\n+                };\n+                var newStudent = {\n+                    data: student,\n+                    events: studentEvents\n+                };\n+                subscribedStudents.push(newStudent);\n+            } else {\n+                var index = this.getIndex(student);\n+                var keys = Object.keys(subscribedStudents[index]['events']);\n+                if (keys.indexOf(eventName) !== -1) {\n+                    subscribedStudents[index]['events'][eventName]['func'] = callback;\n+                } else {\n+                    subscribedStudents[index]['events'][eventName] = {\n+                        func: callback,\n+                        period: 1,\n+                        counter: 1,\n+                        max: Number.MAX_SAFE_INTEGER\n+                    };\n+                }\n+            }\n+        },\n \n+        getIndex: function (student) {\n+            var index = 0;\n+            for (var i = 0; i < subscribedStudents.length; i++) {\n+                var currentStudent = subscribedStudents[i];\n+                if (currentStudent.data === student) {\n+                    return i;\n+                }\n+            }\n+            return -1;\n         },\n \n         off: function (eventName, student) {\n-\n+            var index = this.getIndex(student);\n+            if (index !== -1) {\n+                var currentStudent = subscribedStudents[index];\n+                var keys = Object.keys(currentStudent.events);\n+                for (var i = 0; i < keys.length; i++) {\n+                    if (keys[i].indexOf(eventName) !== -1) {\n+                        delete currentStudent.events[keys[i]];\n+                    }\n+                }\n+            }\n         },\n \n         emit: function (eventName) {\n+            var namespace = this.getNamespace(eventName);\n+            for (var i = 0; i < subscribedStudents.length; i++) {\n+                var student = subscribedStudents[i];\n+                var keys = Object.keys(student.events);\n+                for (var j = 0; j < keys.length; j++) {\n+                    var currentEvent = student.events[keys[j]];\n+                    if (keys[j] === eventName || keys[j] === namespace) {\n+                        if (currentEvent.max > currentEvent.counter &&\n+                            currentEvent.counter % currentEvent.period === 0) {\n+                            currentEvent.func.call(student['data']);\n+                        }\n+                        currentEvent.counter += 1;\n+                    }\n+                }\n+            }\n+        },\n \n+        getNamespace: function (eventName) {\n+            var index = eventName.indexOf('.');\n+            var namespace = eventName;\n+            if (index !== -1) {\n+                namespace = eventName.slice(0, index);\n+            }\n+            return namespace;\n         },\n \n         several: function (eventName, student, callback, n) {\n-\n+            this.setAdditionalValue(eventName, student, callback, 'max', n);\n         },\n \n         through: function (eventName, student, callback, n) {\n+            this.setAdditionalValue(eventName, student, callback, 'period', n);\n+        },\n \n+        setAdditionalValue: function (eventName, student, callback, nameValue, n) {\n+            this.on(eventName, student, callback);\n+            var index = this.getIndex(student);\n+            var currentStudent = subscribedStudents[index];","path":"emitter.js","position":100,"original_position":100,"commit_id":"9baeca4884dbd981d65eaac2a44d18ed03795cab","original_commit_id":"9baeca4884dbd981d65eaac2a44d18ed03795cab","user":{"login":"gogoleff","id":4534405,"avatar_url":"https://avatars.githubusercontent.com/u/4534405?v=3","gravatar_id":"","url":"https://api.github.com/users/gogoleff","html_url":"https://github.com/gogoleff","followers_url":"https://api.github.com/users/gogoleff/followers","following_url":"https://api.github.com/users/gogoleff/following{/other_user}","gists_url":"https://api.github.com/users/gogoleff/gists{/gist_id}","starred_url":"https://api.github.com/users/gogoleff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gogoleff/subscriptions","organizations_url":"https://api.github.com/users/gogoleff/orgs","repos_url":"https://api.github.com/users/gogoleff/repos","events_url":"https://api.github.com/users/gogoleff/events{/privacy}","received_events_url":"https://api.github.com/users/gogoleff/received_events","type":"User","site_admin":false},"body":"Переменная не нужна","created_at":"2015-11-04T19:23:12Z","updated_at":"2015-11-04T19:23:12Z","html_url":"https://github.com/urfu-2015/javascript-tasks-5/pull/11#discussion_r43925954","pull_request_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/pulls/11","_links":{"self":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/pulls/comments/43925954"},"html":{"href":"https://github.com/urfu-2015/javascript-tasks-5/pull/11#discussion_r43925954"},"pull_request":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/pulls/11"}}},"pull_request":{"url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/pulls/11","id":49347811,"html_url":"https://github.com/urfu-2015/javascript-tasks-5/pull/11","diff_url":"https://github.com/urfu-2015/javascript-tasks-5/pull/11.diff","patch_url":"https://github.com/urfu-2015/javascript-tasks-5/pull/11.patch","issue_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/issues/11","number":11,"state":"open","locked":false,"title":"Баженова Анна","user":{"login":"bazhenova","id":12410663,"avatar_url":"https://avatars.githubusercontent.com/u/12410663?v=3","gravatar_id":"","url":"https://api.github.com/users/bazhenova","html_url":"https://github.com/bazhenova","followers_url":"https://api.github.com/users/bazhenova/followers","following_url":"https://api.github.com/users/bazhenova/following{/other_user}","gists_url":"https://api.github.com/users/bazhenova/gists{/gist_id}","starred_url":"https://api.github.com/users/bazhenova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bazhenova/subscriptions","organizations_url":"https://api.github.com/users/bazhenova/orgs","repos_url":"https://api.github.com/users/bazhenova/repos","events_url":"https://api.github.com/users/bazhenova/events{/privacy}","received_events_url":"https://api.github.com/users/bazhenova/received_events","type":"User","site_admin":false},"body":null,"created_at":"2015-10-31T11:47:08Z","updated_at":"2015-11-04T19:23:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0fbdc5b9b4e42d21c9f84b4615cfc2bb6fef4a70","assignee":{"login":"gogoleff","id":4534405,"avatar_url":"https://avatars.githubusercontent.com/u/4534405?v=3","gravatar_id":"","url":"https://api.github.com/users/gogoleff","html_url":"https://github.com/gogoleff","followers_url":"https://api.github.com/users/gogoleff/followers","following_url":"https://api.github.com/users/gogoleff/following{/other_user}","gists_url":"https://api.github.com/users/gogoleff/gists{/gist_id}","starred_url":"https://api.github.com/users/gogoleff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gogoleff/subscriptions","organizations_url":"https://api.github.com/users/gogoleff/orgs","repos_url":"https://api.github.com/users/gogoleff/repos","events_url":"https://api.github.com/users/gogoleff/events{/privacy}","received_events_url":"https://api.github.com/users/gogoleff/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/pulls/11/commits","review_comments_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/pulls/11/comments","review_comment_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/pulls/comments{/number}","comments_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/issues/11/comments","statuses_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/statuses/9baeca4884dbd981d65eaac2a44d18ed03795cab","head":{"label":"bazhenova:master","ref":"master","sha":"9baeca4884dbd981d65eaac2a44d18ed03795cab","user":{"login":"bazhenova","id":12410663,"avatar_url":"https://avatars.githubusercontent.com/u/12410663?v=3","gravatar_id":"","url":"https://api.github.com/users/bazhenova","html_url":"https://github.com/bazhenova","followers_url":"https://api.github.com/users/bazhenova/followers","following_url":"https://api.github.com/users/bazhenova/following{/other_user}","gists_url":"https://api.github.com/users/bazhenova/gists{/gist_id}","starred_url":"https://api.github.com/users/bazhenova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bazhenova/subscriptions","organizations_url":"https://api.github.com/users/bazhenova/orgs","repos_url":"https://api.github.com/users/bazhenova/repos","events_url":"https://api.github.com/users/bazhenova/events{/privacy}","received_events_url":"https://api.github.com/users/bazhenova/received_events","type":"User","site_admin":false},"repo":{"id":45198489,"name":"javascript-tasks-5","full_name":"bazhenova/javascript-tasks-5","owner":{"login":"bazhenova","id":12410663,"avatar_url":"https://avatars.githubusercontent.com/u/12410663?v=3","gravatar_id":"","url":"https://api.github.com/users/bazhenova","html_url":"https://github.com/bazhenova","followers_url":"https://api.github.com/users/bazhenova/followers","following_url":"https://api.github.com/users/bazhenova/following{/other_user}","gists_url":"https://api.github.com/users/bazhenova/gists{/gist_id}","starred_url":"https://api.github.com/users/bazhenova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bazhenova/subscriptions","organizations_url":"https://api.github.com/users/bazhenova/orgs","repos_url":"https://api.github.com/users/bazhenova/repos","events_url":"https://api.github.com/users/bazhenova/events{/privacy}","received_events_url":"https://api.github.com/users/bazhenova/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bazhenova/javascript-tasks-5","description":"Задача к лекции «This / Bind / Call / Apply» – «Пора на лекцию»","fork":true,"url":"https://api.github.com/repos/bazhenova/javascript-tasks-5","forks_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/forks","keys_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/teams","hooks_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/hooks","issue_events_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/issues/events{/number}","events_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/events","assignees_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/assignees{/user}","branches_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/branches{/branch}","tags_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/tags","blobs_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/git/refs{/sha}","trees_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/statuses/{sha}","languages_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/languages","stargazers_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/stargazers","contributors_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/contributors","subscribers_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/subscribers","subscription_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/subscription","commits_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/commits{/sha}","git_commits_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/git/commits{/sha}","comments_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/comments{/number}","issue_comment_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/issues/comments{/number}","contents_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/contents/{+path}","compare_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/merges","archive_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/downloads","issues_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/issues{/number}","pulls_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/pulls{/number}","milestones_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/milestones{/number}","notifications_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/labels{/name}","releases_url":"https://api.github.com/repos/bazhenova/javascript-tasks-5/releases{/id}","created_at":"2015-10-29T17:12:42Z","updated_at":"2015-10-29T17:12:45Z","pushed_at":"2015-11-02T18:29:49Z","git_url":"git://github.com/bazhenova/javascript-tasks-5.git","ssh_url":"git@github.com:bazhenova/javascript-tasks-5.git","clone_url":"https://github.com/bazhenova/javascript-tasks-5.git","svn_url":"https://github.com/bazhenova/javascript-tasks-5","homepage":"","size":92,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"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-2015:master","ref":"master","sha":"f07a8ef71e7f4d9a465fc78e1729079bfa2b359f","user":{"login":"urfu-2015","id":14800971,"avatar_url":"https://avatars.githubusercontent.com/u/14800971?v=3","gravatar_id":"","url":"https://api.github.com/users/urfu-2015","html_url":"https://github.com/urfu-2015","followers_url":"https://api.github.com/users/urfu-2015/followers","following_url":"https://api.github.com/users/urfu-2015/following{/other_user}","gists_url":"https://api.github.com/users/urfu-2015/gists{/gist_id}","starred_url":"https://api.github.com/users/urfu-2015/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urfu-2015/subscriptions","organizations_url":"https://api.github.com/users/urfu-2015/orgs","repos_url":"https://api.github.com/users/urfu-2015/repos","events_url":"https://api.github.com/users/urfu-2015/events{/privacy}","received_events_url":"https://api.github.com/users/urfu-2015/received_events","type":"Organization","site_admin":false},"repo":{"id":45039556,"name":"javascript-tasks-5","full_name":"urfu-2015/javascript-tasks-5","owner":{"login":"urfu-2015","id":14800971,"avatar_url":"https://avatars.githubusercontent.com/u/14800971?v=3","gravatar_id":"","url":"https://api.github.com/users/urfu-2015","html_url":"https://github.com/urfu-2015","followers_url":"https://api.github.com/users/urfu-2015/followers","following_url":"https://api.github.com/users/urfu-2015/following{/other_user}","gists_url":"https://api.github.com/users/urfu-2015/gists{/gist_id}","starred_url":"https://api.github.com/users/urfu-2015/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/urfu-2015/subscriptions","organizations_url":"https://api.github.com/users/urfu-2015/orgs","repos_url":"https://api.github.com/users/urfu-2015/repos","events_url":"https://api.github.com/users/urfu-2015/events{/privacy}","received_events_url":"https://api.github.com/users/urfu-2015/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/urfu-2015/javascript-tasks-5","description":"Задача к лекции «This / Bind / Call / Apply» – «Пора на лекцию»","fork":false,"url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5","forks_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/forks","keys_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/keys{/key_id}","collaborators_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/teams","hooks_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/hooks","issue_events_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/issues/events{/number}","events_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/events","assignees_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/assignees{/user}","branches_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/branches{/branch}","tags_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/tags","blobs_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/git/refs{/sha}","trees_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/git/trees{/sha}","statuses_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/statuses/{sha}","languages_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/languages","stargazers_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/stargazers","contributors_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/contributors","subscribers_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/subscribers","subscription_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/subscription","commits_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/commits{/sha}","git_commits_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/git/commits{/sha}","comments_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/comments{/number}","issue_comment_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/issues/comments{/number}","contents_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/contents/{+path}","compare_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/compare/{base}...{head}","merges_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/merges","archive_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/downloads","issues_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/issues{/number}","pulls_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/pulls{/number}","milestones_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/milestones{/number}","notifications_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/labels{/name}","releases_url":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/releases{/id}","created_at":"2015-10-27T12:30:35Z","updated_at":"2015-10-27T13:29:31Z","pushed_at":"2015-11-04T19:21:10Z","git_url":"git://github.com/urfu-2015/javascript-tasks-5.git","ssh_url":"git@github.com:urfu-2015/javascript-tasks-5.git","clone_url":"https://github.com/urfu-2015/javascript-tasks-5.git","svn_url":"https://github.com/urfu-2015/javascript-tasks-5","homepage":"","size":1523,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":54,"mirror_url":null,"open_issues_count":43,"forks":54,"open_issues":43,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/pulls/11"},"html":{"href":"https://github.com/urfu-2015/javascript-tasks-5/pull/11"},"issue":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/issues/11"},"comments":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/issues/11/comments"},"review_comments":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/pulls/11/comments"},"review_comment":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/pulls/11/commits"},"statuses":{"href":"https://api.github.com/repos/urfu-2015/javascript-tasks-5/statuses/9baeca4884dbd981d65eaac2a44d18ed03795cab"}}}}