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

Enable the use of property initializers in Babel #2

Closed
natecavanaugh opened this issue Apr 26, 2016 · 3 comments
Closed

Enable the use of property initializers in Babel #2

natecavanaugh opened this issue Apr 26, 2016 · 3 comments

Comments

@natecavanaugh
Copy link

Heya Maira,
I'm not sure if this is the right project to submit this to (since you may wish to have the flag set more than for just this repo).

But I recently had found that it's discouraged from using arrow functions and .bind(this) calls inside of render.
The main reason is because it increases memory usage as well as excessively hammers the garbage collector.
You can read about it here.

The way they describe getting around that is to use property initializers, however, they're a stage 1 setting.

But the final product looks something like:

class Foo extends JSXComponent {
    hide = () => {
        this.visible = false;
    }

    render() {
        return <div data-onclick={this.hide}></div>;
    }
}

Is enabling that something we can do?

Thanks Maira!

@mairatma
Copy link
Owner

You're right, binding functions every time can be bad for performance.

There are ways to go around this without needing stage 1 though, as explained here.

I agree that your example is nicer, but since stage 1's features are not as stable as the main es6 ones I'd prefer that we avoid using it on Metal.js by default. Instead we could make it easy for people to customize the build processes we have to use any babel plugins they wish, including the one for enabling stages, so I'll add an option for that on gulp-metal and metal-cli. If they use a separate build process then they can already do this. That way we can keep our core with only the most stable features, while allowing anyone to choose for themselves. What do you think?

@natecavanaugh
Copy link
Author

natecavanaugh commented Apr 29, 2016

Heya Maira,
I think enabling the ability to use the option (and any others they prefer) would be a good compromise.

Though I'm not sure about using another build system (It's kind of a nightmare from what I can tell, but I'll open up a separate ticket about it :))

@mairatma
Copy link
Owner

mairatma commented May 2, 2016

I've created tickets on our 2 build tools: gulp-metal and metal-cli, since that's where the option needs to be. I'll close this since it will be handled there :)

@mairatma mairatma closed this as completed May 2, 2016
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

No branches or pull requests

2 participants