-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added tsdoc for hooks. corrected LDClient variation tsdoc errors.
- Loading branch information
Showing
3 changed files
with
180 additions
and
30 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
154 changes: 138 additions & 16 deletions
154
packages/sdk/react-native/src/hooks/variation/useVariation.ts
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,25 +1,147 @@ | ||
import { useTypedVariation, useTypedVariationDetail } from './useTypedVariation'; | ||
|
||
export const useBoolVariation = (flagKey: string, defaultValue: boolean) => | ||
useTypedVariation<boolean>(flagKey, defaultValue); | ||
/** | ||
* Determines the boolean variation of a feature flag. | ||
* | ||
* If the flag variation does not have a boolean value, defaultValue is returned. | ||
* | ||
* @param key The unique key of the feature flag. | ||
* @param defaultValue The default value of the flag, to be used if the value is not available | ||
* from LaunchDarkly. | ||
* @returns | ||
* The boolean value. | ||
*/ | ||
export const useBoolVariation = (key: string, defaultValue: boolean) => | ||
useTypedVariation<boolean>(key, defaultValue); | ||
|
||
export const useBoolVariationDetail = (flagKey: string, defaultValue: boolean) => | ||
useTypedVariationDetail<boolean>(flagKey, defaultValue); | ||
/** | ||
* Determines the boolean variation of a feature flag for a context, along with information about | ||
* how it was calculated. | ||
* | ||
* The `reason` property of the result will also be included in analytics events, if you are | ||
* capturing detailed event data for this flag. | ||
* | ||
* If the flag variation does not have a boolean value, defaultValue is returned. The reason will | ||
* indicate an error of the type `WRONG_KIND` in this case. | ||
* | ||
* For more information, see the [SDK reference | ||
* guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#react-native). | ||
* | ||
* @param key The unique key of the feature flag. | ||
* @param defaultValue The default value of the flag, to be used if the value is not available | ||
* from LaunchDarkly. | ||
* @returns | ||
* The result (as an {@link LDEvaluationDetailTyped<boolean>}). | ||
*/ | ||
export const useBoolVariationDetail = (key: string, defaultValue: boolean) => | ||
useTypedVariationDetail<boolean>(key, defaultValue); | ||
|
||
export const useNumberVariation = (flagKey: string, defaultValue: number) => | ||
useTypedVariation<number>(flagKey, defaultValue); | ||
/** | ||
* Determines the numeric variation of a feature flag. | ||
* | ||
* If the flag variation does not have a numeric value, defaultValue is returned. | ||
* | ||
* @param key The unique key of the feature flag. | ||
* @param defaultValue The default value of the flag, to be used if the value is not available | ||
* from LaunchDarkly. | ||
* @returns | ||
* The numeric value. | ||
*/ | ||
export const useNumberVariation = (key: string, defaultValue: number) => | ||
useTypedVariation<number>(key, defaultValue); | ||
|
||
export const useNumberVariationDetail = (flagKey: string, defaultValue: number) => | ||
useTypedVariationDetail<number>(flagKey, defaultValue); | ||
/** | ||
* Determines the numeric variation of a feature flag for a context, along with information about | ||
* how it was calculated. | ||
* | ||
* The `reason` property of the result will also be included in analytics events, if you are | ||
* capturing detailed event data for this flag. | ||
* | ||
* If the flag variation does not have a numeric value, defaultValue is returned. The reason will | ||
* indicate an error of the type `WRONG_KIND` in this case. | ||
* | ||
* For more information, see the [SDK reference | ||
* guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#react-native). | ||
* | ||
* @param key The unique key of the feature flag. | ||
* @param defaultValue The default value of the flag, to be used if the value is not available | ||
* from LaunchDarkly. | ||
* @returns | ||
* The result (as an {@link LDEvaluationDetailTyped<number>}). | ||
*/ | ||
export const useNumberVariationDetail = (key: string, defaultValue: number) => | ||
useTypedVariationDetail<number>(key, defaultValue); | ||
|
||
export const useStringVariation = (flagKey: string, defaultValue: string) => | ||
useTypedVariation<string>(flagKey, defaultValue); | ||
/** | ||
* Determines the string variation of a feature flag. | ||
* | ||
* If the flag variation does not have a string value, defaultValue is returned. | ||
* | ||
* @param key The unique key of the feature flag. | ||
* @param defaultValue The default value of the flag, to be used if the value is not available | ||
* from LaunchDarkly. | ||
* @returns | ||
* The string value. | ||
*/ | ||
export const useStringVariation = (key: string, defaultValue: string) => | ||
useTypedVariation<string>(key, defaultValue); | ||
|
||
export const useStringVariationDetail = (flagKey: string, defaultValue: string) => | ||
useTypedVariationDetail<string>(flagKey, defaultValue); | ||
/** | ||
* Determines the string variation of a feature flag for a context, along with information about | ||
* how it was calculated. | ||
* | ||
* The `reason` property of the result will also be included in analytics events, if you are | ||
* capturing detailed event data for this flag. | ||
* | ||
* If the flag variation does not have a string value, defaultValue is returned. The reason will | ||
* indicate an error of the type `WRONG_KIND` in this case. | ||
* | ||
* For more information, see the [SDK reference | ||
* guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#react-native). | ||
* | ||
* @param key The unique key of the feature flag. | ||
* @param defaultValue The default value of the flag, to be used if the value is not available | ||
* from LaunchDarkly. | ||
* @returns | ||
* The result (as an {@link LDEvaluationDetailTyped<string>}). | ||
*/ | ||
export const useStringVariationDetail = (key: string, defaultValue: string) => | ||
useTypedVariationDetail<string>(key, defaultValue); | ||
|
||
export const useJsonVariation = (flagKey: string, defaultValue: unknown) => | ||
useTypedVariation<unknown>(flagKey, defaultValue); | ||
/** | ||
* Determines the json variation of a feature flag. | ||
* | ||
* This version may be favored in TypeScript versus `variation` because it returns | ||
* an `unknown` type instead of `any`. `unknown` will require a cast before usage. | ||
* | ||
* @param key The unique key of the feature flag. | ||
* @param defaultValue The default value of the flag, to be used if the value is not available | ||
* from LaunchDarkly. | ||
* @returns | ||
* The json value. | ||
*/ | ||
export const useJsonVariation = (key: string, defaultValue: unknown) => | ||
useTypedVariation<unknown>(key, defaultValue); | ||
|
||
export const useJsonVariationDetail = (flagKey: string, defaultValue: unknown) => | ||
useTypedVariationDetail<unknown>(flagKey, defaultValue); | ||
/** | ||
* Determines the json variation of a feature flag for a context, along with information about how it | ||
* was calculated. | ||
* | ||
* The `reason` property of the result will also be included in analytics events, if you are | ||
* capturing detailed event data for this flag. | ||
* | ||
* This version may be favored in TypeScript versus `variation` because it returns | ||
* an `unknown` type instead of `any`. `unknown` will require a cast before usage. | ||
* | ||
* For more information, see the [SDK reference | ||
* guide](https://docs.launchdarkly.com/sdk/features/evaluation-reasons#react-native). | ||
* | ||
* @param key The unique key of the feature flag. | ||
* @param defaultValue The default value of the flag, to be used if the value is not available | ||
* from LaunchDarkly. | ||
* @returns | ||
* If you provided a callback, then nothing. Otherwise, a Promise which will be resolved with | ||
* the result (as an{@link LDEvaluationDetailTyped<unknown>}). | ||
*/ | ||
export const useJsonVariationDetail = (key: string, defaultValue: unknown) => | ||
useTypedVariationDetail<unknown>(key, defaultValue); |
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