-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Themes: Switch data fetching to Redux #840
Conversation
Just tried to stick this into #846, to provide data to the themes list we render there, server-side. This could work okayish, but ideally, I think we should use the Redux-based |
Yeah, that's where I'm thinking of heading! |
#338 opened a nice precedent for client-side usage of a Redux global store, so… seems like the pieces are falling together, we can work with that momentum. |
I noticed that search/tier selection was funky, 0aca329 is a possible fix :P |
I meant to fix it, thanks for taking care of it :). |
// console.log( 'Flux -> Redux' ); | ||
// reduxStore.dispatch( action ); | ||
// } ); | ||
//}() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Did this work? :)
I'm thinking we probably don't need to integrate the two dispatchers now, as the Redux transition is getting some momentum behind it. We should check we're not relying on any 'external' actions, although from what I can remember, we're not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Did this work? :)
It did. :)
we probably don't need to integrate the two dispatchers now
I agree. I pushed it for the sake of communicating the exploration process, i.e. as a way of saying that this in particular had been tried.
We should check we're not relying on any 'external' actions, although from what I can remember, we're not.
Yeah, IIRC only the reverse happens, and that's something we can handle at the Redux middleware level.
0aca329
to
a793461
Compare
if ( page > 1 && ! loading && lastPage ) { | ||
this.onLastPage && this.onLastPage(); | ||
} | ||
fetchNextPage( site ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got kind of confused between the AC fetchNextPage
and the fetcher's fetchNextPage
function. Perhaps namespace/rename?
This is looking great. I removed some dead code, and rebased. The Jetpack search is quite amusing atm ;) |
578e4c6
to
5d45aab
Compare
Thanks for your feedback and fixes. I just pushed substantial changes that should make this PR a lot simpler and ship-worthy. Subsequent feedback and some testing would be greatly appreciated. :)
Heh, indeed. Hopefully, it's looking better now. |
On derived data and selectors: the changes brought around Our data needs for |
Wow, yes. This looks much nicer. Perhaps update the PR description with what you guys have done, and how it's better? I figure this would be a good example to give to others, on how to |
Indeed. I've rewritten the PR description and added the NR label. |
Quick note from testing -- purchasing a theme in single-site mode doesn't seem to update the |
How well do our |
) | ||
// TODO: Remove function when using React 0.14 | ||
React.createElement( ReduxProvider, { store: context.reduxStore }, () => { | ||
return React.createElement( ThemesComponent, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we shorten () => { return x; }
to () => x
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely.
👍 |
f58ad6f
to
523337a
Compare
I've tested around preview->customize->activate and the Tracks events. Looking good with no apparent regressions. Noting that we don't have a working Tracks event for jetpack search, with or without this PR. |
Substantial refactor of our data fetching components, which are now Redux-`connect`ed. - `ThemesListFetcher`, `ActivatingTheme`, and `CurrentTheme` (i.e. the data component) are kept as generic data components that relay application state to their children. - Selectors are given much greater importance, as they allow us to simplify the data model by avoiding forms of data duplication — notably, avoiding storage of derived data next to essential data. - Use of selectors allowed to altogether eliminate one action: `SEARCH_THEMES`, which was basically a _virtual_ action (read: _hack_) to trigger client-side filtering of themes, a feature specific to Jetpack sites. An @mcsf and @ockham project, with fixes by @ehgy :-)
This way, we can avoid at least passing `getState()` as a prop to themes-selection.
523337a
to
a84cc81
Compare
Themes: Switch data fetching to Redux
analytics.tracks.recordEvent( 'calypso_themeshowcase_theme_click', { | ||
search_term: queryParams.search, | ||
theme: theme.id, | ||
results_rank: resultsRank + 1, | ||
results: ThemesListStore.get(), | ||
results: themesList, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting here that ThemesListStore.get()
should have actually read ThemesListStore.getThemesList()
-- we had overlooked to change get()
to getThemesList()
when we started using createReducerStore()
to create our stores from reducers. That latter function however returns objects whose .get()
method returns the entire store state. Thus, we were erroneously setting results
to the contents of the entire ThemesListStore
state instead (including query params and whatnot) instead of just the themes list. This has been fixed by this PR.
Notes by @mcsf:
Context
What started as an experimental branch for a number of Redux-related changes across Themes coalesced into a substantial refactor of our data fetching components, which are now Redux-
connect
ed. This means that this PR moves Themes entirely to Redux.Decisions
ThemesListFetcher
,ActivatingTheme
, andCurrentTheme
(i.e. the data component) are kept as generic data components that relay application state to their children.SEARCH_THEMES
, which was basically a virtual action (read: hack) to trigger client-side filtering of themes, a feature specific to Jetpack sites.Next
themes
branch.dispatch()
function fromcontext.reduxStore
in the relevant sections to dispatch the corresponding Redux actions. Another possible approach would have been to have a layer of Redux middleware that dispatches certain actions to the singleton Flux architecture.Bugs
Testing
QA should focus around navigation of the Showcase, switching between sites, including both WP.com and Jetpack sites, searching, per-tier filtering, triggering
InfiniteList
's fetching, and switching between Showcase and other sections.