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

Changed all class properties to use es7 class property syntax #340

Merged
merged 1 commit into from
May 17, 2016

Conversation

alicewriteswrongs
Copy link
Contributor

What are the relevant tickets?

closes #330

What's this PR do?

This moves all class properties to the newer class property syntax, which uses the static keyword and looks like this:

class Foo {
  static someClassProperty = 12;
}

as opposed to the older syntax:

class Foo {
  ...
}

Foo.someClassProperty = 12;

the newer syntax moves the class properties into the body of the class declaration, meaning that the property declarations are closer to the code they relate to. On classes that extend React.Component we can declare our propTypes and defaultProps as class properties:

class Foobar extends React.Component {
  static propTypes = {
    foobar:  React.PropTypes.func.isRequired,
  }

  static defaultProps = {
    foobar: () => console.log("FOOBAR");
  }
}

It's a bit more readable and just generally nicer to work with. This syntax is a stage-1 proposal, which we're able to use by adding the stage-1 preset to Babel (see .babelrc).

Where should the reviewer start?

review the changes, make sure I didn't make any typos :P

How should this be manually tested?

click around and make sure everything works!

Any background context you want to provide?

Screenshots (if appropriate)

What GIF best describes this PR or how it makes you feel?

@bdero bdero temporarily deployed to micromasters-ci-pr-340 May 17, 2016 16:05 Inactive
@gsidebo
Copy link
Contributor

gsidebo commented May 17, 2016

general question: does webpack (or some other tool) take this es6/7 syntax and 'translate' it to something that is compatible with all the browsers we support? keep in mind i dont even know what browsers we support

@alicewriteswrongs
Copy link
Contributor Author

Yeah, we use babel for this purpose.
On May 17, 2016 12:15 PM, "Gavin Sidebottom" notifications@github.com
wrote:

general question: does webpack (or some other tool) take this es6/7 syntax
and 'translate' it to something that is compatible with all the browsers we
support? keep in mind i dont even know what browsers we support


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#340 (comment)

@alicewriteswrongs
Copy link
Contributor Author

you can read more here: https://babeljs.io/

@alicewriteswrongs
Copy link
Contributor Author

Babel is a transpiler, so basically it implements the ES2015 (and newer) syntax in standards-compliant ES5 JS. Webpack has some knowledge of ES2015 syntax, but really right now (until the 2.0 release hits) it pretty much consumes ES5 JS, so we basically chain them together - babel transpiles the code we write to clean ES5, and Webpack does the minification and bundling (for production) or the hot-reload dev stuff.

@alicewriteswrongs
Copy link
Contributor Author

We also polyfill prototype methods that don't yet have wide browser support (like Object.entries).

@alicewriteswrongs
Copy link
Contributor Author

alicewriteswrongs commented May 17, 2016

also I like talking about JS a lot so if you have questions hmu haha

@gsidebo
Copy link
Contributor

gsidebo commented May 17, 2016

👍 looks good

@alicewriteswrongs alicewriteswrongs merged commit d3aad9d into master May 17, 2016
@bdero bdero temporarily deployed to micromasters-ci May 17, 2016 16:59 Inactive
@alicewriteswrongs alicewriteswrongs deleted the ap/class-properties branch May 17, 2016 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert all remaining class.propTypes and etc to use class property syntax
3 participants