-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor
featureFlag
to adopt object-based approach for improved ex…
…tensibility - Replaces single function (isVisible) with a featureFlag object - Introduces a features list (name, active), allowing for future expansion - Implements an isActive() method to handle feature toggles more cleanly
- Loading branch information
1 parent
c606de3
commit f7cd0ef
Showing
4 changed files
with
32 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
type FeatureFlagType = "readerPlayer"; | ||
const allowedUrls = ["dpl-", "dapple-cms"]; | ||
|
||
const isVisible = (name: FeatureFlagType): boolean => { | ||
const allowedUrls = ["dpl-", "dapple-cms"]; | ||
const features = [ | ||
{ name: "exampleFeature", active: false }, | ||
{ name: "readerPlayer", active: true } | ||
] as const; | ||
|
||
if (name === "readerPlayer") { | ||
return allowedUrls.some((url) => window.location.href.includes(url)); | ||
} | ||
type FeatureNameType = typeof features[number]["name"]; | ||
|
||
const featureFlag = { | ||
features, | ||
|
||
isActive(name: FeatureNameType): boolean { | ||
const feature = this.features.find((f) => f.name === name); | ||
if (!feature) return false; | ||
|
||
return false; | ||
const isAllowedUrl = allowedUrls.some((url) => | ||
window.location.href.includes(url) | ||
); | ||
|
||
return feature.active && isAllowedUrl; | ||
} | ||
}; | ||
|
||
export default isVisible; | ||
export default featureFlag; |