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

Play Your Cards Right #6

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open

Conversation

joelamb
Copy link

@joelamb joelamb commented Oct 12, 2018

Managing state in the top level of the app and extensive conditional rendering of dumb components made this quite complex.
Some of the components are unnecessarily granular, but this was to try out props.children and making elements suchs as buttons as reusable as possible.

super();
this.state = {
url: 'https://deckofcardsapi.com/api/deck/new/draw/?count=52',
Copy link
Contributor

Choose a reason for hiding this comment

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

since url does not change, it can just live in a const outside of class

fetch(url)
.then(response => response.json())
.then(data => {
this.setState(
Copy link
Contributor

@dmitrigrabov dmitrigrabov Oct 12, 2018

Choose a reason for hiding this comment

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

There is too much going on here. Especially with mulitple levels of callbacks. This could be done using a single setState call.

const cleanCards = this.cleanData(data.cards)
this.setState({
  allCards: this.state.allCards.concat(cleanCards),
  cardsReady: true
});

});

test('cardShuffle should return a randomised array', () => {
const mockRandom = jest.fn();
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

@dmitrigrabov
Copy link
Contributor

Great work. Love the tests

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