Skip to content

Commit a7569ec

Browse files
committed
authWrapper -> ES6 class
1 parent d450eb0 commit a7569ec

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

ES6

Whitespace-only changes.

client/src/AuthWrapper.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import { default as React, Component } from 'react';
22
import request from 'superagent';
33
import { DefaultSession as RethinkSession } from 'react-rethinkdb';
44
import { ChatBox } from './ChatBox';
@@ -11,19 +11,24 @@ const apiServer = {
1111
port: webPort
1212
}
1313

14-
export const AuthWrapper = React.createClass({
15-
getInitialState() {
16-
return {
14+
export class AuthWrapper extends Component {
15+
constructor(props) {
16+
super(props);
17+
this.state = {
1718
userId: window.localStorage.getItem('userId'),
1819
error: false,
1920
};
20-
},
21+
this.handleButton = this.handleButton.bind(this);
22+
this.handleLogout = this.handleLogout.bind(this);
23+
this.renderLoggedIn = this.renderLoggedIn.bind(this);
24+
this.renderLoggedOut = this.renderLoggedOut.bind(this);
25+
}
2126

2227
componentWillMount() {
2328
if (this.state.userId) {
2429
this.connect();
2530
}
26-
},
31+
}
2732

2833
connect() {
2934
const userId = window.localStorage.getItem('userId');
@@ -39,7 +44,7 @@ export const AuthWrapper = React.createClass({
3944
secure: secure,
4045
db: 'react_example_chat',
4146
});
42-
},
47+
}
4348

4449
handleButton(action, event) {
4550
event.preventDefault();
@@ -64,14 +69,14 @@ export const AuthWrapper = React.createClass({
6469
this.setState({userId});
6570
}
6671
});
67-
},
72+
}
6873

6974
handleLogout() {
7075
RethinkSession.close();
7176
this.setState({userId: null});
7277
window.localStorage.removeItem('userId');
7378
window.localStorage.removeItem('authToken');
74-
},
79+
}
7580

7681
renderLoggedIn() {
7782
return (
@@ -86,7 +91,7 @@ export const AuthWrapper = React.createClass({
8691
</div>
8792
</div>
8893
);
89-
},
94+
}
9095

9196
renderLoggedOut() {
9297
return (
@@ -102,13 +107,13 @@ export const AuthWrapper = React.createClass({
102107
</button>
103108
</div>
104109
);
105-
},
110+
}
106111

107112
render() {
108113
if (this.state.userId) {
109114
return this.renderLoggedIn();
110115
} else {
111116
return this.renderLoggedOut();
112117
}
113-
},
114-
});
118+
}
119+
}

0 commit comments

Comments
 (0)