-
-
Save ramiresnas/8072fe976c6341791be10ef33c022de8 to your computer and use it in GitHub Desktop.
Como mostrar a view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// View.js | |
class View{ | |
constructor(selector){ | |
this.element = document.querySelector(selector) | |
} | |
template(model){ | |
throw new Error("abstract method must be override") | |
} | |
update(model){ | |
this.element.innerHTML = this.template(model) | |
} | |
} | |
//MemberView.js | |
class MemberView extends View{ | |
constructor(selector){ | |
super(selector) | |
} | |
template(member){ | |
return `<h1> Ramires </h1> | |
<a href="#logout" onClick="loginController.logOut(event)"> | |
logout | |
</a> | |
` | |
} | |
} | |
//Member Controller | |
class MemberController{ | |
constructor(selector){ | |
//o array passado em branco, deve ser um array com nomes de todos os métodos ou atributos da classe | |
// Member que devem ser observados, quando eles sofrerem alguma alteração, a view se atualiza automaticamente | |
this.member = new Bind(new Member(),new MemberView(selector),[]) | |
} | |
} | |
//index.html | |
... | |
<div id="member"> </div> | |
<script> | |
const memberController = new MemberController("#member") | |
</script> | |
.... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment