I am trying to understand how the MVP pattern works using a simple example.
I want to show the box content when the user clicks a button.
function reveal(number){
let content;
if(number==1) content = "candy"
else if(number==2) content = "chicken"
else content = "pencil"
document.getElementById("box").innerHTML = "It's a " + content
}
<button onclick="reveal(1)"> box 1</button>
<button onclick="reveal(2)"> box 2</button>
<button onclick="reveal(3)"> box 3</button><br>
<h3 id="box"> </h3>
YES, I do know it is not the best idea to use such a complicated pattern for this snippet code. I just think this example would be really easy to understand.
Now my questions:
- Should I put the logic (if...elseif..) in the presenter or in the model?
- For Question 1, If I put the logic in the presenter, does that mean that the model will be useless?
Aucun commentaire:
Enregistrer un commentaire