Skip to content

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.

constructor() {
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