Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support User: Add (pure) Redux integration (alternate implementation) #2819

Merged
merged 1 commit into from
Feb 2, 2016

Conversation

jordwest
Copy link
Contributor

This is an alternative implementation of #2512 based on this discussion. 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.

Builds upon: #2368

This change moves storage of the support token to the Redux store. There are no user facing functionality changes in this PR since #2368.

ref p195om-2GO-p2

@jordwest jordwest added [Status] In Progress [Feature Group] Support All things related to WordPress.com customer support. labels Jan 27, 2016
@jordwest jordwest self-assigned this Jan 27, 2016
@jordwest jordwest force-pushed the add/support-user-redux-alt branch 5 times, most recently from 8caae34 to 755480b Compare January 28, 2016 10:19
wpcom = require( 'lib/wp/support' )( wpcom );
}

module.exports = wpcom;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for review: These changes give the unit tests access to the wpcomSupport functions

@jordwest jordwest added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Jan 28, 2016
* update the wpcom API interceptor accordingly.
*/
reduxStore.subscribe( () => {
const { supportUser, supportToken } = getSupportState( getState() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to listen to an action rather than subscribing to a store change? This is going to fire often.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Another option might be to move this to a React component, then use connect() and componentWillReceiveProps() to observe the changes. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I couldn't find any better patterns either. 😄

I guess the weirdness comes from the fact that we need to maintain state in two places. I'm OK with the above, but it'd be good if we could refactor this in the future.

@jordwest jordwest force-pushed the add/support-user-redux-alt branch 2 times, most recently from 2fca7ab to d00d9cb Compare February 1, 2016 01:59
* error occurs in a wpcom API call, the error is forwarded to the
* Redux store via an action. This also forces any data refreshes
* that are required due to the change of user.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing, but multiline comments that are not jsdoc blocks should use //.

@mtias
Copy link
Member

mtias commented Feb 1, 2016

I think this is better as an intermediary step in keeping things cleaner, thanks for the alternative approach.

@gwwar
Copy link
Contributor

gwwar commented Feb 2, 2016

👍 retested this and it works well. Thanks for reworking this!

One minor thing that could use some improvement is maybe a quick console.log for your current user status if you've logged in successfully. Currently on login, we see a promise, and on logout, an action:
screen shot 2016-02-01 at 4 41 34 pm
screen shot 2016-02-01 at 4 41 44 pm

@gwwar gwwar added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Feb 2, 2016
@jordwest jordwest force-pushed the add/support-user-redux-alt branch 2 times, most recently from 78fc090 to 5ffe20d Compare February 2, 2016 03:32
@jordwest jordwest force-pushed the add/support-user-redux-alt branch from 5ffe20d to 8de4589 Compare February 2, 2016 04:35
This change adds the Redux actions and reducer for the Support User
UI in an upcoming PR.
@jordwest jordwest force-pushed the add/support-user-redux-alt branch from 8de4589 to c6516a6 Compare February 2, 2016 04:58
jordwest added a commit that referenced this pull request Feb 2, 2016
@jordwest jordwest merged commit 9932ff0 into master Feb 2, 2016
@mtias mtias deleted the add/support-user-redux-alt branch February 2, 2016 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature Group] Support All things related to WordPress.com customer support.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants