Skip to content

Conversation

@OriLev
Copy link
Owner

@OriLev OriLev commented Jan 10, 2018

No description provided.

@OriLev OriLev merged commit a5de9f0 into master Jan 10, 2018
@elektronik2k5
Copy link
Collaborator

const Route = ReactRouter.Route;
const Switch = ReactRouter.Switch;
const Game = require('./Game');
const pathFind = require('../utils/BFS');
Copy link
Collaborator

Choose a reason for hiding this comment

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

import findPath from '../utils/BFS';

Copy link
Owner Author

Choose a reason for hiding this comment

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

so I've been googling on the difference between require() and import and got into a wall of not understanding the difference between 'dynamic' and 'static' loading. And that's besides the fact that most places say that import is being transpiled by Babel to require() anyway because there is no native support yet... :/

  1. Any chance for a link to clarify that difference between dynamic and static loading?

  2. you marked only the findPath to use with import. Is there any reason not to use import everywhere instead of the require() I've been using to for the other classes of the app? Or React for that matter?

Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. It's a complex topic and I can write you the basics in chat.
  2. I only commented in this PR on changes, not on everything. If I'd comment on everything, we'd never finish. Gotta limit the scope, otherwise it's unmanageable. You should use import everywhere you can.


console.log('creating board')
console.log('path?');
console.log(pathFind);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't one console.log enough?


handleClickOnBoard(x, y) {
console.log('trying to update state');
const board = this.state.board;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use destructuring, everywhere: const { board, } = this.state;

this.updateEndLocation(x, y);
} else {
const tempBoard = this.state.board;
const tempBoard = board.map((row) =>{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't name things "temp". Even life is temporary, we all know that. Even "new" is better than "temp".
Name your mapping functions. This helps debugging and stack traces. Naming things in general helps you write better code.

} else {
const tempBoard = this.state.board;
const tempBoard = board.map((row) =>{
return row.map((cell)=>Object.assign({}, cell));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shorter:

return row.map(cell => ({ ...cell, }));

But why clone the cell at all?

Copy link
Owner Author

Choose a reason for hiding this comment

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

because I want to make changes to state only from this.setState(), and since board is a nested array of objects, if i make a change to the cell's content it will change the state without invoking the setState function.

}
}
}
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

return isInField(point) && isAllowedStep(point) && !hasBeenVisited(point);

return legal;
}

// the BFS algorithm that searches for a path between the 'start' and 'end' points
Copy link
Collaborator

Choose a reason for hiding this comment

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

A link to an explanation is better

}

// the BFS algorithm that searches for a path between the 'start' and 'end' points
// returns 'true' if a path was found and 'false' if not
Copy link
Collaborator

Choose a reason for hiding this comment

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

Redundant for a well named boolean function


// the BFS algorithm that searches for a path between the 'start' and 'end' points
// returns 'true' if a path was found and 'false' if not
var pathExists = function() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you copy/pasted if from somewhere, add a link.


}

module.exports = pathFind; No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

export default findPath

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