1 00:00:00,760 --> 00:00:05,440 In the last section we continued developing this analogy to better understand how redux works internally 2 00:00:05,980 --> 00:00:06,640 in this video. 3 00:00:06,640 --> 00:00:10,570 I want to get a better understanding of what is going on with this form right here. 4 00:00:10,570 --> 00:00:15,260 Remember we had said that a customer is going to fill out a form handed off to the former receiver. 5 00:00:15,370 --> 00:00:19,180 The pharmacy will make a copy of it and then hand it off to each department. 6 00:00:19,180 --> 00:00:23,840 Along with that department's little slice of data. 7 00:00:23,850 --> 00:00:24,520 All right. 8 00:00:24,600 --> 00:00:31,290 So we're going to imagine that every form that gets filled out by a customer is going to have two different 9 00:00:31,290 --> 00:00:32,080 parts. 10 00:00:32,190 --> 00:00:36,990 It's going to be essentially a sheet of paper with some fields at the top that the customer has to write 11 00:00:36,990 --> 00:00:41,890 in and then a field at the bottom that has more information that the customer has to enter. 12 00:00:41,940 --> 00:00:45,520 So we'll say that every form has a type assigned to it. 13 00:00:45,600 --> 00:00:50,180 The type of the form essentially declares what the purpose of the form is. 14 00:00:50,190 --> 00:00:56,340 Remember our insurance company has two broad objects that a customer is going to use to interact with 15 00:00:56,340 --> 00:00:56,740 it. 16 00:00:56,790 --> 00:01:00,950 A customer can create a policy and a customer can also create a claim. 17 00:01:01,230 --> 00:01:06,450 So chances are that we would want to have different forms for creating a policy and for creating a claim 18 00:01:06,450 --> 00:01:07,500 as well. 19 00:01:07,530 --> 00:01:11,780 So we'll do it we'll declare it the purpose of each form as a type. 20 00:01:11,820 --> 00:01:17,130 At the very top of each form and then inside the body of the form which we might refer to as the payload 21 00:01:17,400 --> 00:01:22,190 We'll have the customer write down some information relevant to them and what they're trying to do. 22 00:01:22,500 --> 00:01:27,120 So in the case that a customer is trying to create a claim and get some money from the insurance company 23 00:01:27,420 --> 00:01:31,320 we might want the customer to give us their name so that we can identify them. 24 00:01:31,410 --> 00:01:36,430 And we also might want the customer to tell us how much money they think that they should be paid which 25 00:01:36,420 --> 00:01:40,870 you might refer to as say our claim amount now in total. 26 00:01:40,880 --> 00:01:44,980 I think that our company would need three different types of forms. 27 00:01:45,200 --> 00:01:48,570 We would need a form for a customer to create a policy. 28 00:01:48,800 --> 00:01:53,510 We would need a form for them to create a claim and then chances are that eventually a customer would 29 00:01:53,510 --> 00:01:56,110 not want to be a member of our insurance company anymore. 30 00:01:56,210 --> 00:02:00,170 And so they might submit a another form to delete their active policy. 31 00:02:00,170 --> 00:02:06,770 So in total three types type 1 Type 2 type 3 and each different type of form it's going to have a different 32 00:02:07,190 --> 00:02:09,710 set of information inside its payload. 33 00:02:09,710 --> 00:02:14,900 In one case to create a policy the customer might need to provide their name along with some initial 34 00:02:14,900 --> 00:02:19,550 money that they are going to pay to us when they want to create a claim they are going to give us their 35 00:02:19,550 --> 00:02:22,060 name and tell us how much money they want to get. 36 00:02:22,220 --> 00:02:26,330 And then when they want to delete a policy chances are they just need to tell us their name so that 37 00:02:26,330 --> 00:02:32,370 we can go into our big list of people who have policies and just remove them from that list. 38 00:02:32,450 --> 00:02:32,620 OK. 39 00:02:32,630 --> 00:02:37,740 So we have a better idea of forms and departments and this entire flow. 40 00:02:37,880 --> 00:02:44,660 Well it sounds very quickly walked through the process of how each of these different departments would 41 00:02:44,660 --> 00:02:47,370 process each of those different form types. 42 00:02:47,420 --> 00:02:51,020 So in this step right here in the next couple of diagrams things are going to get a little bit more 43 00:02:51,020 --> 00:02:51,630 detailed. 44 00:02:51,740 --> 00:02:57,230 But remember we're going to eventually write out some code to model this entire insurance company. 45 00:02:57,230 --> 00:03:01,220 And so it is important that you understand what is going on internally inside of each of these departments 46 00:03:01,460 --> 00:03:04,270 so that we can actually write some code to model this stuff. 47 00:03:04,660 --> 00:03:04,920 OK. 48 00:03:04,940 --> 00:03:12,830 So let's imagine that our 4 receiver gets a form from a customer and this the purpose of this form is 49 00:03:12,830 --> 00:03:19,640 possibly to create a new claim for receivers are going to take that form and hand it off to the claims 50 00:03:19,670 --> 00:03:25,460 history department whose job is to record a list of all the different claims that have ever been created 51 00:03:26,570 --> 00:03:28,590 when the form receiver hands off that form. 52 00:03:28,610 --> 00:03:31,010 They're also going to get the claims history department. 53 00:03:31,010 --> 00:03:35,600 That list of all the different claims that have been created previously because remember the idea here 54 00:03:35,600 --> 00:03:41,870 now is that we want to have all of our data be centralized inside of this outside data store and only 55 00:03:41,870 --> 00:03:49,190 when a department is given a form are they going to be given their little data set right here and then 56 00:03:49,190 --> 00:03:53,720 it would be up to the claims history department to update that little list of claims history and then 57 00:03:53,750 --> 00:04:02,250 afterwards go and update the claims history list inside of our entire company data so internally the 58 00:04:02,250 --> 00:04:07,200 claims history department is going to take a list of all previous claims in the form and then they're 59 00:04:07,200 --> 00:04:12,870 going to look at the form and they're going to say OK is the form that is coming in trying to create 60 00:04:12,930 --> 00:04:14,130 a claim. 61 00:04:14,160 --> 00:04:18,280 Remember we had said that every department was going to receive a copy of every form. 62 00:04:18,510 --> 00:04:23,640 So that claims history department needs to look at the form type and decide whether or not the form 63 00:04:23,640 --> 00:04:26,430 is trying to create a claim if it's not trying to create a claim. 64 00:04:26,430 --> 00:04:30,510 Chances are this department doesn't care about it they don't care about policies they just care about 65 00:04:30,510 --> 00:04:31,920 claims. 66 00:04:31,920 --> 00:04:37,200 So if this form is not trying to create a claim no then it claims history department is going to say 67 00:04:37,530 --> 00:04:38,300 I don't care. 68 00:04:38,340 --> 00:04:42,500 Just take that list of claims that you just gave us and we're going to return that. 69 00:04:42,570 --> 00:04:48,600 And so we returned the unchanged list of claims and we can kind of imagine that that would be the step 70 00:04:48,900 --> 00:04:55,080 where the list of claims comes out the other end and goes back to our original company repository of 71 00:04:55,080 --> 00:05:02,960 all data now on the other hand if the form that is coming in is trying to create a claim yes then the 72 00:05:02,960 --> 00:05:08,100 claims history department is going to say OK I need to understand who is trying to create this claim. 73 00:05:08,180 --> 00:05:11,130 So it's going to pull off the payload part of that form. 74 00:05:11,180 --> 00:05:15,440 It's going to add that to the list of claims and then it's going to essentially take that list of claims 75 00:05:15,470 --> 00:05:22,910 and dump it out front in order to make sure that it updates the central repository of claims history 76 00:05:22,970 --> 00:05:24,550 data. 77 00:05:24,560 --> 00:05:25,190 All right. 78 00:05:25,310 --> 00:05:28,640 Now let's go through the same process with the accounting department as well. 79 00:05:29,800 --> 00:05:35,760 So with the accounting department we would have our former Sievert say Hey yeah. 80 00:05:36,010 --> 00:05:38,040 So it just dropped off a form right here. 81 00:05:38,050 --> 00:05:39,220 So here is the form. 82 00:05:39,220 --> 00:05:44,150 And by the way here's also our bag with all of our company money inside of it. 83 00:05:44,150 --> 00:05:50,080 So remember this would in theory be the company money that is stored inside of our central repository 84 00:05:50,080 --> 00:05:50,970 right here. 85 00:05:50,980 --> 00:05:57,230 So the accounting department gets the form along with a bag of all of our company's money. 86 00:05:57,300 --> 00:06:01,710 So then that the accounting department is going to look at that form and they're going to see if the 87 00:06:01,710 --> 00:06:02,940 form is a claim. 88 00:06:03,150 --> 00:06:09,050 If it's a claim then the accounting department is going to pull the payload part off that form they're 89 00:06:09,060 --> 00:06:14,430 going to see how much money the company wants or some of the customer wants as part of the claim. 90 00:06:14,490 --> 00:06:18,990 And let's imagine that the customer is saying that they just got into an accident and they claim that 91 00:06:18,990 --> 00:06:20,810 they need $20. 92 00:06:20,910 --> 00:06:26,230 So the accounting department is going to take that $20 out of the bag and send it off to the customer. 93 00:06:26,610 --> 00:06:30,540 And then after that the accounting department will take the rest of the money in the bag which is now 94 00:06:30,540 --> 00:06:34,650 down to 80 because they just took out 20 and they'll return it from their department so that it can 95 00:06:34,650 --> 00:06:36,940 go back to that central repository. 96 00:06:36,960 --> 00:06:41,370 Now that's not the only type of form that the accounting department probably cares about the accounting 97 00:06:41,370 --> 00:06:47,540 department probably also cares about the case in which someone is trying to sign up for a new policy. 98 00:06:47,820 --> 00:06:52,290 So the accounting department is also going to look for forms of type create policy. 99 00:06:52,590 --> 00:06:58,620 If they get one then remember the create policy form is going to contain some amount of money to initially 100 00:06:58,620 --> 00:06:59,830 sign up for a policy. 101 00:06:59,970 --> 00:07:04,960 So we're going to imagine maybe they include $20 to sign up for a new policy here. 102 00:07:05,010 --> 00:07:10,140 So the accounting department is going to take that money and put it into our big bag of money and return 103 00:07:10,140 --> 00:07:10,430 that. 104 00:07:10,440 --> 00:07:17,040 And now our company balance is now at 120 and then in the final case I don't hear if the person or the 105 00:07:17,040 --> 00:07:21,390 form is not trying to create a claim and not trying to create a policy then they can Department is going 106 00:07:21,390 --> 00:07:25,770 to say I don't care just to turn our bag of money with the original hundred dollars and they're going 107 00:07:25,770 --> 00:07:27,330 to throw it out the other side. 108 00:07:27,750 --> 00:07:29,110 All right so just one more step. 109 00:07:30,410 --> 00:07:34,700 So this is the final foreign type or the final department the policies Department. 110 00:07:34,700 --> 00:07:39,800 So again we're going to imagine the Ford receiver takes the form that was just handed to them by a customer. 111 00:07:39,800 --> 00:07:44,610 They're going to hand it to our policies Department along with our list of everyone who holds a policy. 112 00:07:45,140 --> 00:07:47,710 So the policies Department is going to look at that form. 113 00:07:47,720 --> 00:07:49,140 They're going to look at that type on it. 114 00:07:49,190 --> 00:07:54,680 They're going to say OK is this form the type that is trying to create a policy or end a policy if it's 115 00:07:54,680 --> 00:07:58,580 not then they're going to say oh I don't care about this form and they're going to dump out the original 116 00:07:58,580 --> 00:08:02,280 list of people who have a policy completely unchanged. 117 00:08:02,570 --> 00:08:07,160 But if the form is trying to create a policy or end up policy then they're going to say all right are 118 00:08:07,160 --> 00:08:11,630 they trying to end a policy then I'm going to find their name and take it off that list. 119 00:08:11,690 --> 00:08:16,310 Otherwise if they're trying to create a policy then they're going to take the name off the form and 120 00:08:16,310 --> 00:08:22,130 add it to the list and after they produce this new list over here that says everyone who has a policy 121 00:08:22,460 --> 00:08:28,220 just as before are going to say that that new list of people who have policies is going to go back to 122 00:08:28,220 --> 00:08:31,660 this central repository up here. 123 00:08:31,670 --> 00:08:32,030 All right. 124 00:08:32,030 --> 00:08:35,900 So I know that was an incredible amount of detail but that is it for the analogy. 125 00:08:35,900 --> 00:08:40,600 So I think you now understand the entire flow of what is going on inside of our insurance company. 126 00:08:40,640 --> 00:08:44,420 Remember in total we've got the customer who drops off the form. 127 00:08:44,450 --> 00:08:46,740 The form has a type and a payload. 128 00:08:47,000 --> 00:08:52,280 The form receiver going to make a copy that form handed off to each different department along with 129 00:08:52,310 --> 00:08:55,630 each different departments little slice of company data. 130 00:08:55,670 --> 00:09:00,410 Each department is going to look at the foreign type and decide whether or not it has to process the 131 00:09:00,410 --> 00:09:01,030 form. 132 00:09:01,160 --> 00:09:05,510 If they do they're going to make an update to their little slice of data and then eventually return 133 00:09:05,510 --> 00:09:10,120 it out the other end and send it back to this central company repository. 134 00:09:10,130 --> 00:09:15,110 So now that you understand this kind of analogy here we're going to take another quick pause come back 135 00:09:15,110 --> 00:09:15,820 the next section. 136 00:09:15,850 --> 00:09:21,590 I'm going to tell you exactly how this all relates precisely to the world of redux. 137 00:09:21,590 --> 00:09:21,850 All right. 138 00:09:21,860 --> 00:09:23,790 So quick break and I'll see you in just a minute.