In last video we set up our stream reducer to handle fetching a stream creating a stream and editing
a stream.
In each case we wrote out the same exact code.
So now in this video we're going to start to look at some of the more challenging cases.
The cases in which we get a list of records back from our API and we want to merge all those different
records into our object in one go.
We'll also take a look at how we're going to delete a individual record out of that object as well.
So let's first do deleting a record because it's the little bit easier of the two.
Now we kind of already spoke about how we would delete a record out of a object when we're making use
of reducer.
So if we want to remove a property from an object that's what we're trying to do here we could make
use of the omit function from the load ash library.
So if we under install load ash we can then call omit pass in the state object as the first argument
and then as a second argument we pass in a string of the key that we want to remove.
Now in our case our keys our IDs of each stream.
So that's the second argument we would just pass and the idea of the string that we want to remove that
odd object.
And that's pretty much it.
We are good to go.
Now I want to also remind you that when we are deleting a stream or action creator inside the actions
index dodgiest file is dispatching an action with the ID on the payload property.
So before the payload contain our entire stream object in every case right here right here right here
we always had the entire stream object on the pallet property but with delete stream.
Things are different.
We have a payload of just the ID by itself.
OK.
So with that in mind we're going to first install load ASH and then wire up an omit statement inside
a very douceur so to install loadout are going to flip back over to my application running inside my
terminal.
Well hit Control C as usual and I'll do an NPM install dash dash Save Load ash.
All right so while that goes I'll flip back over to my stream reducer at the top.
I'm going to import underscore from Lotus and now inside my reducer I'm going to add on a new case of
delete stream and so in this case I'm going to return underscore.
Omit my entire state object and I'm going to tell it what key I want to drop off that object in this
case it's going to be action dot payload.
Now again we do not have to add in the ID here.
No ID.
The reason for that is what we just discussed two seconds ago when we dispatch an action of type.
Delete stream.
The payload is the ID itself.
So we do not have to reference a dot ID property.
OK so that's pretty much it right there.
Now the nice thing about omit is that omit is not going to change the original state object.
Instead it creates a new object with all the properties from states without whatever we passed in as
the action not payload.
So there's no need in this case to create a new object on spread in state and do all that stuff that
you're used to.
I guess that's how we're going to handle deleting a stream.
Now let's save this.
We'll take another quick pause when we come back the next section.
We're going to handle our last case which is to take a list of records or an array of records and merge
them all into our state object in one go so quick break and I'll see you in just a minute.