r002/firebase-learning

Lab05

Opened this issue · 1 comments

r002 commented

Lab05 Tasks & Questions:

  • Refactor authentication files. Is there a way to share the UserProfile code between index.html and 'editor.html` so we don't need to replicate it? Explore some kind of templating engine?
  • Our file hierarchy is getting a little overpopulated/unwieldy. Is there a way to clean it up?

Questions:

  • Is there a better way than declaring a single tsconfig.json in root? (As opposed in each individual lab0X dir?)
r002 commented

Occasionally refactoring is an important part of the coding process. As we build our app, our codebase obviously grows. One reason senior devs are paid the big bucks is because they can "look around corners" and recognize bad code smells and "see" trouble on the horizon. One sign of trouble is when you feel your workspace becoming overly bloated. Here's a trivial example but something I feel worth mentioning. We've all been here:

image

Originally, our humble TypeScript watcher is dutifully simply watching the /public/lab{LAB_NO}/scripts/ folder and compiling anything it sees. But as you can see above, over time, the number of files crowd and make the directory messy.

The way we originally set up TypeScript was by configuring a single file in /public/tsconfig.json. Let's go ahead now and set up an individual tsconfig.json per every single lab. Meaning, let's create: /public/lab05/tsconfig.json and inside, we specify:

image

This config change will yield:

image

In this new setup, we will solely code inside of the public/lab05/ts/ directory and the watcher (which we also need to now run in this same directory-- which is a little annoying, but them's the breaks!) will dutifully auto-transpile all our TypeScript into (unlinted, sadly; still haven't figured that one out) JavaScript into the public/lab05/js/ dir. To be clear: We will never, ever be directly touching any files in public/lab05/js/-- think of it a folder to which all of the source code we're building is built.

So now we've achieved our desired end result! (At least for now... the only constant in the Universe is change! 🤔🙄) But at least, for now: Mission accomplished! File hierarchy cleaner! 😀