lihaoyi / hands-on-scala-js

Better documentation for Scala.js
142 stars 52 forks source link

Minor changes to weatherapp...? #35

Open murmelsson opened 8 years ago

murmelsson commented 8 years ago

The Hands-On Scala.js tutorial is really good. But the weatherapp could be changed as follows (if you like):

[1] Mention that it's worth adding the line: import scalajs.js
(Maybe this need is due to some amateur mistake [e.g. omitting extends in class defn?] by the unskilled issue-raiser himself, but anyway that import solved the rash of syntax errors around js.JSON.parse , js.Array , etc)

[2] IDE was complaining that .runNow is deprecated and should be replaced by .queue - i.e. change: import scala.scalajs.concurrent.JSExecutionContext.Implicits.runNow to import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue

[3] Though it's no big deal getting an API key from openweathermap.org (takes 2 minutes max to register), you could change the code in two places... [3a] replace ".com" with ".org" in:

p(
      "Enter the name of a city to pull the ",
      "latest weather data from api.openweathermap.com!"
    ),

[3b] change the URL querybuilding to sth like:

    def fetchWeather(query: String) = {
      val searchUrl =
        "http://api.openweathermap.org/data/" +
          "2.5/find?type=like&mode=json&q=" +
          query + "&APPID=" + "6ce0e1********************748ec3"   //<- replace with your actual API-key 

(the idea being that the //-comment encourages the padawans to make the relevant string-substitution)