-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add feature flags * chore: remove setdefaultflags * fix: checked on admin debug page * make enabled toggle råsa * fix: remove need to use onMount for feature flags --------- Co-authored-by: Alfred Grip <[email protected]>
- Loading branch information
1 parent
07d5dec
commit 5456f64
Showing
4 changed files
with
132 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Feature flags | ||
|
||
When working on larger features we want to avoid long lived branches with a lot of changes. This can be avoided by hiding the feature behind a feature flag. | ||
|
||
1. Add your flag to the array `featureFlags` in `src/lib/utils/featureFlag.ts`. | ||
|
||
2. Go to the relevant component/page and add | ||
|
||
```typescript | ||
import { isFeatureFlagEnabled } from "$lib/utils/featureFlag"; | ||
let isEnabled = isFeatureFlagEnabled("newFeature"); | ||
``` | ||
|
||
3. Go to `/admin/debug` to toggle the feature flag | ||
|
||
4. Use | ||
|
||
```svelte | ||
{#if isEnabled} | ||
Awesome new feature goes here | ||
{/if} | ||
``` | ||
|
||
in the relevant component/page to hide your feature until it's ready. |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { browser } from "$app/environment"; | ||
|
||
export const featureFlags: string[] = []; | ||
|
||
export const isFeatureFlagEnabled = (flag: string) => { | ||
if (!featureFlags.includes(flag) || !browser) { | ||
return false; | ||
} | ||
const value = localStorage.getItem(flag); | ||
if (value === null || value === "false") { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
|
||
export const setFeatureFlag = (flag: string, value: boolean) => { | ||
if (!featureFlags.includes(flag)) { | ||
return false; | ||
} | ||
localStorage.setItem(flag, value.toString()); | ||
return true; | ||
}; |
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