Skip to content

Instantly share code, notes, and snippets.

@ramiresnas
Last active September 23, 2017 13:13
Show Gist options
  • Save ramiresnas/8072fe976c6341791be10ef33c022de8 to your computer and use it in GitHub Desktop.
Save ramiresnas/8072fe976c6341791be10ef33c022de8 to your computer and use it in GitHub Desktop.
Como mostrar a view
// 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