1 00:00:00,680 --> 00:00:05,670 In last video we set up our stream reducer to handle fetching a stream creating a stream and editing 2 00:00:05,700 --> 00:00:06,590 a stream. 3 00:00:06,780 --> 00:00:09,000 In each case we wrote out the same exact code. 4 00:00:09,170 --> 00:00:12,730 So now in this video we're going to start to look at some of the more challenging cases. 5 00:00:12,810 --> 00:00:17,490 The cases in which we get a list of records back from our API and we want to merge all those different 6 00:00:17,490 --> 00:00:19,720 records into our object in one go. 7 00:00:20,040 --> 00:00:24,620 We'll also take a look at how we're going to delete a individual record out of that object as well. 8 00:00:24,640 --> 00:00:28,800 So let's first do deleting a record because it's the little bit easier of the two. 9 00:00:28,830 --> 00:00:33,720 Now we kind of already spoke about how we would delete a record out of a object when we're making use 10 00:00:33,720 --> 00:00:34,440 of reducer. 11 00:00:34,530 --> 00:00:38,790 So if we want to remove a property from an object that's what we're trying to do here we could make 12 00:00:38,790 --> 00:00:42,740 use of the omit function from the load ash library. 13 00:00:42,750 --> 00:00:48,930 So if we under install load ash we can then call omit pass in the state object as the first argument 14 00:00:49,170 --> 00:00:53,440 and then as a second argument we pass in a string of the key that we want to remove. 15 00:00:53,610 --> 00:00:57,090 Now in our case our keys our IDs of each stream. 16 00:00:57,090 --> 00:01:00,810 So that's the second argument we would just pass and the idea of the string that we want to remove that 17 00:01:00,830 --> 00:01:01,760 odd object. 18 00:01:01,890 --> 00:01:02,630 And that's pretty much it. 19 00:01:02,640 --> 00:01:04,050 We are good to go. 20 00:01:04,050 --> 00:01:10,560 Now I want to also remind you that when we are deleting a stream or action creator inside the actions 21 00:01:10,590 --> 00:01:16,580 index dodgiest file is dispatching an action with the ID on the payload property. 22 00:01:17,420 --> 00:01:22,910 So before the payload contain our entire stream object in every case right here right here right here 23 00:01:23,180 --> 00:01:27,530 we always had the entire stream object on the pallet property but with delete stream. 24 00:01:27,560 --> 00:01:28,510 Things are different. 25 00:01:28,520 --> 00:01:32,120 We have a payload of just the ID by itself. 26 00:01:32,120 --> 00:01:32,320 OK. 27 00:01:32,330 --> 00:01:37,580 So with that in mind we're going to first install load ASH and then wire up an omit statement inside 28 00:01:37,640 --> 00:01:42,200 a very douceur so to install loadout are going to flip back over to my application running inside my 29 00:01:42,200 --> 00:01:42,830 terminal. 30 00:01:42,950 --> 00:01:49,340 Well hit Control C as usual and I'll do an NPM install dash dash Save Load ash. 31 00:01:49,340 --> 00:01:54,070 All right so while that goes I'll flip back over to my stream reducer at the top. 32 00:01:54,080 --> 00:02:01,550 I'm going to import underscore from Lotus and now inside my reducer I'm going to add on a new case of 33 00:02:01,610 --> 00:02:07,500 delete stream and so in this case I'm going to return underscore. 34 00:02:07,540 --> 00:02:14,500 Omit my entire state object and I'm going to tell it what key I want to drop off that object in this 35 00:02:14,500 --> 00:02:17,560 case it's going to be action dot payload. 36 00:02:17,560 --> 00:02:20,350 Now again we do not have to add in the ID here. 37 00:02:20,380 --> 00:02:21,550 No ID. 38 00:02:21,550 --> 00:02:26,720 The reason for that is what we just discussed two seconds ago when we dispatch an action of type. 39 00:02:26,710 --> 00:02:27,410 Delete stream. 40 00:02:27,430 --> 00:02:29,650 The payload is the ID itself. 41 00:02:29,650 --> 00:02:32,540 So we do not have to reference a dot ID property. 42 00:02:34,250 --> 00:02:36,500 OK so that's pretty much it right there. 43 00:02:36,500 --> 00:02:41,000 Now the nice thing about omit is that omit is not going to change the original state object. 44 00:02:41,000 --> 00:02:46,760 Instead it creates a new object with all the properties from states without whatever we passed in as 45 00:02:46,760 --> 00:02:48,080 the action not payload. 46 00:02:48,080 --> 00:02:52,670 So there's no need in this case to create a new object on spread in state and do all that stuff that 47 00:02:52,670 --> 00:02:53,860 you're used to. 48 00:02:53,980 --> 00:02:56,600 I guess that's how we're going to handle deleting a stream. 49 00:02:56,630 --> 00:02:57,640 Now let's save this. 50 00:02:57,640 --> 00:03:00,210 We'll take another quick pause when we come back the next section. 51 00:03:00,290 --> 00:03:06,350 We're going to handle our last case which is to take a list of records or an array of records and merge 52 00:03:06,350 --> 00:03:11,540 them all into our state object in one go so quick break and I'll see you in just a minute.