In the last lecture we used updateObject, this utility function.
Now there's one other feature we also share across multiple files and hence it would make sense to outsource
it,
I'm talking about the validation logic,
checkValidity.
It's the same method in the auth container and the contact data container
so it makes sense to grab checkValidity and put it into our shared folder into the utility.js file
for example,
you could also create a new validation.js file, whatever you want.
So I'll use checkValidity,
of course it's no longer a method here instead it's a function
so let's export it as an arrow function which expects two arguments.
This is how simple you restructure it, export const equal sign and an error
and inside the function, nothing has to change because we're only working with the function arguments
in there, as we should in a good function.
So we can now use checkValidity in the contact data and the auth container, let's start the auth container
because there I just removed it
and for that, I'll import it from the utility file where I also imported updateObject.
And I now simply need to replace my call to this.checkValidity with just checkValidity which I just
added the import to and that's all
and this makes this file a bit leaner and removes this unnecessary code duplication.
Now let's do the same for the contact data,
there I'll also import checkValidity from the utility file and then in the place where I do use it
with this checkValidity, I will simply call just checkValidity
and of course that means I can now remove the checkValidity method.
Let's save both files and let's see if this still works.
If we go back to the application and we start building a burger,
let's have a look at our contact data there.
If I empty this, validation still seems to work fine
so everything still works
but now of course, we greatly improved the code by outsourcing checkValidity into its own file.