Table of Content
Refactoring again
This refactoring moves the data checking back to the model module. What app controller needs should be just the essential data, Rain or Sunny.
Thin controller approach.
And the model now handles the data.
1;(function($){ 2 var app = this.app = this.app || {}; 3 4 app.model = { 5 fetch: function(query, callback) { 6 $.getJSON('http://api.openweathermap.org/data/2.5/weather?q=' + query + '&callback=?', function(data){ 7 var code = data.weather[0].id + ""; // force to string 8 if (code[0] === '5') { // rainy code all start at 5 9 callback('rain'); 10 } else { 11 callback('sunny'); 12 } 13 }); 14 } 15 } 16 17}).call(this, jQuery);
What’s next? We’re going to take a look at “Getting weather from location”.