-
Notifications
You must be signed in to change notification settings - Fork 0
Домашнее задание 5 #12
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Обратить внимание на то, что стрелочные функцию получают родительский this
, поэтому нет необходимости делать привязывание this
к этим функциям
@@ -23,11 +23,11 @@ class Chat extends React.Component { | |||
); | |||
} | |||
|
|||
onMessage(message) { | |||
onMessage = message => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Выше на 18-21 строках не нужен .bind(this)
, так как стрелочная функция уже захватывает this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chexex Спасибо, теперь понятны слова Мартина про отсутствие своего this у стрелочных функций
this.state.worker.then(worker => { | ||
worker.port.postMessage(message); | ||
}); | ||
} | ||
}; | ||
|
||
getSharedWorker() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почему эта функция не прошла модернизацию?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chexex не совсем понимаю почему, но кажется реакт почему-то не понимает, что я ему функцию отправляю
@@ -20,7 +20,7 @@ class FileButton extends React.Component { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
15 строка: var
на const
reader.onload = () => {...}
, bind
убрать
@@ -7,7 +7,7 @@ import * as actionTypes from "store/actionTypes/actionTypes"; | |||
import ImageFileButton from "static/Chat/MessageForm/FileButton/paperclip.svg"; | |||
|
|||
class FileButton extends React.Component { | |||
onFileSelect(event) { | |||
onFileSelect = event => { | |||
event.preventDefault(); | |||
var files = Array.from(event.target.files); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var
@@ -5,14 +5,14 @@ import styles from "./styles.module.css"; | |||
import * as actionTypes from "store/actionTypes/actionTypes"; | |||
|
|||
class ReactionButton extends React.Component { | |||
sendReaction() { | |||
sendReaction = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Везде, где используется sendReaction
больше не нужен привязывать this
(убрать .bind(this)
)
|
||
updateText() { | ||
updateText = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Убрать .bind(this)
@@ -5,11 +5,11 @@ import styles from "./styles.module.css"; | |||
import * as actionTypes from "store/actionTypes/actionTypes"; | |||
|
|||
class SendButton extends React.Component { | |||
onSubmit(event) { | |||
onSubmit = event => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Убрать .bind(this)
|
||
onSubmit(event) { | ||
onSubmit = event => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Убрать .bind(this)
@@ -5,18 +5,18 @@ import styles from "./styles.module.css"; | |||
import * as actionTypes from "store/actionTypes/actionTypes"; | |||
|
|||
class TextMessageForm extends React.Component { | |||
onChange(event) { | |||
onChange = event => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Убрать .bind(this)
@@ -21,7 +21,7 @@ class MessageList extends React.Component { | |||
this.scrollToBottom(); | |||
} | |||
|
|||
handleDragAndDrop(event) { | |||
handleDragAndDrop = event => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Убрать .bind(this)
@chexex Исправил все замечания кроме getSharedWorker() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Использованы ES6 возможности языка
Убраны комменты
Убраны var
6
@@ -11,13 +11,13 @@ export function getReadableSize(size) { | |||
} | |||
|
|||
export function getTime() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const getTime = () => {...}
var date = new Date(); | ||
var timeRegex = "^([0-1]?[0-9]|[2][0-3]):([0-5][0-9])(:[0-5][0-9])?"; | ||
let date = new Date(); | ||
let timeRegex = "^([0-1]?[0-9]|[2][0-3]):([0-5][0-9])(:[0-5][0-9])?"; | ||
return date.toTimeString().match(timeRegex)[0]; | ||
} | ||
|
||
export function sendToServer(text, file) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const sendToServer (text, file) {...}
@@ -26,11 +26,11 @@ class MessageList extends React.Component { | |||
let files = Array.from(event.dataTransfer.files); | |||
|
|||
files.forEach(function(file) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
files.forEach(file => {...})
@@ -9,14 +9,14 @@ import ImageFileButton from "static/Chat/MessageForm/FileButton/paperclip.svg"; | |||
class FileButton extends React.Component { | |||
onFileSelect = event => { | |||
event.preventDefault(); | |||
var files = Array.from(event.target.files); | |||
let files = Array.from(event.target.files); | |||
|
|||
files.forEach(function(file) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
files.forEach(file => {...})
@chexex Исправил все предыдущие замечания по стилю кода, удалил ненужный закомментированный код, исправил ошибки линтера.