Last active
October 9, 2018 04:41
-
-
Save mbritton/d8286913719a38662271007d4baec25d to your computer and use it in GitHub Desktop.
openweather-apis and n00b mobx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {decorate, observable, action} from 'mobx'; | |
import weather from 'openweather-apis'; | |
class Locations { | |
all = [ | |
{ | |
'id': 'fb3faf1a-1039-49f6-9ced-48dd9b5c1462', | |
'latitude': 33.9434136, | |
'longitude': -84.7758044, | |
'label': '1550 E Paulding Dr, Dallas, GA', | |
'name': 'Mt Tabor Park' | |
}, | |
{ | |
'id': 'b5a039b2-6520-44a8-937d-543f3b2750da', | |
'latitude': 34.0212248, | |
'longitude': -84.7198592, | |
'label': '5690 Old Stilesboro Rd NW, Acworth, GA', | |
'name': 'Allatoona Creek Park' | |
}, | |
{ | |
'id': '85530076-6593-4acb-9107-277bd2ffcecd', | |
'latitude': 34.1615684, | |
'longitude': -84.5419473, | |
'label': '2261 Sixes Rd, Canton, GA', | |
'name': 'Blankets Creek Mountain Bike Trails', | |
}, | |
{ | |
'id': '920b96cd-e2b8-4315-b9a1-726c903cc072', | |
'latitude': 33.9331037, | |
'longitude': -84.8261743, | |
'label': '216 Recreation Dr, Dallas, GA', | |
'name': 'Sara Babb Park' | |
} | |
]; | |
weatherData = []; | |
loadWeather = () => { | |
weather.setLang('eng'); | |
for (let i = 0; i < this.all.length; i++) { | |
weather.setCoordinate(this.all[i].latitude, this.all[i].longitude); | |
weather.setAPPID(''); | |
weather.getAllWeather((err, JSONObj) => { | |
(!err) ? this.setWeather(JSONObj) : console.log('Error: ', err); | |
}); | |
} | |
}; | |
setWeather = action((data) => { | |
this.weatherData.push(data); | |
}); | |
} | |
decorate(Locations, { | |
all: observable, | |
weatherData: observable | |
}); | |
export default new Locations(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment