-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented basic mvc architecture and dummy async API request
- Loading branch information
Eleazar Meza
committed
Feb 6, 2020
1 parent
e0899c6
commit 6cec505
Showing
9 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# MacOS | ||
.DS_Store | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* { | ||
color: red; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class WeatherController { | ||
constructor(weatherModel, weatherView) { | ||
this.weatherModel = weatherModel; | ||
this.weatherView = weatherView; | ||
this.weatherModel.updated.addListener(this.weatherView.update); | ||
} | ||
|
||
run() { | ||
this.weatherView.render(); | ||
this.weatherModel.get(); | ||
} | ||
} | ||
|
||
export default WeatherController; |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Weather from './models/weather'; | ||
import WeatherView from './views/weather_view'; | ||
import WeatherController from './controllers/weather_controller'; | ||
|
||
const weather = new Weather('Dolartoday'); | ||
const weatherView = new WeatherView; | ||
const app = new WeatherController(weather, weatherView); | ||
|
||
app.run(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Event { | ||
constructor(sender) { | ||
this.sender = sender; | ||
this.listeners = []; | ||
} | ||
|
||
addListener(listener) { | ||
this.listeners.push(listener); | ||
} | ||
|
||
notify(args) { | ||
this.listeners.forEach(listener => listener(this.sender, args)); | ||
} | ||
} | ||
|
||
export default Event; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Event from './event'; | ||
|
||
class Weather { | ||
constructor(location) { | ||
this.location = location; | ||
this.updated = new Event(this); | ||
} | ||
|
||
get() { | ||
fetch('https://s3.amazonaws.com/dolartoday/data.json', { mode: 'cors' }) | ||
.then(response => response.json()) | ||
.then(data => { this.updated.notify(data['USD']['dolartoday']); }); | ||
} | ||
|
||
changeLocation(location) { | ||
this.location = location; | ||
this.get(); | ||
} | ||
} | ||
|
||
export default Weather; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class WeatherView { | ||
constructor() { | ||
|
||
} | ||
|
||
update(weather, response) { | ||
document.body.innerHTML = weather.location + ': ' + response; | ||
} | ||
|
||
render() { | ||
document.body.innerHTML = 'Plz wait...'; | ||
} | ||
} | ||
|
||
export default WeatherView; |
This file contains 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