Skip to content

Conversation

@OriLev
Copy link
Owner

@OriLev OriLev commented Feb 3, 2018

so here goes for the first narrow scope branch :)

  • Unite all app headers under <PageHeader> and all main content under <PageMain>, regardless of the current route.

resulted in removal of <GameHeader> and <GameScreen> components. yay less code!

@OriLev OriLev self-assigned this Feb 3, 2018
@OriLev OriLev requested a review from elektronik2k5 February 3, 2018 15:22
};
const gameScreenState = {
const instructionsProps = { instructionsState, };
const instructions = (
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the value is a react component, ItShouldBeCapitalized

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ok, so here I'm a little confused.

if i'd put the wrapper <div> inside the <GameInstructions> then this line would be:

const Instructions = <GameInstructions { ...instructionsProps } >

with the possibility of changing it to const GameInstructions = ... although I doubt I could do it because I already import GameInstructions.

but, the value of putting the jsx structure inside a single word variable is that it will be much more comfortable for use later on.

Although, I could also go for:
const gameHeaderChildren = [ <GameInstructions { ...props } />, <Link { ...otherProps } /> ]

your comment from below about the fine line is very strongly felt..

in the meantime changed to Instructions

</div>
);
const settingsText = '<-- Settings';
const linkProps = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

settingsLinkProps, as these are the props of a very specific link

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

const linkProps = {
className: 'settingsLink',
to: { pathname: '/settings', },
children: settingsText,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd inline it

Copy link
Owner Author

Choose a reason for hiding this comment

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

you mean children: '<---settings'?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

(also moved between <Link></Link> )

children: settingsText,
key: 1,
};
const settingsLink = <Link { ...linkProps } />;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Capital

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

key: 1,
};
const settingsLink = <Link { ...linkProps } />;
const gameHeaderProps = { children: [ settingsLink, instructions ], };
Copy link
Collaborator

Choose a reason for hiding this comment

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

An array of children requires the use of key props. Don't you get any warnings from the linter and browser console for this?
Also, when the contents of the children are static (like here), instead of using an array with key, you can use the new Fragment syntax, assuming you're using the latest version of React.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Another point here: using a children array with only 2 members decreases readability, since when you're looking at the returned tree from your component, it seems flat - when in fact it isn't. Now, if you have to render a long list or something dynamic, then fine. But here, where everything is static it's worse.
Same goes for pageMainProps below.

It is good that you're learning the various ways to compose components :). It's a fine line knowing which exact tool to use when.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I did add the key prop to both props definitions. maybe that's the reason neither of them complain...
Although the Fragment syntax indeed should be explored.
(I feel like a repeating record with the static/dynamic questions, but what does that mean in this case? The text of the instructions is going to change, but apparently it's not considered dynamic :) please help me to understand this conundrum)

about the second comment, totally agree. feels I overreached in this case with the will to use the children prop. in general I start feeling more and more that having 'smart' components with bigger JSX structure is not that bad if they are kept readable. Surely in this case it will be more readable if all the children will be inside the JSX rather than in the children.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Dynamic in the current context: children, not each child.

If you know ahead of time how many children there are (which has nothing to do with each child), then that's static.
Look at the code: it is an array literal with two values. It can't be anything else, cause it's a literal, like this one [1, 2]. :)
Same goes for an array literal of objects: [a, b] - there are two members: a and b. It doesn't matter what they are, as long as we're talking about the array itself. - It is static.

Dynamic is when you don't know the contents ahead of time, because it's an argument or comes from the user or from some API or whatever. In that case you also can't use a literal to describe it - because you don't have it when you write the code. It only exists at runtime.

Does that help?

Copy link
Owner Author

Choose a reason for hiding this comment

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

yes. very much. thanks!

Copy link
Owner Author

Choose a reason for hiding this comment

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

about "Fragment"

Since I wrote all the children directly in the JSX it seems less relevant now

<Board { ...boardProps } />
</div>
);
const buttonsPanel = <GameButtonsPanel { ...buttonPanelProps } />;
Copy link
Collaborator

Choose a reason for hiding this comment

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

B

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

although it will move to the JSX as a whole soon enough..


export default function PageHeader({ instructions, }) {
const instructionsProps = { instructions, };
export default function PageHeader({ children, }) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

A note on default exports: many people feel strongly about avoiding using them. I didn't for a long time, but have mostly changed my mind and no longer use them. You can google and read why people dislike them.

Copy link
Owner Author

Choose a reason for hiding this comment

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

read about it and it does make sense not to use them, both because of the autocomplete option in IDE's and to sustain a single naming convention for of the imported objects (unless import { foo, } as bar... is used, but that's a whole different topic).

now, how would you suggest introducing this refactor into the project?

  • On one of the current branches?
  • On the base/master branch?
  • Creating a separate branch for this specific piece of refactoring?

export default function PageMain({ setBoardColor, }) {
const panelProps = { setBoardColor, };

export default function PageMain({ children, }) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

MainPage is better English

Copy link
Owner Author

Choose a reason for hiding this comment

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

Although I do agree about the sound of it, I wanted to create a separation of a page's header and a page's main section. Which in this case does not necessarily reflect properly in the phrasing 'main page'.

Perhaps I should rename both to PurposeSection..?

Copy link
Collaborator

@elektronik2k5 elektronik2k5 Feb 9, 2018

Choose a reason for hiding this comment

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

FooSection sounds good. I usually set a naming convention, where each file which is a subset of one of the main entity types has it as a suffix in the name. So given these base entities: "Page", "Route", "View", "Widget", "Model", "Store", files would be named "HomePage", "RegistrationRoute", "AddCommentView", "BuySellWidget", "UserModel", "OrdersStore".
It is up to you to define which entities your app has and decide on a naming convention which would make it easier for you to reason about, navigate and make changes in your app.

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

const settingsPanelProps = { setBoardColor, key: 1, };
const mainProps = {
setBoardColor,
children: [ <SettingsPanel { ...settingsPanelProps } /> ],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here about children array of static members

Copy link
Owner Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

@elektronik2k5 elektronik2k5 left a comment

Choose a reason for hiding this comment

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

You commented that you did changes, but I don't see them here in this PR.

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