-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KAIZEN-0] Skrive om logikk for feature toggles, fjerne toggle for ar…
…beidsregistrering
- Loading branch information
1 parent
42eecf0
commit 3a4c541
Showing
6 changed files
with
56 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { FeatureTogglesResponse, hentFeatureToggles } from '../redux/api'; | ||
import { FeatureToggles } from './FeatureToggles'; | ||
|
||
|
||
const TEN_SECONDS = 10000 | ||
|
||
class FeatureToggleManager { | ||
private lastFetch?: number | ||
private toggles: FeatureTogglesResponse | ||
|
||
constructor() { | ||
this.toggles = this.defaultToggles() | ||
} | ||
|
||
private defaultToggles = (): FeatureTogglesResponse => { | ||
return { | ||
'modiacontextholder.ikke-fnr-i-path': false | ||
}; | ||
}; | ||
|
||
private getToggles = async () => { | ||
const res = await hentFeatureToggles() | ||
if (res.data) { | ||
this.toggles = res.data | ||
this.lastFetch = Date.now() | ||
} | ||
} | ||
|
||
private shouldFetchToggles = (): boolean => !this.lastFetch || this.lastFetch < Date.now() - TEN_SECONDS | ||
|
||
getToggle = async (toggleId: FeatureToggles): Promise<boolean> => { | ||
if (this.shouldFetchToggles()) { | ||
await this.getToggles() | ||
} | ||
return !!this.toggles[toggleId] | ||
} | ||
} | ||
|
||
export default new FeatureToggleManager() |
This file was deleted.
Oops, something went wrong.
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,4 +1,3 @@ | ||
export enum FeatureToggles { | ||
NY_ARBEIDSSOKER_REGISTRERING_URL = 'modiacontextholder.ny-arbeidssoker-registrering-url', | ||
IKKE_FNR_I_PATH = 'modiacontextholder.ikke-fnr-i-path' | ||
} |
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