From 28679bfba2d4160cd54fe368e5412aa622cd8c6e Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 25 Jun 2018 13:02:30 +0300 Subject: transform-class-properties --- vnext/package.json | 4 ++++ vnext/src/components/Chat.js | 3 +-- vnext/src/components/Feeds.js | 3 +-- vnext/src/components/LoginButton.js | 15 +++++++-------- vnext/src/components/MessageInput.js | 16 +++++----------- vnext/src/components/Thread.js | 8 +++----- vnext/src/index.js | 5 ++--- vnext/yarn.lock | 13 +++++++++++++ 8 files changed, 36 insertions(+), 31 deletions(-) (limited to 'vnext') diff --git a/vnext/package.json b/vnext/package.json index 845e6426..640283e7 100644 --- a/vnext/package.json +++ b/vnext/package.json @@ -14,6 +14,7 @@ "babel-core": "^6.26.3", "babel-jest": "^23.0.1", "babel-loader": "^7.1.4", + "babel-plugin-transform-class-properties": "^6.24.1", "babel-preset-env": "^1.7.0", "babel-preset-react": "^6.24.1", "connect-history-api-fallback": "^1.5.0", @@ -38,6 +39,9 @@ "whatwg-fetch": "^2.0.4" }, "babel": { + "plugins": [ + ["transform-class-properties", {"spec": true}] + ], "presets": [ "env", "react" diff --git a/vnext/src/components/Chat.js b/vnext/src/components/Chat.js index 79425c12..c4d9422f 100644 --- a/vnext/src/components/Chat.js +++ b/vnext/src/components/Chat.js @@ -11,13 +11,12 @@ export default class Chat extends React.Component { this.state = { chats: [] }; - this.loadChat = this.loadChat.bind(this); } componentWillMount() { this.loadChat(this.props.match.params.user); } - loadChat(uname) { + loadChat = (uname) => { const { hash } = this.props.visitor; this.setState({ chats: [] diff --git a/vnext/src/components/Feeds.js b/vnext/src/components/Feeds.js index 0f12575f..5e9c14d0 100644 --- a/vnext/src/components/Feeds.js +++ b/vnext/src/components/Feeds.js @@ -61,7 +61,6 @@ class Feed extends React.Component { this.state = { msgs: [] }; - this.loadMessages = this.loadMessages.bind(this); } componentDidMount() { this.loadMessages(this.props.visitor.hash, this.props.location.search); @@ -72,7 +71,7 @@ class Feed extends React.Component { this.loadMessages(nextProps.visitor.hash, nextProps.location.search) } } - loadMessages(hash = '', filter = '') { + loadMessages = (hash = '', filter = '') => { document.body.scrollTop = 0; document.documentElement.scrollTop = 0; this.setState({ msgs: [] }) diff --git a/vnext/src/components/LoginButton.js b/vnext/src/components/LoginButton.js index 22ae2198..fb3c087e 100644 --- a/vnext/src/components/LoginButton.js +++ b/vnext/src/components/LoginButton.js @@ -11,25 +11,24 @@ export default class LoginButton extends React.Component { username: '', password: '' }; - this.toggleModal = this.toggleModal.bind(this); } - toggleModal(event) { + toggleModal = (event) => { if (event) event.preventDefault() this.setState({ isOpen: !this.state.isOpen }); } - usernameChanged(event) { + usernameChanged = (event) => { this.setState({ username: event.target.value }) } - passwordChanged(event) { + passwordChanged = (event) => { this.setState({ password: event.target.value }) } - login(event) { + login = (event) => { event.preventDefault(); let headers = new Headers(); headers.append('Authorization', 'Basic ' + window.btoa(unescape(encodeURIComponent(this.state.username + ":" + this.state.password)))); @@ -67,16 +66,16 @@ export default class LoginButton extends React.Component {
Already registered?
- diff --git a/vnext/src/components/MessageInput.js b/vnext/src/components/MessageInput.js index 6e698c32..e30962a8 100644 --- a/vnext/src/components/MessageInput.js +++ b/vnext/src/components/MessageInput.js @@ -9,12 +9,6 @@ import Button from './Button'; export default class MessageInput extends React.Component { constructor(props) { super(props) - this.textChanged = this.textChanged.bind(this); - this.attachmentChanged = this.attachmentChanged.bind(this); - this.openfile = this.openfile.bind(this); - this.handleCtrlEnter = this.handleCtrlEnter.bind(this); - this.onSubmit = this.onSubmit.bind(this); - this.textarea = React.createRef(); this.fileinput = React.createRef(); this.state = { @@ -26,13 +20,13 @@ export default class MessageInput extends React.Component { } } - handleCtrlEnter(event) { + handleCtrlEnter = (event) => { if (event.ctrlKey && (event.charCode == 10 || event.charCode == 13)) { this.onSubmit({}) } } - onSubmit(event) { + onSubmit = (event) => { if (event.preventDefault) event.preventDefault(); const input = this.fileinput.current; this.props.onSend({ @@ -50,7 +44,7 @@ export default class MessageInput extends React.Component { componentDidMount() { this.textarea.current.focus() } - textChanged(event) { + textChanged = (event) => { this.setState({ body: event.target.value }) @@ -59,12 +53,12 @@ export default class MessageInput extends React.Component { const height = el.scrollHeight + offset; el.style.height = `${height + offset}px`; } - attachmentChanged(event) { + attachmentChanged = (event) => { this.setState({ attach: event.target.value }) } - openfile() { + openfile = () => { const input = this.fileinput.current; if (this.state.attach) { this.setState({ diff --git a/vnext/src/components/Thread.js b/vnext/src/components/Thread.js index 5ff91346..17c5b55c 100644 --- a/vnext/src/components/Thread.js +++ b/vnext/src/components/Thread.js @@ -21,8 +21,6 @@ export default class Thread extends React.Component { replies: [], active: 0 }; - this.loaded = this.loaded.bind(this); - this.postComment = this.postComment.bind(this); } componentDidMount() { document.body.scrollTop = 0; @@ -55,7 +53,7 @@ export default class Thread extends React.Component { console.log(ex); }); } - loaded() { + loaded = () => { return (this.state.replies && this.state.replies.length > 0) || ('mid' in this.state.msg && !('replies' in this.state.msg)); } setActive(msg, event) { @@ -63,7 +61,7 @@ export default class Thread extends React.Component { active: msg.rid || 0 }) } - postComment(template) { + postComment = (template) => { const url = `https://api.juick.com/comment?hash=${this.props.visitor.hash}`; let form = new FormData(); form.append('mid', template.mid); @@ -150,7 +148,7 @@ export default class Thread extends React.Component { { this.props.visitor.uid > 0 ? (