Welcome back! In the previous chapter, Activation Control (Feature Flagging), we learned how to turn the power off for our feature using a "Master Switch" (isEnabled).
We have ensured that our "stub" feature won't run any unfinished code. But we have a remaining problem: Just because a machine is unplugged, doesn't mean it is invisible.
If we have a "Stub" button in our main menu, but clicking it does nothing (because it is disabled), users will be confused. They will click it and think the application is broken.
Think of your application like a theater stage.
Sometimes, you need to change the set or put actors in place before the show starts. If the audience watches you moving props around, it ruins the magic.
The Solution: The Curtain (isHidden)
Visibility State Management acts as that curtain. It allows the feature to exist on the "stage" (in the code), but prevents the "audience" (the user) from seeing it.
We are building a "stub" feature. It is currently empty and disabled.
To achieve this, we will use the isHidden property from our Configuration Contract.
To pull the curtain down, we set isHidden to true in our module's configuration file.
Here is the code for index.js:
// index.js
export default {
name: 'stub',
isEnabled: () => false, // The power is off
// The curtain is down
isHidden: true
};
isHidden: This is the property that controls visual rendering.true: By setting this to true, we are saying, "Yes, please hide this."isEnabled (which was a function), isHidden is usually a simple Yes/No value (a boolean).By adding this line, you tell the User Interface (UI) to completely ignore this module when drawing menus or lists.
How does the application know to hide the button? The system's "Menu Builder" checks this property before drawing anything on the screen.
isHidden).Here is a diagram showing how the UI interacts with our configuration:
Let's look at a simplified version of the code that builds the navigation menu. This logic ensures that hidden features stay hidden.
// ui-menu-builder.js
import allFeatures from './feature-loader.js';
const menuList = [];
for (const feature of allFeatures) {
// 1. Check if the curtain is down
if (feature.isHidden) {
// 2. If hidden, skip this iteration immediately
continue;
}
// 3. Only reach here if isHidden is false
menuList.push(feature.name);
}
console.log("Menu items:", menuList);
Because our stub has isHidden: true, the code hits the continue statement. It skips the menuList.push line. As a result, the user never sees the option.
isHidden vs isEnabled: What's the difference?Beginners often ask: "If I disabled the feature in the last chapter, why do I need to hide it too?"
These two concepts control different things. This allows for powerful combinations:
isEnabled: false (Don't run)isHidden: true (Don't show)isEnabled: false (Don't run)isHidden: false (Show it)isEnabled: true (It works)isHidden: true (Don't show in menu)You have now mastered the art of the "Theater Curtain."
Our feature is now fully defined, safe, and hidden. But if we ever do decide to turn it on, what happens? Right now, it's just an empty shell.
In the next chapter, we will learn how to create a "fake" version of the feature logic so we can test the system connections without writing the actual complex business logic.
Next Chapter: Feature Stubbing
Generated by Code IQ