GitHub PullRequestReviewCommentEvent at 2014-06-10 18:32:40
Repository: underscore
Actor: josephspens
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/jashkenas/underscore/pulls/comments/13610659","id":13610659,"diff_hunk":"@@ -484,4 +484,26 @@\n     equal(testAfter(0, 1), 1, 'after(0) should fire when first invoked');\n   });\n \n+  test('before', function() {\n+    var testBefore = function(beforeAmount, timesCalled) {\n+      var beforeCalled = 0;\n+      var before = _.before(beforeAmount, function() {\n+        beforeCalled++;\n+      });\n+      while (timesCalled--) before();\n+      return beforeCalled;\n+    };\n+\n+    equal(testBefore(5, 5), 4, 'before(N) should not fire after being called N times');\n+    equal(testBefore(5, 4), 4, 'before(N) should fire before being called N times');\n+    equal(testBefore(0, 0), 0, 'before(0) should not fire immediately');\n+    equal(testBefore(0, 1), 0, 'before(0) should not fire when first invoked');\n+\n+    var num = 0;\n+    var increment = _.before(3, function(){ return ++num; });\n+    increment();\n+    increment();\n+    equal(increment(), 2, 'stores a memo to the last value');","path":"test/functions.js","position":34,"original_position":34,"commit_id":"4ccfc99b8ab6ded40cbf8742c04ac8fc4a2d3b85","original_commit_id":"4ccfc99b8ab6ded40cbf8742c04ac8fc4a2d3b85","user":{"login":"josephspens","id":933676,"avatar_url":"https://avatars.githubusercontent.com/u/933676?","gravatar_id":"c3768febe81a388c14baa9c97a38b22a","url":"https://api.github.com/users/josephspens","html_url":"https://github.com/josephspens","followers_url":"https://api.github.com/users/josephspens/followers","following_url":"https://api.github.com/users/josephspens/following{/other_user}","gists_url":"https://api.github.com/users/josephspens/gists{/gist_id}","starred_url":"https://api.github.com/users/josephspens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josephspens/subscriptions","organizations_url":"https://api.github.com/users/josephspens/orgs","repos_url":"https://api.github.com/users/josephspens/repos","events_url":"https://api.github.com/users/josephspens/events{/privacy}","received_events_url":"https://api.github.com/users/josephspens/received_events","type":"User","site_admin":false},"body":"I just realized this test actually does the same thing as the first test above. Should we remove this, or refactor it?","created_at":"2014-06-10T18:32:40Z","updated_at":"2014-06-10T18:32:40Z","html_url":"https://github.com/jashkenas/underscore/pull/1628#discussion_r13610659","pull_request_url":"https://api.github.com/repos/jashkenas/underscore/pulls/1628","_links":{"self":{"href":"https://api.github.com/repos/jashkenas/underscore/pulls/comments/13610659"},"html":{"href":"https://github.com/jashkenas/underscore/pull/1628#discussion_r13610659"},"pull_request":{"href":"https://api.github.com/repos/jashkenas/underscore/pulls/1628"}}},"pull_request":{"url":"https://api.github.com/repos/jashkenas/underscore/pulls/1628","id":15558020,"html_url":"https://github.com/jashkenas/underscore/pull/1628","diff_url":"https://github.com/jashkenas/underscore/pull/1628.diff","patch_url":"https://github.com/jashkenas/underscore/pull/1628.patch","issue_url":"https://api.github.com/repos/jashkenas/underscore/issues/1628","number":1628,"state":"open","title":"Add _.before() function to negate _.after()","user":{"login":"josephspens","id":933676,"avatar_url":"https://avatars.githubusercontent.com/u/933676?","gravatar_id":"c3768febe81a388c14baa9c97a38b22a","url":"https://api.github.com/users/josephspens","html_url":"https://github.com/josephspens","followers_url":"https://api.github.com/users/josephspens/followers","following_url":"https://api.github.com/users/josephspens/following{/other_user}","gists_url":"https://api.github.com/users/josephspens/gists{/gist_id}","starred_url":"https://api.github.com/users/josephspens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josephspens/subscriptions","organizations_url":"https://api.github.com/users/josephspens/orgs","repos_url":"https://api.github.com/users/josephspens/repos","events_url":"https://api.github.com/users/josephspens/events{/privacy}","received_events_url":"https://api.github.com/users/josephspens/received_events","type":"User","site_admin":false},"body":"I'm not sure if this PR belongs in this repository or the contributing repository, please let me know if I need to move it.\r\n\r\nI couldn't find any simple way to limit the number of times a function runs using existing underscore functions. I came up with a non-underscore solution, and it turned out I reverse engineered something similar to the `_.after()` function.\r\n\r\nUnlike `_.after()`, which only runs a function after it has been called n times, `_.before()` runs a function _until_ it has been called n times.\r\n\r\nAn example usage of this behavior is adding items to a list. I set up a function to add the items to the list, but I want to limit the number of times an item is added. An underscore alternative would be something like using `_.after()` and null the function after n calls.","created_at":"2014-05-06T18:50:51Z","updated_at":"2014-06-10T18:32:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6e66b8b308514af4fc86a0c2cd5cc6f076b1ef90","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jashkenas/underscore/pulls/1628/commits","review_comments_url":"https://api.github.com/repos/jashkenas/underscore/pulls/1628/comments","review_comment_url":"https://api.github.com/repos/jashkenas/underscore/pulls/comments/{number}","comments_url":"https://api.github.com/repos/jashkenas/underscore/issues/1628/comments","statuses_url":"https://api.github.com/repos/jashkenas/underscore/statuses/4ccfc99b8ab6ded40cbf8742c04ac8fc4a2d3b85","head":{"label":"josephspens:before","ref":"before","sha":"4ccfc99b8ab6ded40cbf8742c04ac8fc4a2d3b85","user":{"login":"josephspens","id":933676,"avatar_url":"https://avatars.githubusercontent.com/u/933676?","gravatar_id":"c3768febe81a388c14baa9c97a38b22a","url":"https://api.github.com/users/josephspens","html_url":"https://github.com/josephspens","followers_url":"https://api.github.com/users/josephspens/followers","following_url":"https://api.github.com/users/josephspens/following{/other_user}","gists_url":"https://api.github.com/users/josephspens/gists{/gist_id}","starred_url":"https://api.github.com/users/josephspens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josephspens/subscriptions","organizations_url":"https://api.github.com/users/josephspens/orgs","repos_url":"https://api.github.com/users/josephspens/repos","events_url":"https://api.github.com/users/josephspens/events{/privacy}","received_events_url":"https://api.github.com/users/josephspens/received_events","type":"User","site_admin":false},"repo":{"id":19504955,"name":"underscore","full_name":"josephspens/underscore","owner":{"login":"josephspens","id":933676,"avatar_url":"https://avatars.githubusercontent.com/u/933676?","gravatar_id":"c3768febe81a388c14baa9c97a38b22a","url":"https://api.github.com/users/josephspens","html_url":"https://github.com/josephspens","followers_url":"https://api.github.com/users/josephspens/followers","following_url":"https://api.github.com/users/josephspens/following{/other_user}","gists_url":"https://api.github.com/users/josephspens/gists{/gist_id}","starred_url":"https://api.github.com/users/josephspens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josephspens/subscriptions","organizations_url":"https://api.github.com/users/josephspens/orgs","repos_url":"https://api.github.com/users/josephspens/repos","events_url":"https://api.github.com/users/josephspens/events{/privacy}","received_events_url":"https://api.github.com/users/josephspens/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/josephspens/underscore","description":"JavaScript's utility _ belt","fork":true,"url":"https://api.github.com/repos/josephspens/underscore","forks_url":"https://api.github.com/repos/josephspens/underscore/forks","keys_url":"https://api.github.com/repos/josephspens/underscore/keys{/key_id}","collaborators_url":"https://api.github.com/repos/josephspens/underscore/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/josephspens/underscore/teams","hooks_url":"https://api.github.com/repos/josephspens/underscore/hooks","issue_events_url":"https://api.github.com/repos/josephspens/underscore/issues/events{/number}","events_url":"https://api.github.com/repos/josephspens/underscore/events","assignees_url":"https://api.github.com/repos/josephspens/underscore/assignees{/user}","branches_url":"https://api.github.com/repos/josephspens/underscore/branches{/branch}","tags_url":"https://api.github.com/repos/josephspens/underscore/tags","blobs_url":"https://api.github.com/repos/josephspens/underscore/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/josephspens/underscore/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/josephspens/underscore/git/refs{/sha}","trees_url":"https://api.github.com/repos/josephspens/underscore/git/trees{/sha}","statuses_url":"https://api.github.com/repos/josephspens/underscore/statuses/{sha}","languages_url":"https://api.github.com/repos/josephspens/underscore/languages","stargazers_url":"https://api.github.com/repos/josephspens/underscore/stargazers","contributors_url":"https://api.github.com/repos/josephspens/underscore/contributors","subscribers_url":"https://api.github.com/repos/josephspens/underscore/subscribers","subscription_url":"https://api.github.com/repos/josephspens/underscore/subscription","commits_url":"https://api.github.com/repos/josephspens/underscore/commits{/sha}","git_commits_url":"https://api.github.com/repos/josephspens/underscore/git/commits{/sha}","comments_url":"https://api.github.com/repos/josephspens/underscore/comments{/number}","issue_comment_url":"https://api.github.com/repos/josephspens/underscore/issues/comments/{number}","contents_url":"https://api.github.com/repos/josephspens/underscore/contents/{+path}","compare_url":"https://api.github.com/repos/josephspens/underscore/compare/{base}...{head}","merges_url":"https://api.github.com/repos/josephspens/underscore/merges","archive_url":"https://api.github.com/repos/josephspens/underscore/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/josephspens/underscore/downloads","issues_url":"https://api.github.com/repos/josephspens/underscore/issues{/number}","pulls_url":"https://api.github.com/repos/josephspens/underscore/pulls{/number}","milestones_url":"https://api.github.com/repos/josephspens/underscore/milestones{/number}","notifications_url":"https://api.github.com/repos/josephspens/underscore/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/josephspens/underscore/labels{/name}","releases_url":"https://api.github.com/repos/josephspens/underscore/releases{/id}","created_at":"2014-05-06T18:06:45Z","updated_at":"2014-06-10T16:40:58Z","pushed_at":"2014-06-10T16:41:01Z","git_url":"git://github.com/josephspens/underscore.git","ssh_url":"git@github.com:josephspens/underscore.git","clone_url":"https://github.com/josephspens/underscore.git","svn_url":"https://github.com/josephspens/underscore","homepage":"http://underscorejs.org","size":3455,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"jashkenas:master","ref":"master","sha":"812334d37f5fd0fbb57aed3a5c6ca4e93cdbbfa9","user":{"login":"jashkenas","id":4732,"avatar_url":"https://avatars.githubusercontent.com/u/4732?","gravatar_id":"32652ed5b8fbd2ecdb1c78e9ac567b4b","url":"https://api.github.com/users/jashkenas","html_url":"https://github.com/jashkenas","followers_url":"https://api.github.com/users/jashkenas/followers","following_url":"https://api.github.com/users/jashkenas/following{/other_user}","gists_url":"https://api.github.com/users/jashkenas/gists{/gist_id}","starred_url":"https://api.github.com/users/jashkenas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jashkenas/subscriptions","organizations_url":"https://api.github.com/users/jashkenas/orgs","repos_url":"https://api.github.com/users/jashkenas/repos","events_url":"https://api.github.com/users/jashkenas/events{/privacy}","received_events_url":"https://api.github.com/users/jashkenas/received_events","type":"User","site_admin":false},"repo":{"id":349241,"name":"underscore","full_name":"jashkenas/underscore","owner":{"login":"jashkenas","id":4732,"avatar_url":"https://avatars.githubusercontent.com/u/4732?","gravatar_id":"32652ed5b8fbd2ecdb1c78e9ac567b4b","url":"https://api.github.com/users/jashkenas","html_url":"https://github.com/jashkenas","followers_url":"https://api.github.com/users/jashkenas/followers","following_url":"https://api.github.com/users/jashkenas/following{/other_user}","gists_url":"https://api.github.com/users/jashkenas/gists{/gist_id}","starred_url":"https://api.github.com/users/jashkenas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jashkenas/subscriptions","organizations_url":"https://api.github.com/users/jashkenas/orgs","repos_url":"https://api.github.com/users/jashkenas/repos","events_url":"https://api.github.com/users/jashkenas/events{/privacy}","received_events_url":"https://api.github.com/users/jashkenas/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jashkenas/underscore","description":"JavaScript's utility _ belt","fork":false,"url":"https://api.github.com/repos/jashkenas/underscore","forks_url":"https://api.github.com/repos/jashkenas/underscore/forks","keys_url":"https://api.github.com/repos/jashkenas/underscore/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jashkenas/underscore/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jashkenas/underscore/teams","hooks_url":"https://api.github.com/repos/jashkenas/underscore/hooks","issue_events_url":"https://api.github.com/repos/jashkenas/underscore/issues/events{/number}","events_url":"https://api.github.com/repos/jashkenas/underscore/events","assignees_url":"https://api.github.com/repos/jashkenas/underscore/assignees{/user}","branches_url":"https://api.github.com/repos/jashkenas/underscore/branches{/branch}","tags_url":"https://api.github.com/repos/jashkenas/underscore/tags","blobs_url":"https://api.github.com/repos/jashkenas/underscore/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jashkenas/underscore/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jashkenas/underscore/git/refs{/sha}","trees_url":"https://api.github.com/repos/jashkenas/underscore/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jashkenas/underscore/statuses/{sha}","languages_url":"https://api.github.com/repos/jashkenas/underscore/languages","stargazers_url":"https://api.github.com/repos/jashkenas/underscore/stargazers","contributors_url":"https://api.github.com/repos/jashkenas/underscore/contributors","subscribers_url":"https://api.github.com/repos/jashkenas/underscore/subscribers","subscription_url":"https://api.github.com/repos/jashkenas/underscore/subscription","commits_url":"https://api.github.com/repos/jashkenas/underscore/commits{/sha}","git_commits_url":"https://api.github.com/repos/jashkenas/underscore/git/commits{/sha}","comments_url":"https://api.github.com/repos/jashkenas/underscore/comments{/number}","issue_comment_url":"https://api.github.com/repos/jashkenas/underscore/issues/comments/{number}","contents_url":"https://api.github.com/repos/jashkenas/underscore/contents/{+path}","compare_url":"https://api.github.com/repos/jashkenas/underscore/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jashkenas/underscore/merges","archive_url":"https://api.github.com/repos/jashkenas/underscore/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jashkenas/underscore/downloads","issues_url":"https://api.github.com/repos/jashkenas/underscore/issues{/number}","pulls_url":"https://api.github.com/repos/jashkenas/underscore/pulls{/number}","milestones_url":"https://api.github.com/repos/jashkenas/underscore/milestones{/number}","notifications_url":"https://api.github.com/repos/jashkenas/underscore/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jashkenas/underscore/labels{/name}","releases_url":"https://api.github.com/repos/jashkenas/underscore/releases{/id}","created_at":"2009-10-25T18:31:06Z","updated_at":"2014-06-10T18:27:41Z","pushed_at":"2014-06-10T15:38:40Z","git_url":"git://github.com/jashkenas/underscore.git","ssh_url":"git@github.com:jashkenas/underscore.git","clone_url":"https://github.com/jashkenas/underscore.git","svn_url":"https://github.com/jashkenas/underscore","homepage":"http://underscorejs.org","size":15009,"stargazers_count":11528,"watchers_count":11528,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":2465,"mirror_url":null,"open_issues_count":41,"forks":2465,"open_issues":41,"watchers":11528,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jashkenas/underscore/pulls/1628"},"html":{"href":"https://github.com/jashkenas/underscore/pull/1628"},"issue":{"href":"https://api.github.com/repos/jashkenas/underscore/issues/1628"},"comments":{"href":"https://api.github.com/repos/jashkenas/underscore/issues/1628/comments"},"review_comments":{"href":"https://api.github.com/repos/jashkenas/underscore/pulls/1628/comments"},"review_comment":{"href":"https://api.github.com/repos/jashkenas/underscore/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/jashkenas/underscore/pulls/1628/commits"},"statuses":{"href":"https://api.github.com/repos/jashkenas/underscore/statuses/4ccfc99b8ab6ded40cbf8742c04ac8fc4a2d3b85"}}}}