Giter VIP home page Giter VIP logo

weather-10's Introduction

React weather app

This app lets you search for different cities, and provides you with a set of graphs for temperature, pressure and humidity for the upcoming 5 days. Every search will result in an additional item on the list of graphs, so the weather in different cities are easily compared.

screenshot

##Udemy Modern React with Redux part 5##

boilerplate: https://github.com/StephenGrider/ReduxSimpleStarter

###Action creator###

We introduced an action creator in the form of fetchWeather. We have a constant for our action type that allows us to specify the action type in our action and in our reducer swell. It cuts down on the ability for us to make typo’s compared to using a pure string.

###Middleware: redux-promise###

Next interesting thing was the use of middleware, specifically redux-promise. We use redux-pormise to handle a promises that we receive, while using AXIOS to make our AJAX request. This middleware is especially helpful because it automatically detects that we provide it a payload of a promise. It stops that action an then waits for the promise to resolve. Once the promise resolves it takes the data coming back from the request, sticks it on the payload property and sents the action on to all of the reducers of our application. So although we wrote an AJAX request here that inherently involves asynchronous code, we don’t really have to think about the asynchronous nature of our code at all; we just write some code where an action is created, it flows to the reducers and we don’t have to worry about any promises or callbacks. So a very handy library to have around!

code-snippet

###Reducers###

Next we covered reducers, specifically how we always have to strive to avoid mutating our state! Remember, we never want to do something like state.weather.push!! We never want to modify our state directly. Instead, we return a new object that will take the place of our existing state.

code-snippet

For an array we also covered the use case of destructuring an existing array. So that’s what was happening here at:

	[ action.payload.data, ...state]

We were taking an existing array, flattening it out to create a new one.

###Libraries: Sparklines & Google Maps###

Finally we covered two very useful libraries that really bring your application to the next level: the sparklines library and Google Maps. Sparklines is fantastically easy to use. The hardest part was figuring out how to get our weather data in there. But once figured out, making our sparkling-chart was very straight forward. Sparklines are generally designed to be smaller charts. They’re really intended give the reader a lot of information at just a glance. It doesn’t have the ability to add axes or anything like that, but we addressed that by adding the the average function and also passing in the units as an additional property

code-snippet

Then we also made use of the react Google Maps component which makes placing a Google map in you application super easy. All we had to do is provide the container element the google map element along with a defaultCenter longitude and lattitude.

code-snippet

Finally we made sure to abstract both these components out ( chart.js and google_maps.js) to their own separate components, which means that if we had other areas in our application that needed a chart of a map we can reuse them in a snap.

###To start this app###

	> git clone [email protected]:tlohstroh/weather.git
	> cd weather
	> npm install
	> npm start

Sign up at http://openweathermap.org to obtain your own api key and create config.js in the root directory of the app with the folowing content:

	> export const API_KEY = "your key"

weather-10's People

Contributors

jsdelivrbot avatar tlohstroh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.