Skip to content
This repository has been archived by the owner on Oct 24, 2021. It is now read-only.

Prevent exporting Container as global variable #893

Merged
merged 2 commits into from
Sep 28, 2018

Conversation

charpeni
Copy link
Contributor

@charpeni charpeni commented Sep 24, 2018

I noticed an unwanted behavior across Meteor codebases that I've been able to track down here.

If we do the following, we do not simply name our container, we create a global variable that we export:

export default ListPageContainer = withTracker(({ id }) => {
  // ...
})(ListPage);

The syntax below is not valid, we can't export default an inline initialized variable. As a side effect, we'll have ListPageContainer in our global scope.

We would have to..

Declare the const before using export default keyword:

const ListPageContainer = withTracker(({ id }) => {
  // ...
})(ListPage);

export default ListPageContainer;

Or if they're in the same file, we can export default our base class, and export our container as an inline const.

export default class ListPage extends Component {
  // ...
}

export const ListPageContainer = withTracker(({ id }) => {
  // ...
})(ListPage);

Then, we'll have to import like this:

import ListPage, { ListPageContainer } from "...";

cc @abernix A serious unattended behavior that probably worth your eyes on. 👀

@lorensr
Copy link
Contributor

lorensr commented Sep 28, 2018

Thanks for the contribution! Edited to use the suggested method from the get-go ☺️

@lorensr lorensr merged commit 2832c8e into meteor:master Sep 28, 2018
lorensr added a commit to meteor/todos that referenced this pull request Sep 28, 2018
@charpeni charpeni deleted the export-withTracker branch October 5, 2018 16:59
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.

2 participants