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

Решение задач #4

Merged
merged 9 commits into from
Dec 23, 2024
Merged

Conversation

iKopturevskiy
Copy link
Contributor

No description provided.

@jsru-1
Copy link
Contributor

jsru-1 commented Dec 22, 2024

Добавляю преподавателя (@ShGKme) для код-ревью.

@jsru-1 jsru-1 requested a review from ShGKme December 22, 2024 16:49
@jsru-1
Copy link
Contributor

jsru-1 commented Dec 22, 2024

Решение было обновлено, посмотрим что скажет @ShGKme

@jsru-1
Copy link
Contributor

jsru-1 commented Dec 22, 2024

Решение было обновлено, посмотрим что скажет @ShGKme

Comment on lines 21 to 28
watch([x, y], () => {
watch([pin, x, y], () => {
// Находим метку и изменяем её положение
const map = document.querySelector('.pin')
map.style.left = `${x}px`
map.style.top = `${y}px`
pin.value.left = `${x.value}px`
pin.value.top = `${y.value}px`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этот watch не очень корректный.

Во-первых, в списке его зависимостей есть pin, который и вычисляется внутри этого watch. Vue здесь защищается от бесконечной рекурсии, но изменение pin не может быть причиной изменения pin.

Во-вторых, этот watch реализует pin как вычисляемое свойство. Есть реактивная переменная pin, в которой хранится результат вычисления от x и y. И она всегда обновляется при изменении зависимостей вычисления - x и y. Это классический computed.

Такие свойства нужно реализовывать именно как вычисляемое свойство computed:

  • Это явно. Так pin будет описан именно как вычисляемое значение, а не как самостоятельная переменная с собственным значением
  • Не нужно самостоятельно определять зависимости отслеживания и контролировать корректность списка зависимостей
  • Эффективнее - вычисляемые свойства ленивые и вычисляются только, когда к их значению обращаются

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Понял, исправил

@jsru-1
Copy link
Contributor

jsru-1 commented Dec 23, 2024

Добавляю преподавателя (@ShGKme) для код-ревью.

@jsru-1 jsru-1 requested a review from ShGKme December 23, 2024 15:40
@jsru-1
Copy link
Contributor

jsru-1 commented Dec 23, 2024

Решение было обновлено, посмотрим что скажет @ShGKme

@jsru-1 jsru-1 merged commit a6ebb06 into js-tasks-ru:master Dec 23, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants