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

Pushing for help with Redux selectors #880

Merged
merged 6 commits into from
Dec 19, 2017
Merged

Conversation

daovist
Copy link
Contributor

@daovist daovist commented Dec 18, 2017

I watched a Redux video and read some of the docs. I've created my action (please ignore the do and confirm actions, I will delete those, sorry) and reducer and they seem to be working but my selector is not. I could use help on this. I think once I manage to get the videoPause value from the store into the VideoPlayer component I will be able to wrap this up.

@liamcardenas
Copy link
Contributor

I'm looking into this

@@ -121,6 +124,11 @@ class VideoPlayer extends React.PureComponent {
}
}

pauseVideo() {
Copy link
Contributor

Choose a reason for hiding this comment

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

what if you change this to componentWillReceiveProps instead of pauseVideo?

Copy link
Contributor

Choose a reason for hiding this comment

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

then of course you would need to filter out the prop changes that don't lead to a pause, but does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried that and the method(?) was never called.

I think the issue is that the selector isn't working, or that the reducer isn't actually changing the state. My focus is on line 63 of components/video.view.jsx where it console logs the value of videoPause. It's always false, even after I've clicked open, which should update valuePause to true through the reducer.

Copy link
Member

Choose a reason for hiding this comment

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

@daovist try using the console to help debug what unexpected behavior is happening here. The console will show all action dispatches as well as all state changes (expand the console messages that are printed on action dispatches). This should tell you whether it's an issue with actions or the reducer. If both the action is fired and the Redux state looks correct, you can add a console statement to see if the selector is firing when you think it ought to.

</div>
);
}
}

export default VideoPlayer;
const select = (state, props) => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

this should go in videos/index.js

@@ -56,8 +57,11 @@ class Video extends React.PureComponent {
changeVolume,
volume,
uri,
// videoPause,
Copy link
Contributor

Choose a reason for hiding this comment

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

you want this in here, and then you want to pass it into VideoPlayer

import * as settings from "constants/settings";
import { createSelector } from "reselect";

const _selectState = state => state.videoPause || false;
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be

const _selectState = state => state.video || {};

Copy link
Contributor

@liamcardenas liamcardenas left a comment

Choose a reason for hiding this comment

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

Looks great! just this one question/change

componentWillReceiveProps(nextProps) {
if (nextProps.videoPause) {
this.refs.media.children[0].pause();
this.props.setVideoPause(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

is this (this.props.setVideoPause(false);) necessary? can we trigger this, instead, when they push "play" in app?

@liamcardenas
Copy link
Contributor

Making a follow up issue to this since this is work.

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