Skip to content

lesson5#6

Open
ArchibaldovRPtech wants to merge 2 commits intomainfrom
lesson5
Open

lesson5#6
ArchibaldovRPtech wants to merge 2 commits intomainfrom
lesson5

Conversation

@ArchibaldovRPtech
Copy link
Copy Markdown
Owner

В методе showCartEmpty() не смог получить актуальные данные о массиве cartItems. они почемуто устаревшие. и поэтому заглушка "корзина пуста" работает не корректно.

Comment thread js/main.js Outdated
console.log('error');
}
});
this.showCartEmpty();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Тут как и в методе удаления проблема с последовательностью вызовов. Вы вызываете метод getJson - это асинхронный метод, то есть удаление товаров произойдет только в его обработчике, а у вас showCartEmpty вызывается по коду одновременно с getJson. То есть чтобы все заработало, надо просто вызывать showCartEmpty в конце обработчика асинхронности (после if else блока на строке 34, но важно чтобы вызов был в обработчике then)

Comment thread js/main.js Outdated
if (!regexp.test(product.product_name)) {
product.filtered = true;
} else {
delete product.filtered;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Все эти свойства фильтеред также будут попадать и в корзину, если добавлять отфильтрованные товары. Не могу сказать что это прямо супер критично, но стоит все-таки поискать обход. Чтобы сохранить то, что у вас есть я бы предложил такой обход. Форма не вызывает метод filter, у вас просто будет вычисляемое значение getRegex, которое будет каждый раз при изменении поля ввода (и значения в searchMsg) создавать и возвращать новый регуляр (return newRegExp(this.searchMsg, 'i')). :class="{invisible:el.filtered}" а в html вам надо будет поменять условие для класса - вместо el.filtered надо написать getRegex.test(el.product_name).

Comment thread js/main.js Outdated
}
},
toggleInvisible() {
this.isInvisibleCart ? this.isInvisibleCart = false : this.isInvisibleCart = true;
Copy link
Copy Markdown

@AndrewRimsky AndrewRimsky Jan 28, 2021

Choose a reason for hiding this comment

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

это тоже самое, что и this.isInvisibleCart = !this.isInvisibleCart, только намного сложнее воспринимается

Comment thread js/main.js Outdated
},
toggleInvisible() {
this.isInvisibleCart ? this.isInvisibleCart = false : this.isInvisibleCart = true;
this.showCartEmpty();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Вы постоянно вызываете этот метод, я бы задумался о вычисляемом значении, которое само следит за данными и возвращает необходимое состояние.

Comment thread js/main.js Outdated
this.showCartEmpty();
},
showCartEmpty() {
if (this.cartItems != undefined && this.cartItems.length > 0) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Проверка this.cartItems != undefined - во первых она не строгая (!== надо), второе она не нужна - такой ситуации не может быть, в картИтемс всегда массив. Ну и последнее, это сравнение равносильно просто if (this.cartItems && this.cartItems.length > 0)

поиск
заглушка "корзина пуста"
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.

2 participants