Table of Content
Refactoring
This refactoring put DOM manipulation in view. And leave the app controller away from any DOM element.
The model.js
file.
The view.js
file.
The app.js
file.
1;(function(){ 2 var app = this.app = this.app || {}; 3 4 app.model.fetch('Macao,MO', function(data){ 5 console.log(data); 6 var code = data.weather[0].id + ""; // force to string 7 if (code[0] === '5') { // rainy code all start at 5 8 app.view.update('rain'); 9 } else { 10 app.view.update('sunny'); 11 } 12 }); 13 14}).call(this);
What’s next? We’re going to take a look at “Refactoring again”.