Skip to content

Commit

Permalink
test4 fix merge pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ershegm committed Apr 14, 2024
1 parent 6047947 commit eac4033
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 46 deletions.
99 changes: 68 additions & 31 deletions src/framework/view/abstract-view.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,68 @@
import {
render,
RenderPosition
} from './render.js';
import TripInfoView from './view/create-trip.js';
import FiltersView from './view/create-filter.js';
import PointsPresenter from './presenter/board-presenter.js';

const tripMainContainer = document.querySelector('.trip-main');
const tripEventsContainer = document.querySelector('.trip-events');
const filtersContainer = tripMainContainer.querySelector('.trip-controls__filters');

import PointsModel from './model/event-points-model.js';
import OffersModel from './model/offers-model.js';
import DestinationsModel from './model/destinations-model.js';

const pointsModel = new PointsModel();
const offersModel = new OffersModel();
const destinationsModel = new DestinationsModel();

const pointsPresenter = new PointsPresenter({
tripEventsContainer,
pointsModel,
offersModel,
destinationsModel
});

render(new TripInfoView(), tripMainContainer, RenderPosition.AFTERBEGIN);
render(new FiltersView(), filtersContainer);

pointsPresenter.init();
import {createElement} from '../render.js';
import './abstract-view.css';

/** @const {string} Класс, реализующий эффект "покачивания головой" */
const SHAKE_CLASS_NAME = 'shake';

/** @const {number} Время анимации в миллисекундах */
const SHAKE_ANIMATION_TIMEOUT = 600;

/**
* Абстрактный класс представления
*/
export default class AbstractView {
/** @type {HTMLElement|null} Элемент представления */
#element = null;

/** @type {Object} Объект с колбэками. Может использоваться для хранения обработчиков событий */
_callback = {};

constructor() {
if (new.target === AbstractView) {
throw new Error('Can\'t instantiate AbstractView, only concrete one.');
}
}

/**
* Геттер для получения элемента
* @returns {HTMLElement} Элемент представления
*/
get element() {
if (!this.#element) {
this.#element = createElement(this.template);
}

return this.#element;
}

/**
* Геттер для получения разметки элемента
* @abstract
* @returns {string} Разметка элемента в виде строки
*/
get template() {
throw new Error('Abstract method not implemented: get template');
}

/** Метод для удаления элемента */
removeElement() {
this.#element = null;
}

/**
* Метод, реализующий эффект "покачивания головой"
* @param {shakeCallback} [callback] Функция, которая будет вызвана после завершения анимации
*/
shake(callback) {
this.element.classList.add(SHAKE_CLASS_NAME);
setTimeout(() => {
this.element.classList.remove(SHAKE_CLASS_NAME);
callback?.();
}, SHAKE_ANIMATION_TIMEOUT);
}
}

/**
* Функция, которая будет вызвана методом shake после завершения анимации
* @callback shakeCallback
*/
33 changes: 18 additions & 15 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import {
render,
RenderPosition
} from './render.js';
import TripInfoView from './view/create-trip.js';
import FiltersView from './view/create-filter.js';
import PointsPresenter from './presenter/board-presenter.js';

const tripMainContainer = document.querySelector('.trip-main');
const tripEventsContainer = document.querySelector('.trip-events');
const filtersContainer = tripMainContainer.querySelector('.trip-controls__filters');

import PointsModel from './model/event-points-model.js';
import OffersModel from './model/offers-model.js';
import DestinationsModel from './model/destinations-model.js';
import PointsPresenter from './presenter/points-presenter.js';
import FiltersPresenter from './presenter/filters-presenter.js';
import TripInfoPresenter from './presenter/trip-presenter.js';
import MockService from './service/mock-service.js';

const mockService = new MockService();
const pointsModel = new PointsModel(mockService);
const offersModel = new OffersModel(mockService);
const destinationsModel = new DestinationsModel(mockService);

const pointsContainer = document.querySelector('.trip-events');
const pointsModel = new PointsModel();
const offersModel = new OffersModel();
const destinationsModel = new DestinationsModel();

const pointsPresenter = new PointsPresenter({
pointsContainer,
tripEventsContainer,
pointsModel,
offersModel,
destinationsModel
});

const filtersPresenter = new FiltersPresenter({pointsModel});
const tripInfoPresenter = new TripInfoPresenter();
render(new TripInfoView(), tripMainContainer, RenderPosition.AFTERBEGIN);
render(new FiltersView(), filtersContainer);

pointsPresenter.init();
filtersPresenter.init();
tripInfoPresenter.init();

0 comments on commit eac4033

Please sign in to comment.