Welcome back! In the previous chapter, Chapter 1: Feature Definition Stub, we built the "shell" or the "storefront" for our new feature. We gave it a name and hid it from view.
However, hiding a feature isn't enough. Experienced users might guess the URL, or a bug might accidentally reveal the button. We need a guarantee that the feature cannot run.
In this chapter, we will learn about Activation Logic.
Imagine you are wiring a house. You have installed a new outlet, but you aren't sure if the wiring is perfect yet. You don't want anyone plugging a toaster in and causing a spark.
We have code for a feature that is currently incomplete or untested. We need a mechanism that acts as a Hardcoded Safety Fuse.
We want to tell the system: "Under no circumstances should this feature be allowed to execute."
Think of the Activation Logic as a Circuit Breaker in your home.
Even if you plug a lamp into the outlet (try to use the feature), if the breaker is switched to OFF, electricity will not flow. It is a physical break in the circuit.
To implement this safety fuse, we use a specific property called isEnabled.
In our specific context for the oauth-refresh project, we are going to implement the strictest possible logic: a function that always says "No".
Here is the code:
// File: index.js
export default {
// ... other properties like name and isHidden ...
// The Activation Logic
isEnabled: () => false
};
If you are new to JavaScript, () => false is a short way of writing a function.
() means it takes no arguments. It doesn't care who you are or what time it is.false means the answer is always "No".Let's walk through what happens when a user (or the system) tries to run this feature.
isEnabled property.false.Here is a diagram showing how the Activation Logic acts as a wall between the App and the Feature.
Let's look at the code snippet again to understand exactly why we write it this way.
isEnabled: () => false
You might wonder, why not just write isEnabled: false (a simple value)?
We use a function (() => ...) because in the future, we might want to change the logic. Later, we might want to say:
By using a function now, we establish a standard way for the Application to "ask questions." Today, the answer is always "False." Tomorrow, the answer might be calculated.
When you run your application with this logic in place, you can verify it works by looking at the behavior:
stub.isEnabled().false.In this chapter, we implemented the Activation Logic for our feature stub.
We learned:
isEnabled: () => false.
You now have a safe, registered, but completely dormant feature in your system. This completes the setup for the oauth-refresh project stubs!
Return to Chapter 1: Feature Definition Stub
Generated by Code IQ