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

Turn Flux Action Creators into Redux ones #390

Merged
merged 1 commit into from
Nov 25, 2015

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Nov 21, 2015

Convert lib/themes/actions.js to Redux-style action creators
(using redux-thunk for async actions, and redux-analytics
middleware for actions involving analytics).

Note that the themes-last-event reducer and store are removed,
as the information they hold can be obtained from the themes-list
reducer, while the analytics functionality is now implemented in
lib/themes/middlewares.

Props @mcsf

CC @ehg @seear

To test:

  • Restart Calypso.
  • Check that the Theme Showcase (calypso.localhost:3000/design) still works as it should, including multi-site, single-site wpcom, and single-site Jetpack views.
  • Don't forget to test analytics (Enter localStorage.setItem( 'debug', 'calypso:analytics' ); in the browser console, and reload) -- themes search and activation should trigger corresponding analytics events. Check that the correct search_term is recorded. (Be aware of Search term not tracked when activating a theme from multisite #391, though -- search_term isn't properly recorded for activation or purchase from multisite.)

@ockham ockham added [Feature Group] Appearance & Themes Features related to the appearance of sites. [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. Server Side Rendering labels Nov 21, 2015
@ockham ockham self-assigned this Nov 21, 2015
@ockham ockham added this to the Themes: Showcase M3-LoggedOut milestone Nov 21, 2015
@@ -45,6 +45,10 @@ export const createReducerStore = ( reducer, initialState = {}, waitFor = [] ) =
return ReducerStore;
};

function mergeStates( stores ) {
Copy link
Member

Choose a reason for hiding this comment

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

Are we using this somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, rebase remnant. Good catch, thx. Removed in 1860f7e

@nb
Copy link
Member

nb commented Nov 21, 2015

What’s the logic behind the new name flux-actions? Weren’t the previous ones flux actions, too?

@ockham
Copy link
Contributor Author

ockham commented Nov 21, 2015

What}S he logic behind the new name flux-actions? Weren’t the previous ones flux actions, too?

They were indeed :-) It's mostly so the new Redux actions (which share a lot of their implementation with the old Flux actions) can remain in actions.js, which makes the diff much more legible.

@aduth
Copy link
Contributor

aduth commented Nov 23, 2015

Continuing a previous discussion on helper methods for retrieving data from the stores.

Looks like you've chosen to include a few helper methods in the reducer modules. Any reason for doing this?

Something I've been experimenting with in #338 is to introduce the concept of a "selector", intended to map the state tree to something more usable (as used here, fetching status or lists). The term selector is used by both react-redux and the reselect library.

The mapStateToProps function takes a single argument of the entire Redux store’s state and returns an object to be passed as props. It is often called a selector.

In #338, I created an entirely separate file for these types of functions, separate from both actions.js and reducers.js, named selectors.js.

What are your thoughts on this? To be clear, this is not a request for changes to be made. I'm more interested in starting some dialogs around conventions we can try using with Redux.

@ockham
Copy link
Contributor Author

ockham commented Nov 23, 2015

I think it's a great idea to follow established Redux patterns, especially if they make a whole lot of sense, as do selectors -- I just haven't seen and/or internalized all those patterns. That said, this PR has been lying around for a while (even though it ha actually less impact than yours -- it's still wrapping Redux for usage with Flux), so I'd rather not stack added complexity on top as to not further delay merging it.

I'll open an issue though to move to the selector pattern later on. I'll also see to reviewing #338 soon.

@mcsf
Copy link
Member

mcsf commented Nov 23, 2015

In #338, I created an entirely separate file for these types of functions, separate from both actions.js and reducers.js, named selectors.js.

Having played with selectors a little because of the Showcase (experimental branch), I think this should make a lot of sense. Will also be reviewing #338.

@mcsf
Copy link
Member

mcsf commented Nov 24, 2015

I trust this to be good, by now. It shouldn't disrupt anything. We've had enough eyeballs and whatever may come up after merging can be fixed.

👍

return this.fetch( site );
/**
* On Jetpack sites, we're not querying themes using the REST API, but fetch all of the installed
* themes (which typically aren't that many), and filter them within Calypso.
Copy link
Contributor

Choose a reason for hiding this comment

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

(which typically aren't that many)

We can probably lose the part of the comment in brackets without sacrificing any information.

@ockham ockham force-pushed the update/themes-redux-action-creators branch from 1860f7e to 5ed539c Compare November 25, 2015 11:12
Convert lib/themes/actions.js to Redux-style action creators
(using `redux-thunk` for async actions, and `redux-analytics`
middleware for actions involving analytics).

Note that the `themes-last-event` reducer and store are removed,
as the information they hold can be obtained from the `themes-list`
reducer, while the analytics functionality is now implemented in
lib/themes/middlewares.

Props @mcsf
@ockham ockham force-pushed the update/themes-redux-action-creators branch from ee6592c to 2bce856 Compare November 25, 2015 11:17
ockham added a commit that referenced this pull request Nov 25, 2015
…eators

Turn Flux Action Creators into Redux ones
@ockham ockham merged commit 103734d into master Nov 25, 2015
@ockham ockham deleted the update/themes-redux-action-creators branch November 25, 2015 11:38
@scruffian scruffian removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Nov 25, 2015

module.exports = ThemesActions;
defer( () => {
page( '/checkout/' + site.slug );
Copy link
Contributor

Choose a reason for hiding this comment

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

site.slug is a computed attribute, which is not appropriate for the Redux state tree and will be removed in a future revision. See #2757 for tracking issue and 74052e7160bfc8d91f3d78fda4f2d1b4c919951b (#4055) for an example alternative.

@mcsf mcsf mentioned this pull request Jun 3, 2016
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature Group] Appearance & Themes Features related to the appearance of sites. Server Side Rendering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants