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

Basic redux integration for thread component #141

Merged
merged 1 commit into from
Jul 10, 2018

Conversation

DmitryTsepelev
Copy link
Contributor

@DmitryTsepelev DmitryTsepelev commented Jul 8, 2018

Here is a very basic integration with redux. I've moved all the complex logic from the Thread component to the reducer, which is also responsible for restoring the initial state from the local storage. Reducer is already covered with a couple of specs, would be also useful to have a spec for getters. Related to #95 and #96

data: { comment, replies = [] },
mods = {},
} = props;

let threadComments = null;
if (!collapsed && !!replies.length) {
threadComments = replies.map(thread => (
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer inline variant. Please put it back to render

Copy link
Contributor Author

Choose a reason for hiding this comment

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

const currentCollapsed = state[action.comment.id];

if (action.collapsed !== currentCollapsed) {
persistCollapsedComments(action.comment, action.collapsed);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reducers must be pure functions. No side effects allowed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can make custom middleware to persist to localStorage. Using localStorage value for initial value is ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, done. If there will be more cases like this - we could try handling all the side effects with sagas

mapDispatchToProps
);

export default enhance(Thread);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I also prefer inline declarations here as well:

export default connect(
  (state, props) => ({
    collapsed: getThreadIsCollapsed(state, props.data.comment)
  }),
  { setCollapse }
)(Thread);

Copy link
Contributor Author

@DmitryTsepelev DmitryTsepelev Jul 8, 2018

Choose a reason for hiding this comment

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

Fixed. Hope it won't become unreadable as soon as we wrap it up with one more HOC :) Please note that we need this hack with <ConnectedThread cause we're using the recursion here

@DmitryTsepelev
Copy link
Contributor Author

@Guria Thanks for the review, I think I'm done. Please let me know if we need to change something else

Copy link
Collaborator

@Guria Guria left a comment

Choose a reason for hiding this comment

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

Ok, it seems it's good first move.
Though it's better to left only one store as soon as possible :)

Also please attach to redux and react devtools.
It would be enough just import 'preact/debug' in each entry point and compose another middleware to redux store.

web/app/store.js Outdated
...threadReducers,
});

const collapsedCommentsMiddleware = ({ getState }) => next => action => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe export middleware from thread as well?

@DmitryTsepelev
Copy link
Contributor Author

@Guria I'm stuck with the devtools :( I've configured everything according to the docs, aliased all the react-related things, but redux dev tool does not see the store, while react dev tool is "waiting for react" or "waiting for the roots to load", what am I missing here?

@Guria
Copy link
Collaborator

Guria commented Jul 9, 2018

Ok, nevermind. We can do it in a separate PR. But we need to resolve new conflicts here.

@DmitryTsepelev
Copy link
Contributor Author

Done

@DmitryTsepelev
Copy link
Contributor Author

@Guria Are we good to go? :) I have one more PR to submit

@Guria Guria merged commit a02b150 into umputun:master Jul 10, 2018
@Guria
Copy link
Collaborator

Guria commented Jul 10, 2018

@DmitryTsepelev please don't use yarn. only npm 6.1.0+

@DmitryTsepelev
Copy link
Contributor Author

ah ok, got it

@paskal paskal added this to the v1.1 milestone Jan 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants