1 00:00:02,140 --> 00:00:06,690 In the last lecture we used updateObject, this utility function. 2 00:00:06,690 --> 00:00:13,830 Now there's one other feature we also share across multiple files and hence it would make sense to outsource 3 00:00:13,830 --> 00:00:14,350 it, 4 00:00:14,670 --> 00:00:16,940 I'm talking about the validation logic, 5 00:00:17,100 --> 00:00:18,500 checkValidity. 6 00:00:18,570 --> 00:00:22,820 It's the same method in the auth container and the contact data container 7 00:00:23,070 --> 00:00:30,690 so it makes sense to grab checkValidity and put it into our shared folder into the utility.js file 8 00:00:30,690 --> 00:00:31,680 for example, 9 00:00:31,710 --> 00:00:36,300 you could also create a new validation.js file, whatever you want. 10 00:00:36,300 --> 00:00:38,360 So I'll use checkValidity, 11 00:00:38,490 --> 00:00:42,330 of course it's no longer a method here instead it's a function 12 00:00:42,330 --> 00:00:46,910 so let's export it as an arrow function which expects two arguments. 13 00:00:46,960 --> 00:00:52,250 This is how simple you restructure it, export const equal sign and an error 14 00:00:52,650 --> 00:00:58,380 and inside the function, nothing has to change because we're only working with the function arguments 15 00:00:58,380 --> 00:01:01,050 in there, as we should in a good function. 16 00:01:01,380 --> 00:01:07,710 So we can now use checkValidity in the contact data and the auth container, let's start the auth container 17 00:01:07,710 --> 00:01:09,620 because there I just removed it 18 00:01:09,750 --> 00:01:16,370 and for that, I'll import it from the utility file where I also imported updateObject. 19 00:01:16,770 --> 00:01:24,030 And I now simply need to replace my call to this.checkValidity with just checkValidity which I just 20 00:01:24,060 --> 00:01:26,200 added the import to and that's all 21 00:01:26,250 --> 00:01:30,840 and this makes this file a bit leaner and removes this unnecessary code duplication. 22 00:01:31,140 --> 00:01:33,320 Now let's do the same for the contact data, 23 00:01:33,540 --> 00:01:39,960 there I'll also import checkValidity from the utility file and then in the place where I do use it 24 00:01:39,960 --> 00:01:46,530 with this checkValidity, I will simply call just checkValidity 25 00:01:46,530 --> 00:01:50,050 and of course that means I can now remove the checkValidity method. 26 00:01:50,190 --> 00:01:54,130 Let's save both files and let's see if this still works. 27 00:01:54,300 --> 00:01:58,490 If we go back to the application and we start building a burger, 28 00:01:58,620 --> 00:02:01,480 let's have a look at our contact data there. 29 00:02:01,890 --> 00:02:06,580 If I empty this, validation still seems to work fine 30 00:02:06,660 --> 00:02:08,270 so everything still works 31 00:02:08,340 --> 00:02:14,290 but now of course, we greatly improved the code by outsourcing checkValidity into its own file.