{"action":"created","comment":{"url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/comments/67601449","id":67601449,"diff_hunk":"@@ -281,6 +289,187 @@ describe( 'reducer', () => {\n \t\t\t} );\n \t\t} );\n \n+\t\tit( 'should transition post counts to trashed when trashing', () => {\n+\t\t\tlet state = counts( undefined, {\n+\t\t\t\ttype: POSTS_RECEIVE,\n+\t\t\t\tposts: [\n+\t\t\t\t\t{ ID: 481, site_ID: 2916284, type: 'post', status: 'publish', author: { ID: 73705554 } }\n+\t\t\t\t]\n+\t\t\t} );\n+\n+\t\t\tstate = counts( state, {\n+\t\t\t\ttype: POST_COUNTS_RECEIVE,\n+\t\t\t\tsiteId: 2916284,\n+\t\t\t\tpostType: 'post',\n+\t\t\t\tcounts: {\n+\t\t\t\t\tall: { publish: 3, trash: 0 },\n+\t\t\t\t\tmine: { publish: 2, trash: 0 }\n+\t\t\t\t}\n+\t\t\t} );\n+\n+\t\t\tstate = counts( state, {\n+\t\t\t\ttype: POST_DELETE,\n+\t\t\t\tsiteId: 2916284,\n+\t\t\t\tpostId: 481\n+\t\t\t} );\n+\n+\t\t\texpect( state ).to.eql( {\n+\t\t\t\t2916284: {\n+\t\t\t\t\tpost: {\n+\t\t\t\t\t\tall: { publish: 2, trash: 1 },\n+\t\t\t\t\t\tmine: { publish: 2, trash: 0 }\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t} );\n+\t\t} );\n+\n+\t\tit( 'should transition mine post counts to trashed when trashing author\\'s post', () => {\n+\t\t\tlet state = counts( undefined, {\n+\t\t\t\ttype: POSTS_RECEIVE,\n+\t\t\t\tposts: [\n+\t\t\t\t\t{ ID: 481, site_ID: 2916284, type: 'post', status: 'publish', author: { ID: 73705554 } }\n+\t\t\t\t]\n+\t\t\t} );\n+\n+\t\t\tstate = counts( state, {\n+\t\t\t\ttype: CURRENT_USER_ID_SET,\n+\t\t\t\tuserId: 73705554\n+\t\t\t} );\n+\n+\t\t\tstate = counts( state, {\n+\t\t\t\ttype: POST_COUNTS_RECEIVE,\n+\t\t\t\tsiteId: 2916284,\n+\t\t\t\tpostType: 'post',\n+\t\t\t\tcounts: {\n+\t\t\t\t\tall: { publish: 3, trash: 0 },\n+\t\t\t\t\tmine: { publish: 2, trash: 0 }\n+\t\t\t\t}\n+\t\t\t} );\n+\n+\t\t\tstate = counts( state, {\n+\t\t\t\ttype: POST_DELETE,\n+\t\t\t\tsiteId: 2916284,\n+\t\t\t\tpostId: 481\n+\t\t\t} );\n+\n+\t\t\texpect( state ).to.eql( {\n+\t\t\t\t2916284: {\n+\t\t\t\t\tpost: {\n+\t\t\t\t\t\tall: { publish: 2, trash: 1 },\n+\t\t\t\t\t\tmine: { publish: 1, trash: 1 }\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t} );\n+\t\t} );\n+\n+\t\tit( 'should transition trashed posts counts to the void when trashing', () => {","path":"client/state/posts/counts/test/reducer.js","position":103,"original_position":103,"commit_id":"6755e502743cc078b47e93285ce01ba84ebeefb6","original_commit_id":"6755e502743cc078b47e93285ce01ba84ebeefb6","user":{"login":"timmyc","id":22080,"avatar_url":"https://avatars.githubusercontent.com/u/22080?v=3","gravatar_id":"","url":"https://api.github.com/users/timmyc","html_url":"https://github.com/timmyc","followers_url":"https://api.github.com/users/timmyc/followers","following_url":"https://api.github.com/users/timmyc/following{/other_user}","gists_url":"https://api.github.com/users/timmyc/gists{/gist_id}","starred_url":"https://api.github.com/users/timmyc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timmyc/subscriptions","organizations_url":"https://api.github.com/users/timmyc/orgs","repos_url":"https://api.github.com/users/timmyc/repos","events_url":"https://api.github.com/users/timmyc/events{/privacy}","received_events_url":"https://api.github.com/users/timmyc/received_events","type":"User","site_admin":false},"body":"> to the void\r\n\r\nsounds ominous","created_at":"2016-06-18T14:06:55Z","updated_at":"2016-06-18T14:06:55Z","html_url":"https://github.com/Automattic/wp-calypso/pull/6040#discussion_r67601449","pull_request_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/6040","_links":{"self":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/comments/67601449"},"html":{"href":"https://github.com/Automattic/wp-calypso/pull/6040#discussion_r67601449"},"pull_request":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/6040"}}},"pull_request":{"url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/6040","id":73805967,"html_url":"https://github.com/Automattic/wp-calypso/pull/6040","diff_url":"https://github.com/Automattic/wp-calypso/pull/6040.diff","patch_url":"https://github.com/Automattic/wp-calypso/pull/6040.patch","issue_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/6040","number":6040,"state":"open","locked":false,"title":"State: Update counts state in response to post status changes","user":{"login":"aduth","id":1779930,"avatar_url":"https://avatars.githubusercontent.com/u/1779930?v=3","gravatar_id":"","url":"https://api.github.com/users/aduth","html_url":"https://github.com/aduth","followers_url":"https://api.github.com/users/aduth/followers","following_url":"https://api.github.com/users/aduth/following{/other_user}","gists_url":"https://api.github.com/users/aduth/gists{/gist_id}","starred_url":"https://api.github.com/users/aduth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aduth/subscriptions","organizations_url":"https://api.github.com/users/aduth/orgs","repos_url":"https://api.github.com/users/aduth/repos","events_url":"https://api.github.com/users/aduth/events{/privacy}","received_events_url":"https://api.github.com/users/aduth/received_events","type":"User","site_admin":false},"body":"Related: #5613\r\n\r\nThis pull request seeks to enhance the `state.posts.counts` state to account for changes in post status, transitioning counts from its previous status to the new status to reflect the change.\r\n\r\n__Implementation notes:__\r\n\r\nThis is a difficult challenge to solve, since post counts are received and tracked in state independently of the posts themselves. This is desirable since when navigating to a post listing screen, the filter tabs should display the counts of each status, even before all posts of that status are requested. This poses a problem when posts change over time, since there's effectively a dependency between the two states. When deleting a post or receiving a new post, the previous implementation had no way of determining what the post's previous status was, since that was tracked elsewhere in state.\r\n\r\nTo address this, I've experimented with the idea of having the reducer track its own local state, monitoring actions that it considers relevant to count changes. Here, this includes trashing posts (`POST_DELETE` action) and changes to posts over time (`POSTS_RECEIVE`). Further, since counts are distinguished by \"mine\" and \"all\", the reducer must also track the current user ID as it changes.\r\n\r\nWhile the implementation is quite different, this was very loosely inspired by an `undoable` higher-order reducer demo'd during this year's React Europe conference ([video](https://www.youtube.com/watch?v=uvAXVMwHJXU&feature=youtu.be&list=PLCC436JpVnK09bZeayg-KeLuHfHgc-tDa&t=677)).\r\n\r\n__Testing instructions:__\r\n\r\nEnsure that Mocha tests pass:\r\n\r\n```\r\nnpm run test-client client/state/posts/counts/test/reducer.js\r\n```\r\n\r\nObserve that when trashing a post from the [CPT listing screen](http://calypso.localhost:3000/types/post), the post counts in both the filter bar and sidebar draft button update accordingly. Specifically, note that posts and pages support \"trash\", while other post types do not, so \"trash\" count is only incremented for these types. Additionally, when trashing an already-trashed post, the post count for trashed should decrement.\r\n\r\nYou can also verify that publishing a draft from the editor updates these counts.\r\n\r\n__Caveats:__\r\n\r\n- Not all posts are tracked in Redux state. Notably, the (non-CPT) post listing screen still uses legacy Flux stores, so the draft count in the sidebar will not update when trashing a post from this screen\r\n\r\n/cc @mtias \n\nTest live: https://calypso.live/?branch=update/cpt-increment-post-counts","created_at":"2016-06-14T20:15:09Z","updated_at":"2016-06-18T14:06:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6d1c893cb82503015dd24102a58b4f6f37e50cf4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/6040/commits","review_comments_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/6040/comments","review_comment_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/6040/comments","statuses_url":"https://api.github.com/repos/Automattic/wp-calypso/statuses/6755e502743cc078b47e93285ce01ba84ebeefb6","head":{"label":"Automattic:update/cpt-increment-post-counts","ref":"update/cpt-increment-post-counts","sha":"6755e502743cc078b47e93285ce01ba84ebeefb6","user":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"repo":{"id":45936895,"name":"wp-calypso","full_name":"Automattic/wp-calypso","owner":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Automattic/wp-calypso","description":"The new JavaScript- and API-powered WordPress.com","fork":false,"url":"https://api.github.com/repos/Automattic/wp-calypso","forks_url":"https://api.github.com/repos/Automattic/wp-calypso/forks","keys_url":"https://api.github.com/repos/Automattic/wp-calypso/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Automattic/wp-calypso/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Automattic/wp-calypso/teams","hooks_url":"https://api.github.com/repos/Automattic/wp-calypso/hooks","issue_events_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/events{/number}","events_url":"https://api.github.com/repos/Automattic/wp-calypso/events","assignees_url":"https://api.github.com/repos/Automattic/wp-calypso/assignees{/user}","branches_url":"https://api.github.com/repos/Automattic/wp-calypso/branches{/branch}","tags_url":"https://api.github.com/repos/Automattic/wp-calypso/tags","blobs_url":"https://api.github.com/repos/Automattic/wp-calypso/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Automattic/wp-calypso/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Automattic/wp-calypso/git/refs{/sha}","trees_url":"https://api.github.com/repos/Automattic/wp-calypso/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Automattic/wp-calypso/statuses/{sha}","languages_url":"https://api.github.com/repos/Automattic/wp-calypso/languages","stargazers_url":"https://api.github.com/repos/Automattic/wp-calypso/stargazers","contributors_url":"https://api.github.com/repos/Automattic/wp-calypso/contributors","subscribers_url":"https://api.github.com/repos/Automattic/wp-calypso/subscribers","subscription_url":"https://api.github.com/repos/Automattic/wp-calypso/subscription","commits_url":"https://api.github.com/repos/Automattic/wp-calypso/commits{/sha}","git_commits_url":"https://api.github.com/repos/Automattic/wp-calypso/git/commits{/sha}","comments_url":"https://api.github.com/repos/Automattic/wp-calypso/comments{/number}","issue_comment_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/comments{/number}","contents_url":"https://api.github.com/repos/Automattic/wp-calypso/contents/{+path}","compare_url":"https://api.github.com/repos/Automattic/wp-calypso/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Automattic/wp-calypso/merges","archive_url":"https://api.github.com/repos/Automattic/wp-calypso/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Automattic/wp-calypso/downloads","issues_url":"https://api.github.com/repos/Automattic/wp-calypso/issues{/number}","pulls_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls{/number}","milestones_url":"https://api.github.com/repos/Automattic/wp-calypso/milestones{/number}","notifications_url":"https://api.github.com/repos/Automattic/wp-calypso/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Automattic/wp-calypso/labels{/name}","releases_url":"https://api.github.com/repos/Automattic/wp-calypso/releases{/id}","deployments_url":"https://api.github.com/repos/Automattic/wp-calypso/deployments","created_at":"2015-11-10T20:00:16Z","updated_at":"2016-06-18T12:19:52Z","pushed_at":"2016-06-18T13:32:02Z","git_url":"git://github.com/Automattic/wp-calypso.git","ssh_url":"git@github.com:Automattic/wp-calypso.git","clone_url":"https://github.com/Automattic/wp-calypso.git","svn_url":"https://github.com/Automattic/wp-calypso","homepage":"https://developer.wordpress.com/calypso/","size":79122,"stargazers_count":7466,"watchers_count":7466,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":920,"mirror_url":null,"open_issues_count":1292,"forks":920,"open_issues":1292,"watchers":7466,"default_branch":"master"}},"base":{"label":"Automattic:master","ref":"master","sha":"a105aa220ae7aafada0c5ba09b1d01d53e97efe3","user":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"repo":{"id":45936895,"name":"wp-calypso","full_name":"Automattic/wp-calypso","owner":{"login":"Automattic","id":887802,"avatar_url":"https://avatars.githubusercontent.com/u/887802?v=3","gravatar_id":"","url":"https://api.github.com/users/Automattic","html_url":"https://github.com/Automattic","followers_url":"https://api.github.com/users/Automattic/followers","following_url":"https://api.github.com/users/Automattic/following{/other_user}","gists_url":"https://api.github.com/users/Automattic/gists{/gist_id}","starred_url":"https://api.github.com/users/Automattic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Automattic/subscriptions","organizations_url":"https://api.github.com/users/Automattic/orgs","repos_url":"https://api.github.com/users/Automattic/repos","events_url":"https://api.github.com/users/Automattic/events{/privacy}","received_events_url":"https://api.github.com/users/Automattic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Automattic/wp-calypso","description":"The new JavaScript- and API-powered WordPress.com","fork":false,"url":"https://api.github.com/repos/Automattic/wp-calypso","forks_url":"https://api.github.com/repos/Automattic/wp-calypso/forks","keys_url":"https://api.github.com/repos/Automattic/wp-calypso/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Automattic/wp-calypso/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Automattic/wp-calypso/teams","hooks_url":"https://api.github.com/repos/Automattic/wp-calypso/hooks","issue_events_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/events{/number}","events_url":"https://api.github.com/repos/Automattic/wp-calypso/events","assignees_url":"https://api.github.com/repos/Automattic/wp-calypso/assignees{/user}","branches_url":"https://api.github.com/repos/Automattic/wp-calypso/branches{/branch}","tags_url":"https://api.github.com/repos/Automattic/wp-calypso/tags","blobs_url":"https://api.github.com/repos/Automattic/wp-calypso/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Automattic/wp-calypso/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Automattic/wp-calypso/git/refs{/sha}","trees_url":"https://api.github.com/repos/Automattic/wp-calypso/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Automattic/wp-calypso/statuses/{sha}","languages_url":"https://api.github.com/repos/Automattic/wp-calypso/languages","stargazers_url":"https://api.github.com/repos/Automattic/wp-calypso/stargazers","contributors_url":"https://api.github.com/repos/Automattic/wp-calypso/contributors","subscribers_url":"https://api.github.com/repos/Automattic/wp-calypso/subscribers","subscription_url":"https://api.github.com/repos/Automattic/wp-calypso/subscription","commits_url":"https://api.github.com/repos/Automattic/wp-calypso/commits{/sha}","git_commits_url":"https://api.github.com/repos/Automattic/wp-calypso/git/commits{/sha}","comments_url":"https://api.github.com/repos/Automattic/wp-calypso/comments{/number}","issue_comment_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/comments{/number}","contents_url":"https://api.github.com/repos/Automattic/wp-calypso/contents/{+path}","compare_url":"https://api.github.com/repos/Automattic/wp-calypso/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Automattic/wp-calypso/merges","archive_url":"https://api.github.com/repos/Automattic/wp-calypso/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Automattic/wp-calypso/downloads","issues_url":"https://api.github.com/repos/Automattic/wp-calypso/issues{/number}","pulls_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls{/number}","milestones_url":"https://api.github.com/repos/Automattic/wp-calypso/milestones{/number}","notifications_url":"https://api.github.com/repos/Automattic/wp-calypso/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Automattic/wp-calypso/labels{/name}","releases_url":"https://api.github.com/repos/Automattic/wp-calypso/releases{/id}","deployments_url":"https://api.github.com/repos/Automattic/wp-calypso/deployments","created_at":"2015-11-10T20:00:16Z","updated_at":"2016-06-18T12:19:52Z","pushed_at":"2016-06-18T13:32:02Z","git_url":"git://github.com/Automattic/wp-calypso.git","ssh_url":"git@github.com:Automattic/wp-calypso.git","clone_url":"https://github.com/Automattic/wp-calypso.git","svn_url":"https://github.com/Automattic/wp-calypso","homepage":"https://developer.wordpress.com/calypso/","size":79122,"stargazers_count":7466,"watchers_count":7466,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":920,"mirror_url":null,"open_issues_count":1292,"forks":920,"open_issues":1292,"watchers":7466,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/6040"},"html":{"href":"https://github.com/Automattic/wp-calypso/pull/6040"},"issue":{"href":"https://api.github.com/repos/Automattic/wp-calypso/issues/6040"},"comments":{"href":"https://api.github.com/repos/Automattic/wp-calypso/issues/6040/comments"},"review_comments":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/6040/comments"},"review_comment":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/6040/commits"},"statuses":{"href":"https://api.github.com/repos/Automattic/wp-calypso/statuses/6755e502743cc078b47e93285ce01ba84ebeefb6"}}}}
{"actor":{"display_login":"timmyc"}}