Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Skip falsy markers - #204

Merged
istarkov merged 1 commit into
GoogleMapReact:masterfrom
shark0der:master
Jul 24, 2016
Merged

istarkov merged 1 commit into
GoogleMapReact:masterfrom
shark0der:master

Conversation

@shark0der

Copy link
Copy Markdown
Contributor

Fixes #203

Comment thread src/google_map_markers.js Outdated
this.dimesionsCache_ = {};

const markers = React.Children.map(this.state.children, (child, childIndex) => {
if (!child) return null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why null? why not undefined or why not a filter like util

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.

I've commented on the issue as well:

I've returned null if child is falsy. The resulting array is passed to react so no need to filter out them after map.

@dapetcu21 dapetcu21 Jul 24, 2016

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Also, I can see this library being used with big amounts of markers, so minimising the amount of steps of intermediate array construction (with .map and .filter), might be a good thing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't like nulls ;-) the same result we will get with undefined.
So the question was about does null here has any advantage or hidden sense over undefined.

Having ES6 using null in any chain like env prevents me to use arguments defaults in the future, so I prefer not to use null at all.

So please change null on undefined ;-)

@shark0der

Copy link
Copy Markdown
Contributor Author

I've changed null to undefined as per request, however, you should keep in mind that null is generally more acceptable than undefined.

References:

Early react didn't even have proper validation for undefined:
react/react#1647

Therefore passing undefined may actually change behavior of underlying classes in confusing ways.

react/react#1668 (comment)

@istarkov

Copy link
Copy Markdown
Member

Thank you!
(IMO both null and undefined should gone from all languages ;-))

@istarkov
istarkov merged commit ef1689e into GoogleMapReact:master Jul 24, 2016
@istarkov

Copy link
Copy Markdown
Member

npm 0.16.2

@lock

lock Bot commented Dec 1, 2019

Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked as resolved and limited conversation to collaborators Dec 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conditionally rendering marker

3 participants