[RFC] feat: add support for strongly typed exp/gates #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Update - Oct 28
2d36d5d Added support for Feature Gate memoization. You can now specify that a gate should be memoized, as well as what UnitID to memoize on (Defaults to
userID
).e25676d Added default memoized experiment types for UserID (
TypedExperimentMemoizedByUserID
) and StableID (TypedExperimentMemoizedByStableID
). This removes the need to specify isisMemoizable
andmemoUnitIdType
Note:
SdkDemoSimpleGroupName
is an enum that only has two groups. It can be shared among many experiments since this is a common setup pattern.With this change, a developer can write their own type definitions for Statsig.
Usage
Gates
A type file is defined by the implementor.
Then the gates can be checked using
Statsig.typed
:Experiments
A type file is defined by the implementor.
Then the experiment can be checked using
Statsig.typed
:Strictly Typed Experiment Values
Its also possible to define the value object to be of a given type by adding a decodable type to the definition
Then you can use the value with the strict typing:
Experiment Memoization (Freezing/Locking)
By setting the
isMemoizable
field in yourTypedExperiment
to returntrue
. Statsig typed will only evaluate the experiment once, repeated calls to the same experiment will return the same result.If you would like the memoization to break when a specific ID type is changed in the StatsigUser, you can set the
memoUnitIdType
field in yourTypedExperiment
.For example, if you set the
memoUnitIdType
to 'userID':