{"action":"created","comment":{"url":"https://api.github.com/repos/ampproject/amphtml/pulls/comments/56418804","id":56418804,"diff_hunk":"@@ -1307,6 +1283,78 @@ export class Resources {\n       }\n     }\n   }\n+\n+  /**\n+   * Calls iterator on each sub-resource\n+   * @param {function(!Resource, number)} iterator\n+   */\n+  setupVisibilityStateMachine_(vsm) {\n+    const prerender = VisibilityState.PRERENDER;\n+    const visible = VisibilityState.VISIBLE;\n+    const hidden = VisibilityState.HIDDEN;\n+    const paused = VisibilityState.PAUSED;\n+    const inactive = VisibilityState.INACTIVE;\n+\n+    const doPass = () => {\n+      // If viewport size is 0, the manager will wait for the resize event.\n+      const viewportSize = this.viewport_.getSize();\n+      if (viewportSize.height > 0 && viewportSize.width > 0) {\n+        if (this.hasMutateWork_()) {\n+          this.mutateWork_();\n+        }\n+        this.discoverWork_();\n+        let delay = this.work_();\n+        if (this.hasMutateWork_()) {\n+          // Overflow mutate work.\n+          delay = Math.min(delay, MUTATE_DEFER_DELAY_);\n+        }\n+        if (this.visible_) {\n+          dev.fine(TAG_, 'next pass:', delay);\n+          this.schedulePass(delay);\n+          this.updateScrollHeight_();\n+        } else {\n+          dev.fine(TAG_, 'document is not visible: no scheduling');\n+        }\n+      }\n+    };\n+    const noop = () => {};\n+    const pause = () => {\n+      this.resources_.forEach(r => r.pause());\n+    };\n+    const unload = () => {\n+      this.resources_.forEach(r => r.unload());\n+    };\n+    const resume = () => {\n+      this.resources_.forEach(r => r.resume());\n+      doPass();\n+    };\n+\n+    vsm.addTransition(prerender, prerender, doPass);\n+    vsm.addTransition(prerender, visible, doPass);\n+    vsm.addTransition(prerender, hidden, doPass);\n+    vsm.addTransition(prerender, inactive, doPass);\n+    vsm.addTransition(prerender, paused, doPass);\n+\n+    vsm.addTransition(visible, visible, doPass);\n+    vsm.addTransition(visible, hidden, doPass);\n+    vsm.addTransition(visible, inactive, unload);\n+    vsm.addTransition(visible, paused, pause);\n+\n+    vsm.addTransition(hidden, visible, doPass);\n+    vsm.addTransition(hidden, hidden, doPass);\n+    vsm.addTransition(hidden, inactive, unload);\n+    vsm.addTransition(hidden, paused, pause);\n+\n+    vsm.addTransition(inactive, visible, doPass);\n+    vsm.addTransition(inactive, hidden, doPass);\n+    vsm.addTransition(inactive, inactive, noop);\n+    vsm.addTransition(inactive, paused, doPass);\n+\n+    vsm.addTransition(paused, visible, resume);\n+    vsm.addTransition(paused, hidden, doPass);\n+    vsm.addTransition(paused, inactive, unload);\n+    vsm.addTransition(paused, paused, doPass);","path":"src/service/resources-impl.js","position":248,"original_position":248,"commit_id":"171aecdc37135c45d6f494e4b5d0ae0f31de174d","original_commit_id":"171aecdc37135c45d6f494e4b5d0ae0f31de174d","user":{"login":"dvoytenko","id":726049,"avatar_url":"https://avatars.githubusercontent.com/u/726049?v=3","gravatar_id":"","url":"https://api.github.com/users/dvoytenko","html_url":"https://github.com/dvoytenko","followers_url":"https://api.github.com/users/dvoytenko/followers","following_url":"https://api.github.com/users/dvoytenko/following{/other_user}","gists_url":"https://api.github.com/users/dvoytenko/gists{/gist_id}","starred_url":"https://api.github.com/users/dvoytenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dvoytenko/subscriptions","organizations_url":"https://api.github.com/users/dvoytenko/orgs","repos_url":"https://api.github.com/users/dvoytenko/repos","events_url":"https://api.github.com/users/dvoytenko/events{/privacy}","received_events_url":"https://api.github.com/users/dvoytenko/received_events","type":"User","site_admin":false},"body":"I think this should be noop as well (paused -> paused).","created_at":"2016-03-16T21:29:20Z","updated_at":"2016-03-16T21:29:20Z","html_url":"https://github.com/ampproject/amphtml/pull/1637#discussion_r56418804","pull_request_url":"https://api.github.com/repos/ampproject/amphtml/pulls/1637","_links":{"self":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/comments/56418804"},"html":{"href":"https://github.com/ampproject/amphtml/pull/1637#discussion_r56418804"},"pull_request":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/1637"}}},"pull_request":{"url":"https://api.github.com/repos/ampproject/amphtml/pulls/1637","id":57538212,"html_url":"https://github.com/ampproject/amphtml/pull/1637","diff_url":"https://github.com/ampproject/amphtml/pull/1637.diff","patch_url":"https://github.com/ampproject/amphtml/pull/1637.patch","issue_url":"https://api.github.com/repos/ampproject/amphtml/issues/1637","number":1637,"state":"open","locked":false,"title":"Pause/Resume and Layout/Unlayout callbacks","user":{"login":"jridgewell","id":112982,"avatar_url":"https://avatars.githubusercontent.com/u/112982?v=3","gravatar_id":"","url":"https://api.github.com/users/jridgewell","html_url":"https://github.com/jridgewell","followers_url":"https://api.github.com/users/jridgewell/followers","following_url":"https://api.github.com/users/jridgewell/following{/other_user}","gists_url":"https://api.github.com/users/jridgewell/gists{/gist_id}","starred_url":"https://api.github.com/users/jridgewell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jridgewell/subscriptions","organizations_url":"https://api.github.com/users/jridgewell/orgs","repos_url":"https://api.github.com/users/jridgewell/repos","events_url":"https://api.github.com/users/jridgewell/events{/privacy}","received_events_url":"https://api.github.com/users/jridgewell/received_events","type":"User","site_admin":false},"body":"First pass at separating `pauseCallback` from `unlayoutCallback`, which adds `resumeCallback` to the mix.\r\n\r\n- [x] Setting up the state machine needs work\r\n- [x] Need integration tests on to check that doc/viewer visibility changes are detected and issue pause/resume and unlayout.\r\n\r\nFuture PRs:\r\n\r\n- Move `layoutCallback` calls into the state machine transitions\r\n- Get rid of the boolean API from `unlayoutCallback`\r\n","created_at":"2016-01-28T17:44:54Z","updated_at":"2016-03-16T21:29:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6d2d222af3757bfec16d58f291023e798c1dc579","assignee":{"login":"dvoytenko","id":726049,"avatar_url":"https://avatars.githubusercontent.com/u/726049?v=3","gravatar_id":"","url":"https://api.github.com/users/dvoytenko","html_url":"https://github.com/dvoytenko","followers_url":"https://api.github.com/users/dvoytenko/followers","following_url":"https://api.github.com/users/dvoytenko/following{/other_user}","gists_url":"https://api.github.com/users/dvoytenko/gists{/gist_id}","starred_url":"https://api.github.com/users/dvoytenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dvoytenko/subscriptions","organizations_url":"https://api.github.com/users/dvoytenko/orgs","repos_url":"https://api.github.com/users/dvoytenko/repos","events_url":"https://api.github.com/users/dvoytenko/events{/privacy}","received_events_url":"https://api.github.com/users/dvoytenko/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/ampproject/amphtml/pulls/1637/commits","review_comments_url":"https://api.github.com/repos/ampproject/amphtml/pulls/1637/comments","review_comment_url":"https://api.github.com/repos/ampproject/amphtml/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ampproject/amphtml/issues/1637/comments","statuses_url":"https://api.github.com/repos/ampproject/amphtml/statuses/171aecdc37135c45d6f494e4b5d0ae0f31de174d","head":{"label":"jridgewell:conserveResourcesCallback","ref":"conserveResourcesCallback","sha":"171aecdc37135c45d6f494e4b5d0ae0f31de174d","user":{"login":"jridgewell","id":112982,"avatar_url":"https://avatars.githubusercontent.com/u/112982?v=3","gravatar_id":"","url":"https://api.github.com/users/jridgewell","html_url":"https://github.com/jridgewell","followers_url":"https://api.github.com/users/jridgewell/followers","following_url":"https://api.github.com/users/jridgewell/following{/other_user}","gists_url":"https://api.github.com/users/jridgewell/gists{/gist_id}","starred_url":"https://api.github.com/users/jridgewell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jridgewell/subscriptions","organizations_url":"https://api.github.com/users/jridgewell/orgs","repos_url":"https://api.github.com/users/jridgewell/repos","events_url":"https://api.github.com/users/jridgewell/events{/privacy}","received_events_url":"https://api.github.com/users/jridgewell/received_events","type":"User","site_admin":false},"repo":{"id":48198933,"name":"amphtml","full_name":"jridgewell/amphtml","owner":{"login":"jridgewell","id":112982,"avatar_url":"https://avatars.githubusercontent.com/u/112982?v=3","gravatar_id":"","url":"https://api.github.com/users/jridgewell","html_url":"https://github.com/jridgewell","followers_url":"https://api.github.com/users/jridgewell/followers","following_url":"https://api.github.com/users/jridgewell/following{/other_user}","gists_url":"https://api.github.com/users/jridgewell/gists{/gist_id}","starred_url":"https://api.github.com/users/jridgewell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jridgewell/subscriptions","organizations_url":"https://api.github.com/users/jridgewell/orgs","repos_url":"https://api.github.com/users/jridgewell/repos","events_url":"https://api.github.com/users/jridgewell/events{/privacy}","received_events_url":"https://api.github.com/users/jridgewell/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jridgewell/amphtml","description":"AMP HTML source code, samples, and documentation.  See below for more info.","fork":true,"url":"https://api.github.com/repos/jridgewell/amphtml","forks_url":"https://api.github.com/repos/jridgewell/amphtml/forks","keys_url":"https://api.github.com/repos/jridgewell/amphtml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jridgewell/amphtml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jridgewell/amphtml/teams","hooks_url":"https://api.github.com/repos/jridgewell/amphtml/hooks","issue_events_url":"https://api.github.com/repos/jridgewell/amphtml/issues/events{/number}","events_url":"https://api.github.com/repos/jridgewell/amphtml/events","assignees_url":"https://api.github.com/repos/jridgewell/amphtml/assignees{/user}","branches_url":"https://api.github.com/repos/jridgewell/amphtml/branches{/branch}","tags_url":"https://api.github.com/repos/jridgewell/amphtml/tags","blobs_url":"https://api.github.com/repos/jridgewell/amphtml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jridgewell/amphtml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jridgewell/amphtml/git/refs{/sha}","trees_url":"https://api.github.com/repos/jridgewell/amphtml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jridgewell/amphtml/statuses/{sha}","languages_url":"https://api.github.com/repos/jridgewell/amphtml/languages","stargazers_url":"https://api.github.com/repos/jridgewell/amphtml/stargazers","contributors_url":"https://api.github.com/repos/jridgewell/amphtml/contributors","subscribers_url":"https://api.github.com/repos/jridgewell/amphtml/subscribers","subscription_url":"https://api.github.com/repos/jridgewell/amphtml/subscription","commits_url":"https://api.github.com/repos/jridgewell/amphtml/commits{/sha}","git_commits_url":"https://api.github.com/repos/jridgewell/amphtml/git/commits{/sha}","comments_url":"https://api.github.com/repos/jridgewell/amphtml/comments{/number}","issue_comment_url":"https://api.github.com/repos/jridgewell/amphtml/issues/comments{/number}","contents_url":"https://api.github.com/repos/jridgewell/amphtml/contents/{+path}","compare_url":"https://api.github.com/repos/jridgewell/amphtml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jridgewell/amphtml/merges","archive_url":"https://api.github.com/repos/jridgewell/amphtml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jridgewell/amphtml/downloads","issues_url":"https://api.github.com/repos/jridgewell/amphtml/issues{/number}","pulls_url":"https://api.github.com/repos/jridgewell/amphtml/pulls{/number}","milestones_url":"https://api.github.com/repos/jridgewell/amphtml/milestones{/number}","notifications_url":"https://api.github.com/repos/jridgewell/amphtml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jridgewell/amphtml/labels{/name}","releases_url":"https://api.github.com/repos/jridgewell/amphtml/releases{/id}","deployments_url":"https://api.github.com/repos/jridgewell/amphtml/deployments","created_at":"2015-12-17T21:21:35Z","updated_at":"2016-01-14T20:20:47Z","pushed_at":"2016-03-16T19:42:37Z","git_url":"git://github.com/jridgewell/amphtml.git","ssh_url":"git@github.com:jridgewell/amphtml.git","clone_url":"https://github.com/jridgewell/amphtml.git","svn_url":"https://github.com/jridgewell/amphtml","homepage":"https://ampproject.org","size":31186,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":false,"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":"ampproject:master","ref":"master","sha":"e33d632b50ac1075e0d3698dc2d369a072c36f0d","user":{"login":"ampproject","id":14114390,"avatar_url":"https://avatars.githubusercontent.com/u/14114390?v=3","gravatar_id":"","url":"https://api.github.com/users/ampproject","html_url":"https://github.com/ampproject","followers_url":"https://api.github.com/users/ampproject/followers","following_url":"https://api.github.com/users/ampproject/following{/other_user}","gists_url":"https://api.github.com/users/ampproject/gists{/gist_id}","starred_url":"https://api.github.com/users/ampproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ampproject/subscriptions","organizations_url":"https://api.github.com/users/ampproject/orgs","repos_url":"https://api.github.com/users/ampproject/repos","events_url":"https://api.github.com/users/ampproject/events{/privacy}","received_events_url":"https://api.github.com/users/ampproject/received_events","type":"Organization","site_admin":false},"repo":{"id":41766002,"name":"amphtml","full_name":"ampproject/amphtml","owner":{"login":"ampproject","id":14114390,"avatar_url":"https://avatars.githubusercontent.com/u/14114390?v=3","gravatar_id":"","url":"https://api.github.com/users/ampproject","html_url":"https://github.com/ampproject","followers_url":"https://api.github.com/users/ampproject/followers","following_url":"https://api.github.com/users/ampproject/following{/other_user}","gists_url":"https://api.github.com/users/ampproject/gists{/gist_id}","starred_url":"https://api.github.com/users/ampproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ampproject/subscriptions","organizations_url":"https://api.github.com/users/ampproject/orgs","repos_url":"https://api.github.com/users/ampproject/repos","events_url":"https://api.github.com/users/ampproject/events{/privacy}","received_events_url":"https://api.github.com/users/ampproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ampproject/amphtml","description":"AMP HTML source code, samples, and documentation.  See below for more info.","fork":false,"url":"https://api.github.com/repos/ampproject/amphtml","forks_url":"https://api.github.com/repos/ampproject/amphtml/forks","keys_url":"https://api.github.com/repos/ampproject/amphtml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ampproject/amphtml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ampproject/amphtml/teams","hooks_url":"https://api.github.com/repos/ampproject/amphtml/hooks","issue_events_url":"https://api.github.com/repos/ampproject/amphtml/issues/events{/number}","events_url":"https://api.github.com/repos/ampproject/amphtml/events","assignees_url":"https://api.github.com/repos/ampproject/amphtml/assignees{/user}","branches_url":"https://api.github.com/repos/ampproject/amphtml/branches{/branch}","tags_url":"https://api.github.com/repos/ampproject/amphtml/tags","blobs_url":"https://api.github.com/repos/ampproject/amphtml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ampproject/amphtml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ampproject/amphtml/git/refs{/sha}","trees_url":"https://api.github.com/repos/ampproject/amphtml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ampproject/amphtml/statuses/{sha}","languages_url":"https://api.github.com/repos/ampproject/amphtml/languages","stargazers_url":"https://api.github.com/repos/ampproject/amphtml/stargazers","contributors_url":"https://api.github.com/repos/ampproject/amphtml/contributors","subscribers_url":"https://api.github.com/repos/ampproject/amphtml/subscribers","subscription_url":"https://api.github.com/repos/ampproject/amphtml/subscription","commits_url":"https://api.github.com/repos/ampproject/amphtml/commits{/sha}","git_commits_url":"https://api.github.com/repos/ampproject/amphtml/git/commits{/sha}","comments_url":"https://api.github.com/repos/ampproject/amphtml/comments{/number}","issue_comment_url":"https://api.github.com/repos/ampproject/amphtml/issues/comments{/number}","contents_url":"https://api.github.com/repos/ampproject/amphtml/contents/{+path}","compare_url":"https://api.github.com/repos/ampproject/amphtml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ampproject/amphtml/merges","archive_url":"https://api.github.com/repos/ampproject/amphtml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ampproject/amphtml/downloads","issues_url":"https://api.github.com/repos/ampproject/amphtml/issues{/number}","pulls_url":"https://api.github.com/repos/ampproject/amphtml/pulls{/number}","milestones_url":"https://api.github.com/repos/ampproject/amphtml/milestones{/number}","notifications_url":"https://api.github.com/repos/ampproject/amphtml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ampproject/amphtml/labels{/name}","releases_url":"https://api.github.com/repos/ampproject/amphtml/releases{/id}","deployments_url":"https://api.github.com/repos/ampproject/amphtml/deployments","created_at":"2015-09-01T22:10:53Z","updated_at":"2016-03-16T21:27:43Z","pushed_at":"2016-03-16T21:10:09Z","git_url":"git://github.com/ampproject/amphtml.git","ssh_url":"git@github.com:ampproject/amphtml.git","clone_url":"https://github.com/ampproject/amphtml.git","svn_url":"https://github.com/ampproject/amphtml","homepage":"https://ampproject.org","size":42335,"stargazers_count":6886,"watchers_count":6886,"language":"JavaScript","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":833,"mirror_url":null,"open_issues_count":356,"forks":833,"open_issues":356,"watchers":6886,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/1637"},"html":{"href":"https://github.com/ampproject/amphtml/pull/1637"},"issue":{"href":"https://api.github.com/repos/ampproject/amphtml/issues/1637"},"comments":{"href":"https://api.github.com/repos/ampproject/amphtml/issues/1637/comments"},"review_comments":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/1637/comments"},"review_comment":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/1637/commits"},"statuses":{"href":"https://api.github.com/repos/ampproject/amphtml/statuses/171aecdc37135c45d6f494e4b5d0ae0f31de174d"}}}}