The solution here is, to be honest, a bit complex. So if I have this one, I will probably need to extract the shared functionality and then call this shared functionality for both models. It's easier drawn than actually done. It can be quite complex to understand what is the functionality.
Cyclic references. Now let's switch to the barrel file, and this is where the name come from. A barrel file, the logstock and barrel means everything including everything, and the barrel file is basically an index file from which you export multiple functions. So it will look something like that. I have function A, B, C, whatever I'm exporting it, and then in your file, you are going to import these functions just from the index file and use whatever you need. When we are talking about barrel files, it has a really good point. It will hide the internal structure. So not every module that is importing from this module needs to know the internal structure, and it gives you some freedom to do some refactoring inside without impacting the external consumers. But it also has downsides. The bad is it increases the import surface, so you are trying to import a single function and you end up with importing 500 files. This can have huge impact on performance, and because barrel files import a lot of files, you have a better chance to get cyclic references because you are just importing so many files.
I want to show an example of how I use tsmove again in code in order to fix an example. So again, I have here a slightly different version of my import going from a different export, and then in my file, I am importing function 1, 6, and 8 from this index file. And now let's say I looked at the code and I said, okay, so function 7 and function 8 from module D, I want to extract them to a separate module. I want to take them out from this utils and have them in their own module. And I created a domain D index file with module D, and I export only these files. I also moved the files. Now, people might come and say, look, when you move the files, your IDE can actually fix all your imports for you. True, but when you are working with large code bases, it's probably going to create very bad references, especially if you are using a shortcut for path. It might use a relative path instead of the shortcut for path. Okay, so now in my file, I want to change the function 1, 6, and 8 from utils and split it to two imports, one still from utils and another from function 8. If this is only on one file, you can do that manually, no problem. But the problem is that you probably have hundreds of imports for this utils all over the place, and going one by one can be really tedious. So what do we do? We create a function that is called runReplaceImports, okay, using again tsmove. It will get four parameters.
Comments