From 18ac08009e30caac0e24d02978e9bc504ae93323 Mon Sep 17 00:00:00 2001 From: Ksenia Tryapitsyna Date: Sun, 15 Sep 2024 18:12:18 +0300 Subject: [PATCH] feat: add private class fields, add getters instead of functions --- src/model/point-model.js | 18 +++++++++--------- src/presenter/main-presenter.js | 29 +++++++++++++++++------------ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/model/point-model.js b/src/model/point-model.js index 8be0ca4..0634b89 100644 --- a/src/model/point-model.js +++ b/src/model/point-model.js @@ -3,19 +3,19 @@ import { getDestinations } from '../mock/destinations-mock'; import { getOffers } from '../mock/offers-mock'; export default class PointModel { - points = getPoints(); - destinations = getDestinations(); - offers = getOffers(); + #points = getPoints(); + #destinations = getDestinations(); + #offers = getOffers(); - getPoints() { - return this.points; + get points() { + return this.#points; } - getDestinations() { - return this.destinations; + get destinations() { + return this.#destinations; } - getOffers() { - return this.offers; + get offers() { + return this.#offers; } } diff --git a/src/presenter/main-presenter.js b/src/presenter/main-presenter.js index dc4e481..4e247ba 100644 --- a/src/presenter/main-presenter.js +++ b/src/presenter/main-presenter.js @@ -7,25 +7,30 @@ import { render } from '../framework/render'; export default class MainPresenter { - pointsListComponent = new PointListView(); + #pointsListComponent = new PointListView(); + #pointsContainer = null; + #pointModel = null; + #points = []; + #destinations = []; + #offers = []; constructor({pointsContainer, pointModel}) { - this.pointsContainer = pointsContainer; - this.pointModel = pointModel; + this.#pointsContainer = pointsContainer; + this.#pointModel = pointModel; } init() { - this.points = [...this.pointModel.getPoints()]; - this.destinations = [...this.pointModel.getDestinations()]; - this.offers = [...this.pointModel.getOffers()]; + this.#points = [...this.#pointModel.points]; + this.#destinations = [...this.#pointModel.destinations]; + this.#offers = [...this.#pointModel.offers]; - render(new SortingView(), this.pointsContainer); - render(this.pointsListComponent, this.pointsContainer); - render(new EditPoint({point: this.points[0], offers: this.offers, destinations: this.destinations}), this.pointsListComponent.element); - render(new CreatePoint(), this.pointsListComponent.element); + render(new SortingView(), this.#pointsContainer); + render(this.#pointsListComponent, this.#pointsContainer); + render(new EditPoint({point: this.#points[0], offers: this.#offers, destinations: this.#destinations}), this.#pointsListComponent.element); + render(new CreatePoint(), this.#pointsListComponent.element); - for (let i = 1; i < this.points.length; i++) { - render(new PointItemView({point: this.points[i], offers: this.offers, destinations: this.destinations}), this.pointsListComponent.element); + for (let i = 1; i < this.#points.length; i++) { + render(new PointItemView({point: this.#points[i], offers: this.#offers, destinations: this.#destinations}), this.#pointsListComponent.element); } } }