In the last section we put together our actions index not just file.
It's all done now so I'm going to close that thing up.
And then inside of my reducers directory I'm going to create a new file called as you might guess index.
Yes like so so inside of here we're going to write out both of our reducers that we need and then we're
going to eventually export them from this file so that they can be used somewhere else inside of our
project.
Now we're going to have our two reducers first saw one that is going to return a static list of songs
and then the second one that is going to allow our user to select a very specific song once they click
on the select button so we'll first put together our static list of songs reducer.
So back inside of my code editor I'm going to say Konst songs reducer and then I'll assign this an arrow
function like so so as I mentioned this is going to have a static list of songs it's a static array
so there will be no arguments.
We need to worry about here we don't need to look at any actions because we never expect to change it
in any way shape or form.
As I mentioned a little bit ago it's really overkill to put this list of songs into introducer but I
just want to show you how we could really completely redux ify so to speak and application.
So from this producer I'm going to return an array of objects where every object represents a different
song.
Well you will say that every song has a title property.
So maybe I'll give this first song a title like I don't know what songs are there.
Even these days.
Let's let's look at really quick.
About 90s songs.
Ok got Backstreet Boys.
Oh this is awful.
Ok whatever.
No Scrubs in Macarena.
That's what we're doing.
So no scrubs on.
I'll give this thing a duration of four minutes five seconds and then I'll put on another song here
I'll do the Macarena for the duration of I don't know two minutes and 30 seconds and we'll do two more
really quickly.
This is awful.
OK.
All star with a duration of three minutes 15 seconds.
And then one more write Backstreet Boys I guess I want it that way.
I don't really but whatever.
And I'll give it a duration of one minute forty five seconds.
All right.
So that's it.
That is our song data right there does it my guess.
Totally fixed totally static totally randomized more or less with fixed durations.
Now the only reason I made these durations strings was just to expect or express a duration easily with
like our minutes Colin.
And then the second.
All right.
So there's our songs producer.
So now we're going to work on the more interesting reducer the reducer for selecting a specific song.
So now we're going to have to really think about how to put this one together.
All flip back over and underneath the existing reducer.
I'll put my next one and I'll say Let's call this what do we have a selected song reducer.
This is going to be called with a first argument of the currently selected song.
And so I'm going to refer to that as selected song or defaulted to be no to indicate that when our application
first starts up we are not going to have any selected song it's just nil.
And then as a second argument will be our action object so we're going to look at that action object.
We're going to inspect its type if its type is song selected.
Then we're going to return.
It's Paillard property because remember our select song action over here has a payload of the song that
the user is trying to select.
So I'm going to say if action not type equals and remember that will be our one action type song underscore
selected.
And if that is the case then I'm going to return.
Action Daut payload.
And if that's not the case then I will return whatever are currently selected song is now one thing
I want to mention here is that as we have written out this producer we only have one action creator
inside of our application right now but we've still written out an if statement assuming that we might
have other actions at some point in the future.
So technically for our current app we don't really need this if statement because we're only ever going
to see actions of type songs selected.
However just to be kind of hygenic and make sure that if we ever expand our application in the future
with additional actions and additional types we're not going to somehow ruin our code here and break
our selected song we're douceur.
All right.
So that's it for these to reduce hours we have to put together.
Now let's take a quick pause right here when we continue in the next section we're going to wire these
things up together with that combine reducers call that we had seen previously and then we'll start
to wire up the provider inside of our application.
So quick break and I'll see you in just a minute.