Skip to content

Commit 74d94b7

Browse files
committed
Run everything through the JSX transpiler with harmony=true
Use ES6 concise mixins Use ES6 destructuring Use ES6 arrow functions
1 parent 1f6d936 commit 74d94b7

29 files changed

+156
-196
lines changed

gulpfile.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ var template = require('gulp-template')
1414
var uglify = require('gulp-uglify')
1515

1616
var testFiles = ['./src/**/__tests__/*.js', './src/**/__mocks__/*.js']
17-
var jsFiles = ['./src/**/*.js'].concat(testFiles.map(function(p) { return '!' + p }))
18-
var jsxFiles = jsFiles[0] + 'x'
17+
var jsFiles = ['./src/**/*.js', './src/**/*.jsx'].concat(testFiles.map(function(p) { return '!' + p }))
1918
var buildFiles = './build/modules/**/*.js'
2019

2120
var jsExt = (gutil.env.production ? 'min.js' : 'js')
@@ -29,17 +28,13 @@ gulp.task('clean-modules', function(cb) {
2928
del('./build/modules/**', cb)
3029
})
3130

32-
/** Copy non-jsx JavaScript to /build/modules */
33-
gulp.task('copy-js', ['clean-modules'], function() {
34-
return gulp.src(jsFiles)
35-
.pipe(gulp.dest('./build/modules'))
36-
})
37-
3831
/** Transpile JSX to plain old JavaScript and copy to /build/modules */
39-
gulp.task('transpile-jsx', ['clean-modules'], function() {
40-
return gulp.src(jsxFiles)
32+
gulp.task('transpile-js', ['clean-modules'], function() {
33+
return gulp.src(jsFiles)
4134
.pipe(plumber())
42-
.pipe(react())
35+
.pipe(react({
36+
harmony: true
37+
}))
4338
.pipe(gulp.dest('./build/modules'))
4439
})
4540

@@ -64,7 +59,7 @@ gulp.task('build-deps', function() {
6459
})
6560

6661
/** Lint everything in /build/modules */
67-
gulp.task('lint', ['copy-js', 'transpile-jsx'], function() {
62+
gulp.task('lint', ['transpile-js'], function() {
6863
return gulp.src(buildFiles)
6964
.pipe(jshint('./.jshintrc'))
7065
.pipe(jshint.reporter('jshint-stylish'))
@@ -162,7 +157,7 @@ gulp.task('dist', ['dist-copy'], function() {
162157
* against everything else which is already in /dist
163158
*/
164159
gulp.task('watch', ['copy-app', 'lint-tests'], function() {
165-
gulp.watch([jsFiles, jsxFiles], ['copy-app'])
160+
gulp.watch(jsFiles, ['copy-app'])
166161
gulp.watch(testFiles, ['lint-tests'])
167162
gulp.watch('./public/**/*.css', ['dist-css'])
168163
})

src/Comment.jsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,27 @@ var Comment = React.createClass({
2424
, threadStore: React.PropTypes.instanceOf(CommentThreadStore).isRequired
2525
},
2626

27-
getDefaultProps: function() {
27+
getDefaultProps() {
2828
return {
2929
loadingSpinner: false
3030
}
3131
},
3232

33-
getInitialState: function() {
33+
getInitialState() {
3434
return {
3535
comment: {}
3636
}
3737
},
3838

39-
componentWillMount: function() {
39+
componentWillMount() {
4040
this.bindFirebaseRef()
4141
},
4242

43-
componentWillUnmount: function() {
43+
componentWillUnmount() {
4444
this.clearDelayTimeout()
4545
},
4646

47-
componentDidUpdate: function(prevProps, prevState) {
47+
componentDidUpdate(prevProps, prevState) {
4848
if (!prevState.comment.id) {
4949
// Register a newly-loaded comment with the thread store
5050
if (this.state.comment.id) {
@@ -78,7 +78,7 @@ var Comment = React.createClass({
7878
}
7979
},
8080

81-
bindFirebaseRef: function() {
81+
bindFirebaseRef() {
8282
this.bindAsObject(HNService.itemRef(this.props.id), 'comment', this.handleFirebaseRefCancelled)
8383
if (this.timeout) {
8484
this.timeout = null
@@ -90,7 +90,7 @@ var Comment = React.createClass({
9090
* its author using the delay setting, which is measured in minutes - try
9191
* again in 30 seconds.
9292
*/
93-
handleFirebaseRefCancelled: function(e) {
93+
handleFirebaseRefCancelled(e) {
9494
if ("production" !== process.env.NODE_ENV) {
9595
console.error('Firebase ref for comment ' + this.props.id + ' was cancelled: ' + e.message)
9696
}
@@ -102,19 +102,19 @@ var Comment = React.createClass({
102102
}
103103
},
104104

105-
clearDelayTimeout: function() {
105+
clearDelayTimeout() {
106106
if (this.timeout) {
107107
clearTimeout(this.timeout)
108108
this.timeout = null
109109
}
110110
},
111111

112-
toggleCollapse: function(e) {
112+
toggleCollapse(e) {
113113
e.preventDefault()
114114
this.props.threadStore.toggleCollapse(this.state.comment.id)
115115
},
116116

117-
render: function() {
117+
render() {
118118
var comment = this.state.comment
119119
var props = this.props
120120
// Render a placeholder while we're waiting for the comment to load

src/DisplayComment.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ var DisplayComment = React.createClass({
1818
comment: React.PropTypes.object.isRequired
1919
},
2020

21-
getInitialState: function() {
21+
getInitialState() {
2222
return {
2323
op: {}
2424
, parent: {type: 'comment'}
2525
}
2626
},
2727

28-
componentWillMount: function() {
28+
componentWillMount() {
2929
this.fetchAncestors(this.props.comment)
3030
},
3131

32-
render: function() {
32+
render() {
3333
if (this.props.comment.deleted) { return null }
3434
if (this.props.comment.dead && !SettingsStore.showDead) { return null }
3535

src/DisplayListItem.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ var DisplayListItem = React.createClass({
1818
item: React.PropTypes.object.isRequired
1919
},
2020

21-
componentWillMount: function() {
21+
componentWillMount() {
2222
this.threadState = StoryCommentThreadStore.loadState(this.props.item.id)
2323
},
2424

25-
render: function() {
25+
render() {
2626
return this.renderListItem(this.props.item, this.threadState)
2727
}
2828
})

src/Item.jsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ function timeUnitsAgo(_moment) {
2626
var Item = React.createClass({
2727
mixins: [ItemMixin, ReactFireMixin],
2828

29-
getInitialState: function() {
29+
getInitialState() {
3030
return {
3131
item: ItemStore.getCachedStory(Number(this.props.params.id)) || {}
3232
}
3333
},
3434

35-
componentWillMount: function() {
35+
componentWillMount() {
3636
this.bindAsObject(HNService.itemRef(this.props.params.id), 'item')
3737
if (this.state.item.id) {
3838
this.threadStore = new StoryCommentThreadStore(this.state.item, this.handleCommentsChanged, {cached: true})
@@ -41,12 +41,12 @@ var Item = React.createClass({
4141
window.addEventListener('beforeunload', this.handleBeforeUnload)
4242
},
4343

44-
componentWillUnmount: function() {
44+
componentWillUnmount() {
4545
this.threadStore.dispose()
4646
window.removeEventListener('beforeunload', this.handleBeforeUnload)
4747
},
4848

49-
componentWillReceiveProps: function(nextProps) {
49+
componentWillReceiveProps(nextProps) {
5050
if (this.props.params.id != nextProps.params.id) {
5151
// Tear it down...
5252
this.threadStore.dispose()
@@ -63,14 +63,14 @@ var Item = React.createClass({
6363
}
6464
},
6565

66-
componentWillUpdate: function(nextProps, nextState) {
66+
componentWillUpdate(nextProps, nextState) {
6767
// Update the title when the item has loaded.
6868
if (!this.state.item.id && nextState.item.id) {
6969
setTitle(nextState.item.title)
7070
}
7171
},
7272

73-
componentDidUpdate: function(prevProps, prevState) {
73+
componentDidUpdate(prevProps, prevState) {
7474
// If the state item id changed, an initial or new item must have loaded
7575
if (prevState.item.id != this.state.item.id) {
7676
if (!this.threadStore || this.threadStore.itemId != this.state.item.id) {
@@ -96,26 +96,26 @@ var Item = React.createClass({
9696
* Ensure the last visit time and comment details get stored for this item if
9797
* the user refreshes or otherwise navigates off the page.
9898
*/
99-
handleBeforeUnload: function() {
99+
handleBeforeUnload() {
100100
this.threadStore.dispose()
101101
},
102102

103-
handleCommentsChanged: function(payload) {
103+
handleCommentsChanged(payload) {
104104
this.forceUpdate()
105105
},
106106

107-
autoCollapse: function(e) {
107+
autoCollapse(e) {
108108
e.preventDefault()
109109
this.threadStore.collapseThreadsWithoutNewComments()
110110
},
111111

112-
markAsRead: function(e) {
112+
markAsRead(e) {
113113
e.preventDefault()
114114
this.threadStore.markAsRead()
115115
this.forceUpdate()
116116
},
117117

118-
render: function() {
118+
render() {
119119
var state = this.state
120120
var item = state.item
121121
var threadStore = this.threadStore

src/Paginator.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
'use strict';
22

33
var React = require('react')
4-
var Router = require('react-router')
5-
6-
var Link = Router.Link
4+
var {Link} = require('react-router')
75

86
var Paginator = React.createClass({
9-
render: function() {
7+
render() {
108
if (this.props.page == 1 && !this.props.hasNext) { return null }
119
return <div className="Paginator">
1210
{this.props.page > 1 && <span className="Paginator__prev">

src/PermalinkedComment.jsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var React = require('react')
44
var ReactFireMixin = require('reactfire')
5-
var Router = require('react-router')
5+
var {Navigation} = require('react-router')
66

77
var CommentThreadStore = require('./stores/CommentThreadStore')
88
var HNService = require('./services/HNService')
@@ -15,33 +15,31 @@ var CommentMixin = require('./mixins/CommentMixin')
1515
var cx = require('./utils/buildClassName')
1616
var setTitle = require('./utils/setTitle')
1717

18-
var Navigation = Router.Navigation
19-
2018
var PermalinkedComment = React.createClass({
2119
mixins: [CommentMixin, ReactFireMixin, Navigation],
2220

23-
getDefaultProps: function() {
21+
getDefaultProps() {
2422
return {
2523
level: 0
2624
}
2725
},
2826

29-
getInitialState: function() {
27+
getInitialState() {
3028
return {
3129
comment: UpdatesStore.getComment(this.props.params.id) || {}
3230
, parent: {type: 'comment'}
3331
, op: {}
3432
}
3533
},
3634

37-
componentWillMount: function() {
35+
componentWillMount() {
3836
this.bindAsObject(HNService.itemRef(this.props.params.id), 'comment')
3937
if (this.state.comment.id) {
4038
this.commentLoaded(this.state.comment)
4139
}
4240
},
4341

44-
componentWillReceiveProps: function(nextProps) {
42+
componentWillReceiveProps(nextProps) {
4543
if (nextProps.params.id != this.props.params.id) {
4644
var comment = UpdatesStore.getComment(nextProps.params.id)
4745
if (comment) {
@@ -53,7 +51,7 @@ var PermalinkedComment = React.createClass({
5351
}
5452
},
5553

56-
componentWillUpdate: function(nextProps, nextState) {
54+
componentWillUpdate(nextProps, nextState) {
5755
if (this.state.comment.id != nextState.comment.id) {
5856
if (!nextState.comment.deleted) {
5957
// Redirect to the appropriate route if a Comment "parent" link had a
@@ -69,15 +67,15 @@ var PermalinkedComment = React.createClass({
6967
}
7068
},
7169

72-
commentLoaded: function(comment) {
70+
commentLoaded(comment) {
7371
this.setTitle(comment)
7472
if (!comment.deleted) {
7573
this.threadStore = new CommentThreadStore(comment, this.handleCommentsChanged)
7674
this.fetchAncestors(comment)
7775
}
7876
},
7977

80-
setTitle: function(comment) {
78+
setTitle(comment) {
8179
if (comment.deleted) {
8280
return setTitle('Deleted comment')
8381
}
@@ -88,14 +86,14 @@ var PermalinkedComment = React.createClass({
8886
setTitle(title)
8987
},
9088

91-
handleCommentsChanged: function(payload) {
89+
handleCommentsChanged(payload) {
9290
// We're only interested in re-rendering to update collapsed display
9391
if (payload.type == 'collapse') {
9492
this.forceUpdate()
9593
}
9694
},
9795

98-
render: function() {
96+
render() {
9997
var comment = this.state.comment
10098
// Render a placeholder while we're waiting for the comment to load
10199
if (!comment.id) { return this.renderCommentLoading(comment) }

src/PollOption.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ var pluralise = require('./utils/pluralise')
1212
var PollOption = React.createClass({
1313
mixins: [ReactFireMixin],
1414

15-
getInitialState: function() {
15+
getInitialState() {
1616
return {pollopt: {}}
1717
},
1818

19-
componentWillMount: function() {
19+
componentWillMount() {
2020
this.bindAsObject(HNService.itemRef(this.props.id), 'pollopt')
2121
},
2222

23-
render: function() {
23+
render() {
2424
var pollopt = this.state.pollopt
2525
if (!pollopt.id) { return <div className="PollOption PollOption--loading"><Spinner size="20"/></div> }
2626
return <div className="PollOption">

src/Settings.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ var React = require('react')
55
var SettingsStore = require('./stores/SettingsStore')
66

77
var Settings = React.createClass({
8-
componentDidMount: function() {
8+
componentDidMount() {
99
this.refs.container.getDOMNode().focus()
1010
},
1111

12-
onChange: function(e) {
12+
onChange(e) {
1313
SettingsStore[e.target.name] = e.target.checked
1414
this.forceUpdate()
1515
SettingsStore.save()
1616
},
1717

18-
render: function() {
18+
render() {
1919
return <div ref="container" className="Settings" tabIndex="-1">
2020
<form onChange={this.onChange}>
2121
<div className="Settings__setting Settings__setting--checkbox">

0 commit comments

Comments
 (0)