From 04ba0ab694e45d465d0324257b749df4ec41a06d Mon Sep 17 00:00:00 2001 From: gregorianrants Date: Sun, 29 Oct 2023 13:57:08 +0000 Subject: [PATCH] Update part4a.md I have in the past been put of refactoring a large code base because i cant find usages of functions, i find this feature invaluable so thought i would share it. --- src/content/4/en/part4a.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/content/4/en/part4a.md b/src/content/4/en/part4a.md index 94444b93fa..7274800848 100644 --- a/src/content/4/en/part4a.md +++ b/src/content/4/en/part4a.md @@ -393,6 +393,14 @@ Now the exported "thing" (in this case a router object) is assigned to a variabl +#### Finding the usages of your exports with VScode + +VScode has a handy feature that allows you to see where your modules have been exported. This can be very helpfull for refactoring, say for example you decide to spilt a function in to 2 seperate functions, your code could break if you don't modify all the usages. This is difficult if you dont know where they are. However you need to define your exports in a particular way for this to work. + +If you right click on a variable, in the location it is exported from and select find all references it will show you everywhere the variable is imported. However if you assign an object directly to module.exports it will not work. A work around is to assign the object you want to export to a named variable then export the named variable. It also will not work if you destructure where you are importing, you have to import the named variable then destructure or just use dot notation to use the functions contained in the named variable. + +The nature of VS code bleeding into how you write your code is probably not ideal, so you need to decide yourself if the trade off is worthwhile. +
### Exercises 4.1.-4.2.