{"action":"created","comment":{"url":"https://api.github.com/repos/WICG/IntersectionObserver/pulls/comments/56570141","id":56570141,"diff_hunk":"@@ -0,0 +1,188 @@\n+(function() {\n+  // TODO: rootMargin are completely ignored for now\n+  \n+  // Constructor\n+  window.IntersectionObserver = function(callback, options) {\n+    options = options || {};\n+    \n+    if(!(callback instanceof Function)) {\n+      throw('callback needs to be a function');\n+    }\n+    \n+    this._callback = callback;\n+    this._root = options.root || null;\n+    this._rootMargin = options.rootMargin || [0, 0, 0, 0];\n+    this._thresholds = options.threshold || 0;\n+    this._init();\n+  };\n+\n+  window.IntersectionObserver.prototype = {\n+    //\n+    // Public API\n+    //\n+    get root() {\n+      return this._root || document;\n+    },\n+    \n+    get rootMargin() {\n+      return '0';\n+    },\n+    \n+    get thresholds() {\n+      // 0 means call callback on every change\n+      // See note at http://rawgit.com/WICG/IntersectionObserver/master/index.html#intersection-observer-init\n+      if(this._thresholds === 0) {\n+        return 0;\n+      }\n+      if(this._thresholds instanceof Array) {\n+        return this._thresholds;\n+      }\n+      return [this._thresholds];\n+    },\n+    \n+    observe: function(target) {\n+      if(!(target instanceof HTMLElement)) {\n+        throw('Target needs to be an HTMLelement');\n+      }\n+      \n+      var root = this.root;\n+      var ancestor = target.parentNode;\n+      while (ancestor != root) {\n+        if (!ancestor) {\n+          throw('Target must be decendant of root');\n+        }\n+        ancestor = ancestor.parentNode;   \n+      }\n+      \n+      this._observationTargets.set(target, {});\n+    },\n+    \n+    unobserve: function(target) {\n+      this._observationTargets.delete(target);\n+    },\n+    \n+    disconnect: function() {\n+      this._observationTargets.clear();\n+      this.root.removeEventListener('scroll', this._boundUpdate);\n+      window.clearInterval(this._timeoutId);\n+      this._descheduleCallback();\n+    },\n+    \n+    takeRecords: function() {\n+      this._update();\n+      this._descheduleCallback();\n+      var copy = this._queue.slice();\n+      this._queue = [];\n+      return copy;\n+    },\n+    \n+    //\n+    // Private API\n+    //\n+    _init: function() {\n+      this._observationTargets = new Map();\n+      this._boundUpdate = this._update.bind(this);\n+      this.root.addEventListener('scroll', this._boundUpdate);\n+      this._intervalId = window.setInterval(this._boundUpdate, 100);","path":"polyfill/intersectionobserver-polyfill.js","position":86,"original_position":86,"commit_id":"e69581f26277d589221ea019bda42f2c61ba612c","original_commit_id":"e69581f26277d589221ea019bda42f2c61ba612c","user":{"login":"surma","id":234957,"avatar_url":"https://avatars.githubusercontent.com/u/234957?v=3","gravatar_id":"","url":"https://api.github.com/users/surma","html_url":"https://github.com/surma","followers_url":"https://api.github.com/users/surma/followers","following_url":"https://api.github.com/users/surma/following{/other_user}","gists_url":"https://api.github.com/users/surma/gists{/gist_id}","starred_url":"https://api.github.com/users/surma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/surma/subscriptions","organizations_url":"https://api.github.com/users/surma/orgs","repos_url":"https://api.github.com/users/surma/repos","events_url":"https://api.github.com/users/surma/events{/privacy}","received_events_url":"https://api.github.com/users/surma/received_events","type":"User","site_admin":false},"body":"So, I agree that the polling and the scroll-events overlap. I can do something about that.\r\n\r\nHowever, I am not sure about rate-limiting the updates to 100ms in general. If you want to use this data in animation, you ideally get an update from the IntersectionObserver every frame, right? Or did I miss something in the spec about this? I was thinking to use `requestAnimationFrame()` so you get frame-by-frame updates in the polyfill. ","created_at":"2016-03-17T20:14:51Z","updated_at":"2016-03-17T20:14:51Z","html_url":"https://github.com/WICG/IntersectionObserver/pull/116#discussion_r56570141","pull_request_url":"https://api.github.com/repos/WICG/IntersectionObserver/pulls/116","_links":{"self":{"href":"https://api.github.com/repos/WICG/IntersectionObserver/pulls/comments/56570141"},"html":{"href":"https://github.com/WICG/IntersectionObserver/pull/116#discussion_r56570141"},"pull_request":{"href":"https://api.github.com/repos/WICG/IntersectionObserver/pulls/116"}}},"pull_request":{"url":"https://api.github.com/repos/WICG/IntersectionObserver/pulls/116","id":63070230,"html_url":"https://github.com/WICG/IntersectionObserver/pull/116","diff_url":"https://github.com/WICG/IntersectionObserver/pull/116.diff","patch_url":"https://github.com/WICG/IntersectionObserver/pull/116.patch","issue_url":"https://api.github.com/repos/WICG/IntersectionObserver/issues/116","number":116,"state":"open","locked":false,"title":"Add IntersectionObserver polyfill","user":{"login":"surma","id":234957,"avatar_url":"https://avatars.githubusercontent.com/u/234957?v=3","gravatar_id":"","url":"https://api.github.com/users/surma","html_url":"https://github.com/surma","followers_url":"https://api.github.com/users/surma/followers","following_url":"https://api.github.com/users/surma/following{/other_user}","gists_url":"https://api.github.com/users/surma/gists{/gist_id}","starred_url":"https://api.github.com/users/surma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/surma/subscriptions","organizations_url":"https://api.github.com/users/surma/orgs","repos_url":"https://api.github.com/users/surma/repos","events_url":"https://api.github.com/users/surma/events{/privacy}","received_events_url":"https://api.github.com/users/surma/received_events","type":"User","site_admin":false},"body":"r: @ojanvafai \r\ncc: @ianvollick @paullewis @flackr\r\n\r\nThis adds a polyfill for the IntersectionObserver API. It is compatible to the current version of the spec but ignores margins for now, as I wanted to avoid implementing a CSS string parser.\r\n\r\nThere’s also a simple test suite by @ojanvafai. All tests pass except for the margin tests for the reasons mentioned above. Please take a look at the tests to check that the polyfill is behaving as you’d expect.\r\n![screenshot 2016-03-16 14 05 35](https://cloud.githubusercontent.com/assets/234957/13814970/9537797a-eb80-11e5-8356-627bf13b55be.png)\r\n\r\nAny other feedback obviously welcome as well :)\r\n","created_at":"2016-03-16T14:10:50Z","updated_at":"2016-03-17T20:14:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f90df19f967589feeb64d5f72effa20ce2258935","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/WICG/IntersectionObserver/pulls/116/commits","review_comments_url":"https://api.github.com/repos/WICG/IntersectionObserver/pulls/116/comments","review_comment_url":"https://api.github.com/repos/WICG/IntersectionObserver/pulls/comments{/number}","comments_url":"https://api.github.com/repos/WICG/IntersectionObserver/issues/116/comments","statuses_url":"https://api.github.com/repos/WICG/IntersectionObserver/statuses/e69581f26277d589221ea019bda42f2c61ba612c","head":{"label":"surma-dump:polyfill","ref":"polyfill","sha":"e69581f26277d589221ea019bda42f2c61ba612c","user":{"login":"surma-dump","id":1838196,"avatar_url":"https://avatars.githubusercontent.com/u/1838196?v=3","gravatar_id":"","url":"https://api.github.com/users/surma-dump","html_url":"https://github.com/surma-dump","followers_url":"https://api.github.com/users/surma-dump/followers","following_url":"https://api.github.com/users/surma-dump/following{/other_user}","gists_url":"https://api.github.com/users/surma-dump/gists{/gist_id}","starred_url":"https://api.github.com/users/surma-dump/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/surma-dump/subscriptions","organizations_url":"https://api.github.com/users/surma-dump/orgs","repos_url":"https://api.github.com/users/surma-dump/repos","events_url":"https://api.github.com/users/surma-dump/events{/privacy}","received_events_url":"https://api.github.com/users/surma-dump/received_events","type":"Organization","site_admin":false},"repo":{"id":54037024,"name":"IntersectionObserver","full_name":"surma-dump/IntersectionObserver","owner":{"login":"surma-dump","id":1838196,"avatar_url":"https://avatars.githubusercontent.com/u/1838196?v=3","gravatar_id":"","url":"https://api.github.com/users/surma-dump","html_url":"https://github.com/surma-dump","followers_url":"https://api.github.com/users/surma-dump/followers","following_url":"https://api.github.com/users/surma-dump/following{/other_user}","gists_url":"https://api.github.com/users/surma-dump/gists{/gist_id}","starred_url":"https://api.github.com/users/surma-dump/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/surma-dump/subscriptions","organizations_url":"https://api.github.com/users/surma-dump/orgs","repos_url":"https://api.github.com/users/surma-dump/repos","events_url":"https://api.github.com/users/surma-dump/events{/privacy}","received_events_url":"https://api.github.com/users/surma-dump/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/surma-dump/IntersectionObserver","description":"API Sketch for Intersection Observers","fork":true,"url":"https://api.github.com/repos/surma-dump/IntersectionObserver","forks_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/forks","keys_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/teams","hooks_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/hooks","issue_events_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/issues/events{/number}","events_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/events","assignees_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/assignees{/user}","branches_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/branches{/branch}","tags_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/tags","blobs_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/git/refs{/sha}","trees_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/statuses/{sha}","languages_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/languages","stargazers_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/stargazers","contributors_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/contributors","subscribers_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/subscribers","subscription_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/subscription","commits_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/commits{/sha}","git_commits_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/git/commits{/sha}","comments_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/comments{/number}","issue_comment_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/issues/comments{/number}","contents_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/contents/{+path}","compare_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/merges","archive_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/downloads","issues_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/issues{/number}","pulls_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/pulls{/number}","milestones_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/milestones{/number}","notifications_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/labels{/name}","releases_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/releases{/id}","deployments_url":"https://api.github.com/repos/surma-dump/IntersectionObserver/deployments","created_at":"2016-03-16T14:06:08Z","updated_at":"2016-03-16T14:06:09Z","pushed_at":"2016-03-16T14:06:54Z","git_url":"git://github.com/surma-dump/IntersectionObserver.git","ssh_url":"git@github.com:surma-dump/IntersectionObserver.git","clone_url":"https://github.com/surma-dump/IntersectionObserver.git","svn_url":"https://github.com/surma-dump/IntersectionObserver","homepage":"","size":253,"stargazers_count":0,"watchers_count":0,"language":"HTML","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":"WICG:master","ref":"master","sha":"0c10deb4a1d35bac322ecf735350af8522499d8f","user":{"login":"WICG","id":13145324,"avatar_url":"https://avatars.githubusercontent.com/u/13145324?v=3","gravatar_id":"","url":"https://api.github.com/users/WICG","html_url":"https://github.com/WICG","followers_url":"https://api.github.com/users/WICG/followers","following_url":"https://api.github.com/users/WICG/following{/other_user}","gists_url":"https://api.github.com/users/WICG/gists{/gist_id}","starred_url":"https://api.github.com/users/WICG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WICG/subscriptions","organizations_url":"https://api.github.com/users/WICG/orgs","repos_url":"https://api.github.com/users/WICG/repos","events_url":"https://api.github.com/users/WICG/events{/privacy}","received_events_url":"https://api.github.com/users/WICG/received_events","type":"Organization","site_admin":false},"repo":{"id":37750203,"name":"IntersectionObserver","full_name":"WICG/IntersectionObserver","owner":{"login":"WICG","id":13145324,"avatar_url":"https://avatars.githubusercontent.com/u/13145324?v=3","gravatar_id":"","url":"https://api.github.com/users/WICG","html_url":"https://github.com/WICG","followers_url":"https://api.github.com/users/WICG/followers","following_url":"https://api.github.com/users/WICG/following{/other_user}","gists_url":"https://api.github.com/users/WICG/gists{/gist_id}","starred_url":"https://api.github.com/users/WICG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WICG/subscriptions","organizations_url":"https://api.github.com/users/WICG/orgs","repos_url":"https://api.github.com/users/WICG/repos","events_url":"https://api.github.com/users/WICG/events{/privacy}","received_events_url":"https://api.github.com/users/WICG/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/WICG/IntersectionObserver","description":"API Sketch for Intersection Observers","fork":false,"url":"https://api.github.com/repos/WICG/IntersectionObserver","forks_url":"https://api.github.com/repos/WICG/IntersectionObserver/forks","keys_url":"https://api.github.com/repos/WICG/IntersectionObserver/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WICG/IntersectionObserver/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WICG/IntersectionObserver/teams","hooks_url":"https://api.github.com/repos/WICG/IntersectionObserver/hooks","issue_events_url":"https://api.github.com/repos/WICG/IntersectionObserver/issues/events{/number}","events_url":"https://api.github.com/repos/WICG/IntersectionObserver/events","assignees_url":"https://api.github.com/repos/WICG/IntersectionObserver/assignees{/user}","branches_url":"https://api.github.com/repos/WICG/IntersectionObserver/branches{/branch}","tags_url":"https://api.github.com/repos/WICG/IntersectionObserver/tags","blobs_url":"https://api.github.com/repos/WICG/IntersectionObserver/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WICG/IntersectionObserver/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WICG/IntersectionObserver/git/refs{/sha}","trees_url":"https://api.github.com/repos/WICG/IntersectionObserver/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WICG/IntersectionObserver/statuses/{sha}","languages_url":"https://api.github.com/repos/WICG/IntersectionObserver/languages","stargazers_url":"https://api.github.com/repos/WICG/IntersectionObserver/stargazers","contributors_url":"https://api.github.com/repos/WICG/IntersectionObserver/contributors","subscribers_url":"https://api.github.com/repos/WICG/IntersectionObserver/subscribers","subscription_url":"https://api.github.com/repos/WICG/IntersectionObserver/subscription","commits_url":"https://api.github.com/repos/WICG/IntersectionObserver/commits{/sha}","git_commits_url":"https://api.github.com/repos/WICG/IntersectionObserver/git/commits{/sha}","comments_url":"https://api.github.com/repos/WICG/IntersectionObserver/comments{/number}","issue_comment_url":"https://api.github.com/repos/WICG/IntersectionObserver/issues/comments{/number}","contents_url":"https://api.github.com/repos/WICG/IntersectionObserver/contents/{+path}","compare_url":"https://api.github.com/repos/WICG/IntersectionObserver/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WICG/IntersectionObserver/merges","archive_url":"https://api.github.com/repos/WICG/IntersectionObserver/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WICG/IntersectionObserver/downloads","issues_url":"https://api.github.com/repos/WICG/IntersectionObserver/issues{/number}","pulls_url":"https://api.github.com/repos/WICG/IntersectionObserver/pulls{/number}","milestones_url":"https://api.github.com/repos/WICG/IntersectionObserver/milestones{/number}","notifications_url":"https://api.github.com/repos/WICG/IntersectionObserver/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WICG/IntersectionObserver/labels{/name}","releases_url":"https://api.github.com/repos/WICG/IntersectionObserver/releases{/id}","deployments_url":"https://api.github.com/repos/WICG/IntersectionObserver/deployments","created_at":"2015-06-19T23:12:24Z","updated_at":"2016-03-17T05:00:13Z","pushed_at":"2016-03-17T04:17:58Z","git_url":"git://github.com/WICG/IntersectionObserver.git","ssh_url":"git@github.com:WICG/IntersectionObserver.git","clone_url":"https://github.com/WICG/IntersectionObserver.git","svn_url":"https://github.com/WICG/IntersectionObserver","homepage":"","size":347,"stargazers_count":48,"watchers_count":48,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":13,"forks":13,"open_issues":13,"watchers":48,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/WICG/IntersectionObserver/pulls/116"},"html":{"href":"https://github.com/WICG/IntersectionObserver/pull/116"},"issue":{"href":"https://api.github.com/repos/WICG/IntersectionObserver/issues/116"},"comments":{"href":"https://api.github.com/repos/WICG/IntersectionObserver/issues/116/comments"},"review_comments":{"href":"https://api.github.com/repos/WICG/IntersectionObserver/pulls/116/comments"},"review_comment":{"href":"https://api.github.com/repos/WICG/IntersectionObserver/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/WICG/IntersectionObserver/pulls/116/commits"},"statuses":{"href":"https://api.github.com/repos/WICG/IntersectionObserver/statuses/e69581f26277d589221ea019bda42f2c61ba612c"}}}}