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

Duplicate creation of leafletElement in Path #549

Closed
vadzim opened this issue Jan 3, 2019 · 2 comments · Fixed by #550
Closed

Duplicate creation of leafletElement in Path #549

vadzim opened this issue Jan 3, 2019 · 2 comments · Fixed by #550

Comments

@vadzim
Copy link
Contributor

vadzim commented Jan 3, 2019

MapLayer constructor creates leafletElement in its only statement:

export default class MapLayer<
...
  constructor(props: Props) {
    super(props)
    this.leafletElement = this.createLeafletElement(props)
}

this.leafletElement = this.createLeafletElement(props)

Path component extends MapLayer, calls MapLayer constructor and then immediately calls the same createLeafletElement function and saves the result to the same field leafletElement:

export default class Path<...> extends MapLayer<LeafletElement, Props> {
...
  constructor(props: Props) {
    super(props)
    this.leafletElement = this.createLeafletElement(props)
    if (this.contextValue == null) {
      this.contextValue = {
        ...props.leaflet,
        popupContainer: this.leafletElement,
      }
    }
  }

this.leafletElement = this.createLeafletElement(props)

Actually, the same data is creating twice. There is no need to create leafletElement in Path.

vadzim added a commit to vadzim/react-leaflet that referenced this issue Jan 3, 2019
vadzim added a commit to vadzim/react-leaflet that referenced this issue Jan 3, 2019
@vadzim
Copy link
Contributor Author

vadzim commented Jan 3, 2019

Oops.. The problem is much more interesting)
Path has a field declaration leafletElement: LeafletElement. This declaration actually assigns undefined to this.leafletElement after calling super(props). The declaration itself was added to make flow check pass.
So it turns that this.leafletElement is created twice only for flow to shut up.

@vadzim
Copy link
Contributor Author

vadzim commented Jan 3, 2019

fixed

vadzim added a commit to vadzim/react-leaflet that referenced this issue Jan 3, 2019
PaulLeCam added a commit that referenced this issue Jan 12, 2019
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 a pull request may close this issue.

1 participant