Skip to content

Gamelab grid#14897

Merged
caleybrock merged 7 commits intostagingfrom
gamelab-grid
May 10, 2017
Merged

Gamelab grid#14897
caleybrock merged 7 commits intostagingfrom
gamelab-grid

Conversation

@caleybrock
Copy link
Copy Markdown
Contributor

@caleybrock caleybrock commented May 5, 2017

Screenshot

screen shot 2017-05-09 at 10 34 52 pm

At any point during running or reset, the grid can be toggled on and off.

Technical decisions - hopefully to reference in the future when there is more time to fix.

Checkbox placement and implementation: At first, I tried putting the checkbox outside of GameButtons because that is a protected div, but GameButtons has some CSS with an after sector that causes GameButtons to have a -18px margin. This takes over click events for buttons below it. Removing the CSS that requires the negative margin breaks other scripts.
The checkbox is now included in GameButtons, but since it's a protected div, it requires jquery to update.
Grid: The grid is inside of VisualizationOverlay which is also protected so it is turned on and off with jquery. Since all other visualizations don't happen while the app is running, I added functionality to allow the grid to show anytime.

height={GAME_HEIGHT}
onMouseMove={this.onMouseMove}
>
<GridOverlay show={this.props.showGrid} />
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Bjvanminnen I would expect that passing in this prop would update this component but since it's in a protected div, is there something else I need to do to make this work?
I can log and see that redux state has the right value, but my component does not.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The short answer is that when you're inside a ProtectedDiv, it's not going to update on redux store changes. Your options are (a) ensure that it has the right state on initial render and never needs to update (presumably not applicable if you want to toggle on/off dynamically) (b) move this outside of the ProtectedDiv (possibly difficult) (c) Make the div not protected (while cleaning up the things that necessitated it being protected) or (d) toggle the state using something like jquery code instead of react (generally not recommended).

(c) is probably the most desirable, but not sure how plausible it is.

@caleybrock
Copy link
Copy Markdown
Contributor Author

@Bjvanminnen please take a look - thanks!

$("#grid-overlay")[0].style.display = 'none';
}
}
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking at this code again, I'm actually pretty happy with it. The pattern still feels fairly React like. One thing you could do is use refs instead of ids for grid-checkbox. Then you would have something like this.refs.gridCheckbox.className = "fa-check-square-o". For grid-overlay, that may not be be possible because grid-overlay is in a different component.

I think that may be what I actually like least about this - modifying the rendered DOM of another component from this one. Could/should we have a method like this in GridOverlay as well? There I think it could just be

componentWillReceiveProps(nextProps) {
  $(ReactDOM.findDOMNode(this)).toggle(nextProps.showGrid)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

GridOverlay is also in a protected div, so it won't ever receive new props, which is why is has to be modified here. Since they both need to be modified in this component, I just decided to keep them consistent by updating the classname in the same way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, of course.

@caleybrock caleybrock merged commit bf27980 into staging May 10, 2017
@caleybrock caleybrock deleted the gamelab-grid branch May 10, 2017 18:07
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.

2 participants