Welcome back! In Chapter 1: Module Definition, we created a "stub"โa placeholder module that acts like a prop on a movie set. It exists, but it doesn't do anything yet.
Imagine you are in a crowded room full of people. If you want to get the attention of one specific person, you don't just yell "Hey, Person!" because everyone might turn around (or no one will). You yell their specific name, like "Hey, Alice!"
In our teleport project, the system will eventually load many different modules. To manage them effectively, the system needs to know who is who.
We need a way for the main system to keep a list of all available modules. This list is often called a Registry (think of it like a phone book).
When the system starts up, it picks up our code and asks, "What should I call you?" If our module doesn't have a name, the system can't file it away for later use. We need to provide a unique identifier so the system can find our module again later to check its status or display it.
The solution is the name property. This is a simple text string that acts as a unique serial number or nametag for your code.
We are going to update the file we created in the previous chapter.
// --- File: index.js ---
export default {
// ... (other properties like isEnabled) ...
// This is the Component Identification
name: 'stub'
};
name: 'stub': We assigned a string value to the name property.'stub', we are claiming this word. No other module in the system should be named 'stub'.index.js, my-code.js, or temp.js. The system doesn't care about the filename; it only cares that the module inside calls itself 'stub'.
Output: When the system processes this, it reads the string 'stub'. It can now log messages like "Loading module: stub" or errors like "Error in module: stub," making it much easier for humans to understand what is happening.
How does teleport actually use this string? Let's visualize the "Registration" process.
name property.name as the key (or label).
Let's imagine how the teleport system (the code running behind the scenes) handles this registration.
// --- Internal System Code (Simplified) ---
const registry = {}; // 1. The phone book
function register(module) {
const id = module.name; // 2. Extract the name tag
registry[id] = module; // 3. File it away
console.log(`Successfully registered: ${id}`);
}
Explanation:
const registry = {}: This is an empty object. It acts as our storage box.module.name: The system extracts the string 'stub' from our module.registry[id] = module: The system saves the module. Now, registry['stub'] points to our code.Because we have this name, we can now perform specific checks. For example, in the next chapter, we might want to check if the 'stub' module specifically is enabled.
In this chapter, we learned that Component Identification is simply giving our module a name tag.
name property ('stub').Now that our module has an identity, we can start making decisions based on that identity. For instance, what if we want to turn the module 'stub' on for some users but off for others?
We will explore this in Chapter 3: Feature Gating.
Generated by Code IQ