Welcome to the third chapter of the perf-issue tutorial!
In the previous chapter, Chapter 2: Feature Toggling Interface, we built a "Kill Switch" to prevent our feature's logic from running. We ensured the code is safe.
However, safety is only half the battle. Even if a button doesn't crash the app when clicked, users shouldn't see the button at all if the feature isn't ready.
Imagine you are in a restaurant. There is a door leading to the kitchen.
isEnabled): The door is locked. Customers can't go in.isHidden): If you put a bright neon sign saying "FREE PIZZA" on that locked door, customers will try to open it, get frustrated, and complain.It is better to make the door look like part of the wall, or put a discreet "Staff Only" sign on it.
The Use Case:
You have a feature called Dark Mode. The code is disabled because it's buggy.
Dark Mode exists yet.We need a way to tell the UI: "Do not show this."
isHiddenThe Visibility Configuration is a simple property representing the state of concealment.
It allows us to separate Logic (does it work?) from Presentation (can I see it?).
When building your User Interface (like a Menu or a Sidebar), you check this property before drawing the element on the screen.
Imagine your application is deciding which buttons to show on the navigation bar.
import feature from './index.js';
// We check: Is this feature hidden?
if (feature.isHidden) {
// Scenario A: Do nothing.
console.log("Skipping this item. It is hidden.");
} else {
// Scenario B: Draw the UI.
console.log("Render the button!");
}
Output:
Skipping this item. It is hidden.
Because feature.isHidden is true, the code inside the else block is never reached. The button is never drawn. The user experience remains clean and unconfused.
How does the Stub handle this request?
Think of the feature as a person wearing an Invisibility Cloak.
isHidden property.true, the UI looks right through it effectively ignoring it.Here is the interaction flow:
Let's look at index.js one last time to focus on this specific property.
// --- File: index.js ---
export default {
isEnabled: () => false,
// This is the Visibility Configuration
// It is a simple boolean value.
isHidden: true,
name: 'stub'
};
Explanation:
isHidden: true: This is a direct property, not a function. It is a hardcoded fact about this object.true?: Since this is a Stub (a placeholder for missing features), the default safe assumption is that it should not be seen by the public.
By setting this to true, we ensure that any feature using this Stub definition will automatically vanish from menus, lists, and search results in the application, without us having to write extra logic in every UI component.
You have completed the section on the Feature Definition Stub!
In this chapter, you learned about Visibility Configuration:
isHidden property.Recap of the Module:
isEnabled) to stop logic from running (Chapter 2).isHidden) to hide the feature from the user.You now have a robust, crash-proof placeholder system. Whenever a feature is broken or not yet downloaded, your application will seamlessly swap in this Stub, ensuring safety (it won't run) and cleanliness (it won't show).
Generated by Code IQ