{"action":"created","comment":{"url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/comments/51371741","id":51371741,"diff_hunk":"@@ -0,0 +1,66 @@\n+/**\n+ * External dependencies\n+ */\n+import { compose } from 'lodash';\n+\n+/**\n+ * Internal dependencies\n+ */\n+import wpcom from 'lib/wp';\n+import User from 'lib/user';\n+import userSettings from 'lib/user-settings';\n+\n+import { supportUserTokenFetch, supportUserRestore } from 'state/support/actions';\n+import { getSupportState } from 'state/support/selectors';\n+\n+/**\n+ * Connects the Redux store and the low-level support user functions\n+ * of the wpcom library. When the support user token is changed in the\n+ * Redux store, the token is sent to the wpcom library. If a token\n+ * error occurs in a wpcom API call, the error is forwarded to the\n+ * Redux store via an action. This also forces any data refreshes\n+ * that are required due to the change of user.\n+ */\n+export default function( reduxStore ) {\n+\tconst user = new User();\n+\tconst dispatch = reduxStore.dispatch.bind( reduxStore );\n+\tconst getState = reduxStore.getState.bind( reduxStore );\n+\n+\t/**\n+\t * Called when the support user token was updated in wpcom\n+\t */\n+\tconst onTokenChange = () => {\n+\t\tuser.clear();\n+\t\tuser.fetch();\n+\t\tuserSettings.fetchSettings();\n+\t}\n+\n+\t/**\n+\t * Called when an API call fails due to a token error\n+\t * @param  {error} error  The token error\n+\t */\n+\tconst onTokenError = ( error ) => {\n+\t\treduxStore.dispatch( supportUserRestore( error ) );\n+\t}\n+\n+\t/**\n+\t * Follow any changes to the support token in the Redux store and\n+\t * update the wpcom API interceptor accordingly.\n+\t */\n+\treduxStore.subscribe( () => {\n+\t\tconst { supportUser, supportToken } = getSupportState( getState() );","path":"client/lib/user/support-user-interop.js","position":51,"original_position":51,"commit_id":"755480b6448ae2a1fc918d54760c503b4a988521","original_commit_id":"755480b6448ae2a1fc918d54760c503b4a988521","user":{"login":"jordwest","id":416133,"avatar_url":"https://avatars.githubusercontent.com/u/416133?v=3","gravatar_id":"","url":"https://api.github.com/users/jordwest","html_url":"https://github.com/jordwest","followers_url":"https://api.github.com/users/jordwest/followers","following_url":"https://api.github.com/users/jordwest/following{/other_user}","gists_url":"https://api.github.com/users/jordwest/gists{/gist_id}","starred_url":"https://api.github.com/users/jordwest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jordwest/subscriptions","organizations_url":"https://api.github.com/users/jordwest/orgs","repos_url":"https://api.github.com/users/jordwest/repos","events_url":"https://api.github.com/users/jordwest/events{/privacy}","received_events_url":"https://api.github.com/users/jordwest/received_events","type":"User","site_admin":false},"body":"There doesn't seem to be any way with Redux to only subscribe to specific events, however this should only fire once per dispatch - which is just as frequently as each reducer function. \r\n\r\nAnother option might be to move this to a React component, then use `connect()` and `componentWillReceiveProps()` to observe the changes. What do you think?","created_at":"2016-02-01T01:05:49Z","updated_at":"2016-02-01T01:05:49Z","html_url":"https://github.com/Automattic/wp-calypso/pull/2819#discussion_r51371741","pull_request_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/2819","_links":{"self":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/comments/51371741"},"html":{"href":"https://github.com/Automattic/wp-calypso/pull/2819#discussion_r51371741"},"pull_request":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/2819"}}},"pull_request":{"url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/2819","id":57307568,"html_url":"https://github.com/Automattic/wp-calypso/pull/2819","diff_url":"https://github.com/Automattic/wp-calypso/pull/2819.diff","patch_url":"https://github.com/Automattic/wp-calypso/pull/2819.patch","issue_url":"https://api.github.com/repos/Automattic/wp-calypso/issues/2819","number":2819,"state":"open","locked":false,"title":"Support User: Add (pure) Redux integration (alternate implementation)","user":{"login":"jordwest","id":416133,"avatar_url":"https://avatars.githubusercontent.com/u/416133?v=3","gravatar_id":"","url":"https://api.github.com/users/jordwest","html_url":"https://github.com/jordwest","followers_url":"https://api.github.com/users/jordwest/followers","following_url":"https://api.github.com/users/jordwest/following{/other_user}","gists_url":"https://api.github.com/users/jordwest/gists{/gist_id}","starred_url":"https://api.github.com/users/jordwest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jordwest/subscriptions","organizations_url":"https://api.github.com/users/jordwest/orgs","repos_url":"https://api.github.com/users/jordwest/repos","events_url":"https://api.github.com/users/jordwest/events{/privacy}","received_events_url":"https://api.github.com/users/jordwest/received_events","type":"User","site_admin":false},"body":"This is an alternative implementation of #2512 based on [this discussion](https://github.com/Automattic/wp-calypso/pull/2512#discussion-diff-50547415). The difference in this branch is that the Redux actions and reducers are kept pure with no side effects. To achieve this, the support token is stored in the Redux store and any change is pushed down to the `wpcom` library through an interop module. The interop module also triggers any content refreshes required due to the change of support token.\r\n\r\nBuilds upon: #2368\r\n\r\nThis change moves storage of the support token to the Redux store. There are no user facing functionality changes in this PR since #2368.\r\n\r\nref p195om-2GO-p2","created_at":"2016-01-27T03:00:06Z","updated_at":"2016-02-01T01:05:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fe4e209eb2ee141eeedc3e4b254eb26dfec5e863","assignee":{"login":"jordwest","id":416133,"avatar_url":"https://avatars.githubusercontent.com/u/416133?v=3","gravatar_id":"","url":"https://api.github.com/users/jordwest","html_url":"https://github.com/jordwest","followers_url":"https://api.github.com/users/jordwest/followers","following_url":"https://api.github.com/users/jordwest/following{/other_user}","gists_url":"https://api.github.com/users/jordwest/gists{/gist_id}","starred_url":"https://api.github.com/users/jordwest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jordwest/subscriptions","organizations_url":"https://api.github.com/users/jordwest/orgs","repos_url":"https://api.github.com/users/jordwest/repos","events_url":"https://api.github.com/users/jordwest/events{/privacy}","received_events_url":"https://api.github.com/users/jordwest/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/2819/commits","review_comments_url":"https://api.github.com/repos/Automattic/wp-calypso/pulls/2819/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/2819/comments","statuses_url":"https://api.github.com/repos/Automattic/wp-calypso/statuses/755480b6448ae2a1fc918d54760c503b4a988521","head":{"label":"Automattic:add/support-user-redux-alt","ref":"add/support-user-redux-alt","sha":"755480b6448ae2a1fc918d54760c503b4a988521","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-01-31T14:25:56Z","pushed_at":"2016-02-01T00:54:40Z","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":56440,"stargazers_count":6708,"watchers_count":6708,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":750,"mirror_url":null,"open_issues_count":1185,"forks":750,"open_issues":1185,"watchers":6708,"default_branch":"master"}},"base":{"label":"Automattic:master","ref":"master","sha":"e36c7bb234147da5e5ac9c722189a9d0b3663de9","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-01-31T14:25:56Z","pushed_at":"2016-02-01T00:54:40Z","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":56440,"stargazers_count":6708,"watchers_count":6708,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":750,"mirror_url":null,"open_issues_count":1185,"forks":750,"open_issues":1185,"watchers":6708,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/2819"},"html":{"href":"https://github.com/Automattic/wp-calypso/pull/2819"},"issue":{"href":"https://api.github.com/repos/Automattic/wp-calypso/issues/2819"},"comments":{"href":"https://api.github.com/repos/Automattic/wp-calypso/issues/2819/comments"},"review_comments":{"href":"https://api.github.com/repos/Automattic/wp-calypso/pulls/2819/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/2819/commits"},"statuses":{"href":"https://api.github.com/repos/Automattic/wp-calypso/statuses/755480b6448ae2a1fc918d54760c503b4a988521"}}}}