-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: export public option types (#1101)
## This PR - renames the `shared` folder to `internal` to prevent accident exports - export public option types ### Notes This will make it easier for devs who need access to the option types. --------- Signed-off-by: Michael Beemer <[email protected]>
- Loading branch information
Showing
16 changed files
with
112 additions
and
102 deletions.
There are no files selected for viewing
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
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
8 changes: 5 additions & 3 deletions
8
packages/react/src/common/context.ts → packages/react/src/internal/context.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
File renamed without changes.
File renamed without changes.
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,40 @@ | ||
import type { ReactFlagEvaluationOptions, NormalizedOptions } from '../options'; | ||
|
||
/** | ||
* Default options. | ||
* DO NOT EXPORT PUBLICLY | ||
* @internal | ||
*/ | ||
export const DEFAULT_OPTIONS: ReactFlagEvaluationOptions = { | ||
updateOnContextChanged: true, | ||
updateOnConfigurationChanged: true, | ||
suspendUntilReady: false, | ||
suspendWhileReconciling: false, | ||
}; | ||
|
||
/** | ||
* Returns normalization options (all `undefined` fields removed, and `suspend` decomposed to `suspendUntilReady` and `suspendWhileReconciling`). | ||
* DO NOT EXPORT PUBLICLY | ||
* @internal | ||
* @param {ReactFlagEvaluationOptions} options options to normalize | ||
* @returns {NormalizedOptions} normalized options | ||
*/ | ||
export const normalizeOptions: (options?: ReactFlagEvaluationOptions) => NormalizedOptions = ( | ||
options: ReactFlagEvaluationOptions = {}, | ||
) => { | ||
const updateOnContextChanged = options.updateOnContextChanged; | ||
const updateOnConfigurationChanged = options.updateOnConfigurationChanged; | ||
|
||
// fall-back the suspense options to the catch-all `suspend` property | ||
const suspendUntilReady = 'suspendUntilReady' in options ? options.suspendUntilReady : options.suspend; | ||
const suspendWhileReconciling = | ||
'suspendWhileReconciling' in options ? options.suspendWhileReconciling : options.suspend; | ||
|
||
return { | ||
// only return these if properly set (no undefined to allow overriding with spread) | ||
...(typeof suspendUntilReady === 'boolean' && { suspendUntilReady }), | ||
...(typeof suspendWhileReconciling === 'boolean' && { suspendWhileReconciling }), | ||
...(typeof updateOnContextChanged === 'boolean' && { updateOnContextChanged }), | ||
...(typeof updateOnConfigurationChanged === 'boolean' && { updateOnConfigurationChanged }), | ||
}; | ||
}; |
File renamed without changes.
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,53 @@ | ||
import type { FlagEvaluationOptions } from '@openfeature/web-sdk'; | ||
|
||
export type ReactFlagEvaluationOptions = ( | ||
| { | ||
/** | ||
* Enable or disable all suspense functionality. | ||
* Cannot be used in conjunction with `suspendUntilReady` and `suspendWhileReconciling` options. | ||
* @experimental Suspense is an experimental feature subject to change in future versions. | ||
*/ | ||
suspend?: boolean; | ||
suspendUntilReady?: never; | ||
suspendWhileReconciling?: never; | ||
} | ||
| { | ||
/** | ||
* Suspend flag evaluations while the provider is not ready. | ||
* Set to false if you don't want to show suspense fallbacks until the provider is initialized. | ||
* Defaults to false. | ||
* Cannot be used in conjunction with `suspend` option. | ||
* @experimental Suspense is an experimental feature subject to change in future versions. | ||
*/ | ||
suspendUntilReady?: boolean; | ||
/** | ||
* Suspend flag evaluations while the provider's context is being reconciled. | ||
* Set to true if you want to show suspense fallbacks while flags are re-evaluated after context changes. | ||
* Defaults to false. | ||
* Cannot be used in conjunction with `suspend` option. | ||
* @experimental Suspense is an experimental feature subject to change in future versions. | ||
*/ | ||
suspendWhileReconciling?: boolean; | ||
suspend?: never; | ||
} | ||
) & { | ||
/** | ||
* Update the component if the provider emits a ConfigurationChanged event. | ||
* Set to false to prevent components from re-rendering when flag value changes | ||
* are received by the associated provider. | ||
* Defaults to true. | ||
*/ | ||
updateOnConfigurationChanged?: boolean; | ||
/** | ||
* Update the component when the OpenFeature context changes. | ||
* Set to false to prevent components from re-rendering when attributes which | ||
* may be factors in flag evaluation change. | ||
* Defaults to true. | ||
*/ | ||
updateOnContextChanged?: boolean; | ||
} & FlagEvaluationOptions; | ||
|
||
// suspense options removed for the useSuspenseFlag hooks | ||
export type ReactFlagEvaluationNoSuspenseOptions = Omit<ReactFlagEvaluationOptions, 'suspend' | 'suspendUntilReady' | 'suspendWhileReconciling'>; | ||
|
||
export type NormalizedOptions = Omit<ReactFlagEvaluationOptions, 'suspend'>; |
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
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