{"action":"created","comment":{"url":"https://api.github.com/repos/turingschool-examples/birdeck/pulls/comments/57241288","id":57241288,"diff_hunk":"@@ -17,32 +22,34 @@ function renderPost(post) {\n     + \"</p>\"\n     + \"<button id='delete-post' name='button-fetch' class='btn btn-default btn-xs'>Delete</button>\"\n     + \"</div>\"\n-    )\n+  )\n+}\n+\n+function renderPosts(posts) {\n+  return posts.map(renderPost)\n+}\n+\n+function addPostToPage(post) {\n+  $latestPosts.append(post);\n+}\n+\n+function addPostsToPage(posts) {\n+  $latestPosts.html(posts)\n+}\n+\n+function handleError(xhr) {\n+  console.log(xhr.responseText)\n }\n \n function fetchPostsButton() {\n-  $(\"#button-fetch-posts\").on(\"click\", function(){\n-    fetchPosts()\n-    })\n+  $(\"#button-fetch-posts\").on(\"click\", fetchPosts)\n }\n \n function fetchPosts() {\n-  var newestItemID = parseInt($(\".post\").last().attr(\"data-id\"))\n-\n-  $.ajax({\n-    type:    \"GET\",\n-    url:     \"https://turing-birdie.herokuapp.com/api/v1/posts.json\",\n-    success: function(posts) {\n-      $.each(posts, function(index, post) {\n-        if (isNaN(newestItemID) || post.id > newestItemID) {\n-          renderPost(post)\n-        }\n-      })\n-    },\n-    error: function(xhr) {\n-      console.log(xhr.responseText)\n-    }\n-  })\n+  $.getJSON(\"https://turing-birdie.herokuapp.com/api/v1/posts.json\")","path":"assets/javascripts/birdeck.js","position":67,"original_position":67,"commit_id":"2699339737c8c5a28833ac9963de6f4ed45a43f2","original_commit_id":"2699339737c8c5a28833ac9963de6f4ed45a43f2","user":{"login":"stevekinney","id":251000,"avatar_url":"https://avatars.githubusercontent.com/u/251000?v=3","gravatar_id":"","url":"https://api.github.com/users/stevekinney","html_url":"https://github.com/stevekinney","followers_url":"https://api.github.com/users/stevekinney/followers","following_url":"https://api.github.com/users/stevekinney/following{/other_user}","gists_url":"https://api.github.com/users/stevekinney/gists{/gist_id}","starred_url":"https://api.github.com/users/stevekinney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevekinney/subscriptions","organizations_url":"https://api.github.com/users/stevekinney/orgs","repos_url":"https://api.github.com/users/stevekinney/repos","events_url":"https://api.github.com/users/stevekinney/events{/privacy}","received_events_url":"https://api.github.com/users/stevekinney/received_events","type":"User","site_admin":false},"body":"@novohispano Cool, let's have them use `.each` exclusively in Ruby as well. Let's also only have them write `.find_by_sql` statements in ActiveRecord too. As it stands, we're having them use a pattern that _no one_ uses and it's not adding to their understanding of anything they come into Module 4.","created_at":"2016-03-23T21:34:54Z","updated_at":"2016-03-23T21:34:54Z","html_url":"https://github.com/turingschool-examples/birdeck/pull/2#discussion_r57241288","pull_request_url":"https://api.github.com/repos/turingschool-examples/birdeck/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/turingschool-examples/birdeck/pulls/comments/57241288"},"html":{"href":"https://github.com/turingschool-examples/birdeck/pull/2#discussion_r57241288"},"pull_request":{"href":"https://api.github.com/repos/turingschool-examples/birdeck/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/turingschool-examples/birdeck/pulls/2","id":63944882,"html_url":"https://github.com/turingschool-examples/birdeck/pull/2","diff_url":"https://github.com/turingschool-examples/birdeck/pull/2.diff","patch_url":"https://github.com/turingschool-examples/birdeck/pull/2.patch","issue_url":"https://api.github.com/repos/turingschool-examples/birdeck/issues/2","number":2,"state":"open","locked":false,"title":"Refactor the end result","user":{"login":"stevekinney","id":251000,"avatar_url":"https://avatars.githubusercontent.com/u/251000?v=3","gravatar_id":"","url":"https://api.github.com/users/stevekinney","html_url":"https://github.com/stevekinney","followers_url":"https://api.github.com/users/stevekinney/followers","following_url":"https://api.github.com/users/stevekinney/following{/other_user}","gists_url":"https://api.github.com/users/stevekinney/gists{/gist_id}","starred_url":"https://api.github.com/users/stevekinney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevekinney/subscriptions","organizations_url":"https://api.github.com/users/stevekinney/orgs","repos_url":"https://api.github.com/users/stevekinney/repos","events_url":"https://api.github.com/users/stevekinney/events{/privacy}","received_events_url":"https://api.github.com/users/stevekinney/received_events","type":"User","site_admin":false},"body":"@jmejia @novohispano \n\nBird Deck seems to be the reference of choice for implementing Ideabox 2.0 in Module 4. For the most part, it’s great. Students come in better and more adept at AJAX and jQuery than they did previously.\n\nThat said, there are some anti-patterns. Most notably, the method that fetches all of the ideas and then does some squirrelly comparison to see if they’re already on the page.\n\nThis isn’t particularly performant. We’re iterating through the ideas and doing some computation and then modifying the DOM _n_ times.\n\nIt’s kind of like an _n + 1_ query in ActiveRecord. The browser has to repaint and see if any of the layout has changed every single time we make a modification to it. It’s way better just to pop them all in there at once.\n\nThere was also some use of jQuery’s `each` method on plain old arrays that already support their own `forEach` method.\n\nI also cached selectors that we use multiple times so that we don’t have to keep querying the DOM for them.\n\nI DRY’d up error handling.\n\nThe controversial part: I moved from the low-level `$.ajax` calls to higher level abstractions. `$.ajax` is literally filed under “Low-Level Interface” in [the jQuery documentation](https://api.jquery.com/jquery.ajax/).\n\nAccording to the documentation:\n\n> The `$.ajax()` function underlies all Ajax requests sent by jQuery. It is often unnecessary to directly call this function, as several higher-level alternatives like `$.get()` and `.load()` are available and are easier to use.\n\nI also took advantage of jQuery [Deferreds](https://api.jquery.com/jquery.deferred/). Effectively, these are promises. These allowed me to break up the rendering posts and adding them to the page into two distinct functions with a single responsibility.","created_at":"2016-03-23T20:09:50Z","updated_at":"2016-03-23T21:34:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"295900b5d928fd3988afd567989fecf9084888cd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/turingschool-examples/birdeck/pulls/2/commits","review_comments_url":"https://api.github.com/repos/turingschool-examples/birdeck/pulls/2/comments","review_comment_url":"https://api.github.com/repos/turingschool-examples/birdeck/pulls/comments{/number}","comments_url":"https://api.github.com/repos/turingschool-examples/birdeck/issues/2/comments","statuses_url":"https://api.github.com/repos/turingschool-examples/birdeck/statuses/2699339737c8c5a28833ac9963de6f4ed45a43f2","head":{"label":"turingschool-examples:more-better","ref":"more-better","sha":"2699339737c8c5a28833ac9963de6f4ed45a43f2","user":{"login":"turingschool-examples","id":8518346,"avatar_url":"https://avatars.githubusercontent.com/u/8518346?v=3","gravatar_id":"","url":"https://api.github.com/users/turingschool-examples","html_url":"https://github.com/turingschool-examples","followers_url":"https://api.github.com/users/turingschool-examples/followers","following_url":"https://api.github.com/users/turingschool-examples/following{/other_user}","gists_url":"https://api.github.com/users/turingschool-examples/gists{/gist_id}","starred_url":"https://api.github.com/users/turingschool-examples/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/turingschool-examples/subscriptions","organizations_url":"https://api.github.com/users/turingschool-examples/orgs","repos_url":"https://api.github.com/users/turingschool-examples/repos","events_url":"https://api.github.com/users/turingschool-examples/events{/privacy}","received_events_url":"https://api.github.com/users/turingschool-examples/received_events","type":"Organization","site_admin":false},"repo":{"id":37589978,"name":"birdeck","full_name":"turingschool-examples/birdeck","owner":{"login":"turingschool-examples","id":8518346,"avatar_url":"https://avatars.githubusercontent.com/u/8518346?v=3","gravatar_id":"","url":"https://api.github.com/users/turingschool-examples","html_url":"https://github.com/turingschool-examples","followers_url":"https://api.github.com/users/turingschool-examples/followers","following_url":"https://api.github.com/users/turingschool-examples/following{/other_user}","gists_url":"https://api.github.com/users/turingschool-examples/gists{/gist_id}","starred_url":"https://api.github.com/users/turingschool-examples/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/turingschool-examples/subscriptions","organizations_url":"https://api.github.com/users/turingschool-examples/orgs","repos_url":"https://api.github.com/users/turingschool-examples/repos","events_url":"https://api.github.com/users/turingschool-examples/events{/privacy}","received_events_url":"https://api.github.com/users/turingschool-examples/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/turingschool-examples/birdeck","description":"An example app to teach about AJAX.","fork":false,"url":"https://api.github.com/repos/turingschool-examples/birdeck","forks_url":"https://api.github.com/repos/turingschool-examples/birdeck/forks","keys_url":"https://api.github.com/repos/turingschool-examples/birdeck/keys{/key_id}","collaborators_url":"https://api.github.com/repos/turingschool-examples/birdeck/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/turingschool-examples/birdeck/teams","hooks_url":"https://api.github.com/repos/turingschool-examples/birdeck/hooks","issue_events_url":"https://api.github.com/repos/turingschool-examples/birdeck/issues/events{/number}","events_url":"https://api.github.com/repos/turingschool-examples/birdeck/events","assignees_url":"https://api.github.com/repos/turingschool-examples/birdeck/assignees{/user}","branches_url":"https://api.github.com/repos/turingschool-examples/birdeck/branches{/branch}","tags_url":"https://api.github.com/repos/turingschool-examples/birdeck/tags","blobs_url":"https://api.github.com/repos/turingschool-examples/birdeck/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/turingschool-examples/birdeck/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/turingschool-examples/birdeck/git/refs{/sha}","trees_url":"https://api.github.com/repos/turingschool-examples/birdeck/git/trees{/sha}","statuses_url":"https://api.github.com/repos/turingschool-examples/birdeck/statuses/{sha}","languages_url":"https://api.github.com/repos/turingschool-examples/birdeck/languages","stargazers_url":"https://api.github.com/repos/turingschool-examples/birdeck/stargazers","contributors_url":"https://api.github.com/repos/turingschool-examples/birdeck/contributors","subscribers_url":"https://api.github.com/repos/turingschool-examples/birdeck/subscribers","subscription_url":"https://api.github.com/repos/turingschool-examples/birdeck/subscription","commits_url":"https://api.github.com/repos/turingschool-examples/birdeck/commits{/sha}","git_commits_url":"https://api.github.com/repos/turingschool-examples/birdeck/git/commits{/sha}","comments_url":"https://api.github.com/repos/turingschool-examples/birdeck/comments{/number}","issue_comment_url":"https://api.github.com/repos/turingschool-examples/birdeck/issues/comments{/number}","contents_url":"https://api.github.com/repos/turingschool-examples/birdeck/contents/{+path}","compare_url":"https://api.github.com/repos/turingschool-examples/birdeck/compare/{base}...{head}","merges_url":"https://api.github.com/repos/turingschool-examples/birdeck/merges","archive_url":"https://api.github.com/repos/turingschool-examples/birdeck/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/turingschool-examples/birdeck/downloads","issues_url":"https://api.github.com/repos/turingschool-examples/birdeck/issues{/number}","pulls_url":"https://api.github.com/repos/turingschool-examples/birdeck/pulls{/number}","milestones_url":"https://api.github.com/repos/turingschool-examples/birdeck/milestones{/number}","notifications_url":"https://api.github.com/repos/turingschool-examples/birdeck/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/turingschool-examples/birdeck/labels{/name}","releases_url":"https://api.github.com/repos/turingschool-examples/birdeck/releases{/id}","deployments_url":"https://api.github.com/repos/turingschool-examples/birdeck/deployments","created_at":"2015-06-17T11:04:41Z","updated_at":"2016-03-23T21:26:55Z","pushed_at":"2016-03-23T20:09:50Z","git_url":"git://github.com/turingschool-examples/birdeck.git","ssh_url":"git@github.com:turingschool-examples/birdeck.git","clone_url":"https://github.com/turingschool-examples/birdeck.git","svn_url":"https://github.com/turingschool-examples/birdeck","homepage":null,"size":12,"stargazers_count":1,"watchers_count":1,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"turingschool-examples:polling","ref":"polling","sha":"1af6d8dcd80c385530340882e1ae2ff87d23fcf2","user":{"login":"turingschool-examples","id":8518346,"avatar_url":"https://avatars.githubusercontent.com/u/8518346?v=3","gravatar_id":"","url":"https://api.github.com/users/turingschool-examples","html_url":"https://github.com/turingschool-examples","followers_url":"https://api.github.com/users/turingschool-examples/followers","following_url":"https://api.github.com/users/turingschool-examples/following{/other_user}","gists_url":"https://api.github.com/users/turingschool-examples/gists{/gist_id}","starred_url":"https://api.github.com/users/turingschool-examples/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/turingschool-examples/subscriptions","organizations_url":"https://api.github.com/users/turingschool-examples/orgs","repos_url":"https://api.github.com/users/turingschool-examples/repos","events_url":"https://api.github.com/users/turingschool-examples/events{/privacy}","received_events_url":"https://api.github.com/users/turingschool-examples/received_events","type":"Organization","site_admin":false},"repo":{"id":37589978,"name":"birdeck","full_name":"turingschool-examples/birdeck","owner":{"login":"turingschool-examples","id":8518346,"avatar_url":"https://avatars.githubusercontent.com/u/8518346?v=3","gravatar_id":"","url":"https://api.github.com/users/turingschool-examples","html_url":"https://github.com/turingschool-examples","followers_url":"https://api.github.com/users/turingschool-examples/followers","following_url":"https://api.github.com/users/turingschool-examples/following{/other_user}","gists_url":"https://api.github.com/users/turingschool-examples/gists{/gist_id}","starred_url":"https://api.github.com/users/turingschool-examples/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/turingschool-examples/subscriptions","organizations_url":"https://api.github.com/users/turingschool-examples/orgs","repos_url":"https://api.github.com/users/turingschool-examples/repos","events_url":"https://api.github.com/users/turingschool-examples/events{/privacy}","received_events_url":"https://api.github.com/users/turingschool-examples/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/turingschool-examples/birdeck","description":"An example app to teach about AJAX.","fork":false,"url":"https://api.github.com/repos/turingschool-examples/birdeck","forks_url":"https://api.github.com/repos/turingschool-examples/birdeck/forks","keys_url":"https://api.github.com/repos/turingschool-examples/birdeck/keys{/key_id}","collaborators_url":"https://api.github.com/repos/turingschool-examples/birdeck/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/turingschool-examples/birdeck/teams","hooks_url":"https://api.github.com/repos/turingschool-examples/birdeck/hooks","issue_events_url":"https://api.github.com/repos/turingschool-examples/birdeck/issues/events{/number}","events_url":"https://api.github.com/repos/turingschool-examples/birdeck/events","assignees_url":"https://api.github.com/repos/turingschool-examples/birdeck/assignees{/user}","branches_url":"https://api.github.com/repos/turingschool-examples/birdeck/branches{/branch}","tags_url":"https://api.github.com/repos/turingschool-examples/birdeck/tags","blobs_url":"https://api.github.com/repos/turingschool-examples/birdeck/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/turingschool-examples/birdeck/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/turingschool-examples/birdeck/git/refs{/sha}","trees_url":"https://api.github.com/repos/turingschool-examples/birdeck/git/trees{/sha}","statuses_url":"https://api.github.com/repos/turingschool-examples/birdeck/statuses/{sha}","languages_url":"https://api.github.com/repos/turingschool-examples/birdeck/languages","stargazers_url":"https://api.github.com/repos/turingschool-examples/birdeck/stargazers","contributors_url":"https://api.github.com/repos/turingschool-examples/birdeck/contributors","subscribers_url":"https://api.github.com/repos/turingschool-examples/birdeck/subscribers","subscription_url":"https://api.github.com/repos/turingschool-examples/birdeck/subscription","commits_url":"https://api.github.com/repos/turingschool-examples/birdeck/commits{/sha}","git_commits_url":"https://api.github.com/repos/turingschool-examples/birdeck/git/commits{/sha}","comments_url":"https://api.github.com/repos/turingschool-examples/birdeck/comments{/number}","issue_comment_url":"https://api.github.com/repos/turingschool-examples/birdeck/issues/comments{/number}","contents_url":"https://api.github.com/repos/turingschool-examples/birdeck/contents/{+path}","compare_url":"https://api.github.com/repos/turingschool-examples/birdeck/compare/{base}...{head}","merges_url":"https://api.github.com/repos/turingschool-examples/birdeck/merges","archive_url":"https://api.github.com/repos/turingschool-examples/birdeck/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/turingschool-examples/birdeck/downloads","issues_url":"https://api.github.com/repos/turingschool-examples/birdeck/issues{/number}","pulls_url":"https://api.github.com/repos/turingschool-examples/birdeck/pulls{/number}","milestones_url":"https://api.github.com/repos/turingschool-examples/birdeck/milestones{/number}","notifications_url":"https://api.github.com/repos/turingschool-examples/birdeck/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/turingschool-examples/birdeck/labels{/name}","releases_url":"https://api.github.com/repos/turingschool-examples/birdeck/releases{/id}","deployments_url":"https://api.github.com/repos/turingschool-examples/birdeck/deployments","created_at":"2015-06-17T11:04:41Z","updated_at":"2016-03-23T21:26:55Z","pushed_at":"2016-03-23T20:09:50Z","git_url":"git://github.com/turingschool-examples/birdeck.git","ssh_url":"git@github.com:turingschool-examples/birdeck.git","clone_url":"https://github.com/turingschool-examples/birdeck.git","svn_url":"https://github.com/turingschool-examples/birdeck","homepage":null,"size":12,"stargazers_count":1,"watchers_count":1,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/turingschool-examples/birdeck/pulls/2"},"html":{"href":"https://github.com/turingschool-examples/birdeck/pull/2"},"issue":{"href":"https://api.github.com/repos/turingschool-examples/birdeck/issues/2"},"comments":{"href":"https://api.github.com/repos/turingschool-examples/birdeck/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/turingschool-examples/birdeck/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/turingschool-examples/birdeck/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/turingschool-examples/birdeck/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/turingschool-examples/birdeck/statuses/2699339737c8c5a28833ac9963de6f4ed45a43f2"}}}}