Welcome to the final chapter of our beginner tutorial!
In Chapter 3: Feature Gating, we learned how to use the "Circuit Breaker" (isEnabled) to cut the power to a module so it doesn't run dangerous logic.
But what if the module is working perfectly, but we just don't want it to appear on the screen?
Imagine you are at a fancy restaurant. The kitchen is bustling with activityβchefs are cooking, dishwashers are cleaning. The "logic" of the restaurant is running at full speed. However, as a customer in the dining room, you don't see the kitchen. It is hidden behind a door.
If the kitchen were right next to your table, it would be chaotic. We need a way to separate the operation (doing the work) from the presentation (what the user sees).
In software, we often build "Background Services." These are modules that do important work but don't need a button in the navigation menu.
For example:
We need a way to tell the User Interface (UI): "This module exists, but Do Not Draw it."
We solve this using the isHidden property. This is our "Invisibility Cloak."
While isEnabled stops the code from running, isHidden simply stops the pixels from appearing on the screen.
Let's finalize our stub module.
// --- File: index.js ---
export default {
// Logic: The engine is running
isEnabled: () => true,
// Presentation: But it is invisible
isHidden: true,
name: 'stub'
};
isEnabled: () => true: We have turned the switch ON. The system will load this module and execute its setup code.isHidden: true: We set this flag to true. This acts as a filter.name: 'stub': The system still tracks it by this name (Chapter 2: Component Identification).Output:
How does teleport distinguish between running code and showing code? It usually separates these tasks into two different steps.
isEnabled. Since it is true, the System registers the module and lets it run.isHidden property.isHidden is true, the System removes the module from the list intended for the screen.
Let's look at a simplified version of the code that draws the navigation menu to understand how it uses isHidden.
// --- Internal UI System Code ---
function drawMenu(allModules) {
// 1. filter() loops through every module
const visibleItems = allModules.filter(module => {
// 2. If isHidden is true, exclude it!
if (module.isHidden === true) {
return false;
}
// 3. Otherwise, keep it in the list
return true;
});
// 4. Only draw what remains
renderOnScreen(visibleItems);
}
Explanation:
allModules.filter(...): This is a standard Javascript tool. Imagine sifting flour; the filter holds back the lumps (hidden items) and lets the fine flour (visible items) pass through.if (module.isHidden === true): This is the check. If the "Do Not Disturb" sign is up, the renderer simply skips it.renderOnScreen: This function eventually draws the buttons. It never even receives our stub module, so it doesn't know it exists!
Congratulations! You have successfully defined a complete module using the teleport architecture. Let's recap the four pillars we have built:
name so the registry could track it.isEnabled to safely control whether the code runs.isHidden to control whether the user can see the module.By combining these four concepts, you can create "Stubs"βplaceholders that allow you to ship code safely, keep your application stable, and hide unfinished features from your users until they are ready to shine.
End of Tutorial.
Generated by Code IQ