[S4L3] Components 1 Flashcards

1
Q

Warum benutzt man Components?

A
  • Da große Projekte oft wiederholende Codeteile besitzen
  • Weniger Komplexität/Fehler/Wartung
  • Man entspricht dem DRY-Prinzip besser
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Was ist eine Component?

A

-Ein wiederverwendbares Stück Software, welches ein Teile eines großen ganzen sein kann

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Wie schreibt man Components in CSS?

A
@import custom-btn.less
.custom-btn {
  // custom styles here
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Wie schreibt man Components in Javascript?

A
const buttons = document. querySelectorAll('.button');
class Button {
  constructor(element){
    this. element = element;
    this. element.addEventListener('click', () => { this. buttonClick() });
  }
  button Click(event){
    console. log('button clicked!');
  } 
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Wie erschafft man Components im Javascript DOM?

RETURN!

A
//Schritt3: Build out the Panel base class
class Panel {
  constructor(panel) {
    this.panel = panel:
    this.panelButtons = this.panel.querySelector('.oanel-buttons');
    this.panelBtnOpen = this.panel .querySelector('.oanel-btn-open');
    this.panelBtnClose = this.panel .querySelector('.oanel-btn-close');
this.panelContent = this.panel .querySelector('.oanel-content');

this.panelButtons.addEventListeners(‘click’, this.togglePanel.bind(this));

//BESSER! , this not bound to the arrow so the compiler looks it up under the constructor
this.panelButtons.addEventListeners('click', () => this.togglePanel());

}
togglePanel() {
this.panelBTnOpen.classList.toggle(‘hide-btn’);
this.panelBTnClose.classList.toggle(‘hide-btn’);
this.panelBTnOpen.classList.toggle(‘hide-btn’);
this.paneContent.classList.toggle(‘toggle-on’);
}
}

//Schritt1: Get the original DOM elements
const panels = document. querySelectorAll('.panel');
//Schritt2: Return a newly constructed DOM element
panels. forEach(function(panel){
return new Panel(panel);
});
How well did you know this?
1
Not at all
2
3
4
5
Perfectly