Skip to content
Snippets Groups Projects
Commit bf11b07a authored by Thomas Fritsch's avatar Thomas Fritsch
Browse files

ajout commentaires et jsdoc

parent 25dba9b2
Branches
No related tags found
No related merge requests found
export default class Router {
static titleElement;
static contentElement;
/**
* Tableau des routes/pages de l'application.
* @example `Router.routes = [{ path: '/', page: pizzaList, title: 'La carte' }]`
*/
static routes = [];
/**
* Affiche la page correspondant à `path` dans le tableau `routes`
* @param {String} path URL de la page à afficher
*/
static navigate(path) {
const route = this.routes.find(route => route.path === path);
if (route) {
// affichage du titre de la page
this.titleElement.innerHTML = `<h1>${route.title}</h1>`;
// affichage de la page elle même
this.contentElement.innerHTML = route.page.render();
}
}
......
......@@ -9,5 +9,5 @@ const pizzaList = new PizzaList([]);
Router.routes = [{ path: '/', page: pizzaList, title: 'La carte' }];
Router.navigate('/'); // affiche une page vide
pizzaList.pizzas = data;
pizzaList.pizzas = data; // appel du setter
Router.navigate('/'); // affiche la liste des pizzas
......@@ -2,13 +2,19 @@ import Component from '../components/Component.js';
import PizzaThumbnail from '../components/PizzaThumbnail.js';
export default class PizzaList extends Component {
#pizzas;
#pizzas; // propriété privée
constructor(pizzas) {
super('section', { name: 'class', value: 'pizzaList' });
this.pizzas = pizzas;
}
/**
* setter de la liste des pizzas.
* Génère autant de composants `PizzaThumbnail` que de pizzas dans le tableau
* et les stocke dans `this.children`
* @param {Array} value Tableau d'objets pizza à afficher
*/
set pizzas(value) {
this.#pizzas = value;
this.children = this.#pizzas.map(pizza => new PizzaThumbnail(pizza));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment