Skip to content

feat: Add FlagOptions for consolidated feature flag configuration - #896

Merged
msiebert merged 6 commits into
masterfrom
msiebert-flag-options-config
Mar 4, 2026
Merged

feat: Add FlagOptions for consolidated feature flag configuration#896
msiebert merged 6 commits into
masterfrom
msiebert-flag-options-config

Conversation

@msiebert

@msiebert msiebert commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Introduces a new FlagOptions class (builder pattern) that groups feature flag settings (enabled, context, loadOnFirstForeground) into a single configuration object
  • Adds setFlagOptions(FlagOptions) to MixpanelOptions.Builder, deprecating the flat featureFlagsEnabled() and featureFlagsContext() methods (backward compatible — flat params are auto-wrapped into a FlagOptions when the new API isn't used)
  • Adds loadOnFirstForeground option so callers can control whether flags are automatically fetched on the first app foreground event
  • Includes instrumented tests covering defaults, custom values, defensive copying, MixpanelOptions integration, and behavioral verification of the foreground-load toggle

🤖 Generated with Claude Code

msiebert and others added 3 commits February 24, 2026 14:04
Introduces FlagOptions with builder pattern to group feature flag settings
(enabled, context, loadOnFirstForeground) into a single configuration
object. Deprecates the flat featureFlagsEnabled/featureFlagsContext params
on MixpanelOptions in favor of the new setFlagOptions() builder method.
The new loadOnFirstForeground option allows callers to control whether
flags are automatically fetched on the first app foreground event.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@msiebert
msiebert requested a review from tylerjroach February 25, 2026 18:59
@msiebert msiebert self-assigned this Feb 25, 2026
@msiebert
msiebert marked this pull request as ready for review February 25, 2026 19:00
@msiebert

Copy link
Copy Markdown
Contributor Author

@dillon-mce here's the Android version of the option to not load flags on first foreground!

Comment thread src/main/java/com/mixpanel/android/mpmetrics/MixpanelOptions.java Outdated
* or an empty JSONObject if the source is {@code null} or copying fails.
*/
@NonNull
public static JSONObject defensiveCopy(@Nullable JSONObject source) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unnecessary with proper nullability annotations and being defensive elsewhere before attempting to convert. Just feels like a utility function that will be forgotten about, used in some places, but not others.

* @param enabled {@code true} to enable feature flags, {@code false} to disable.
* @return This Builder instance for chaining.
*/
public Builder setEnabled(boolean enabled) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current builder pattern is to not use set at the start of these as setting should be obvious given that we are in builder pattern. We don't use set for the mixpanel options

private FlagOptions(Builder builder) {
this.mEnabled = builder.mEnabled;
this.mLoadOnFirstForeground = builder.mLoadOnFirstForeground;
this.mContext = builder.mContext != null ? builder.mContext : new JSONObject();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See argument against defensive copy utility since this would be a good way to ensure not null.

@msiebert

Copy link
Copy Markdown
Contributor Author

K @tylerjroach, I think I've addressed your concerns by:

  1. Updating the builder patterns to be less brittle
  2. Removing the defensive copy helper and then just doing it inline with a comment for why I'm using it. It's generally not about null checks, and more about making sure that we have a copy that doesn't change based on end user mutation

msiebert and others added 2 commits March 2, 2026 15:11
… prefetchFlags

Improves naming clarity for the feature flag configuration class and its
auto-load parameter.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@msiebert
msiebert merged commit 0d9a900 into master Mar 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants