-
Notifications
You must be signed in to change notification settings - Fork 25k
Add an 'Experiments' class to enable/disable experiments. #5446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /** | ||
| * Copyright (c) 2015-present, Facebook, Inc. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. An additional grant | ||
| * of patent rights can be found in the PATENTS file in the same directory. | ||
| */ | ||
|
|
||
| package com.facebook.react; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
|
|
||
| /** | ||
| * This class exposes a way to enable/disable experimental features in React Native. | ||
| */ | ||
| public class Experiments { | ||
|
|
||
| // Enables Hot Module Replacement menu item in the developer menu | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
| public static String HOT_MODULE_REPLACEMENT = "HOT_MODULE_REPLACEMENT"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add Javadoc with a short explanation this shows/hides the HMR menu please. |
||
|
|
||
| private static Set<String> enabledExperiments; | ||
|
|
||
| /** | ||
| * Enables an experiment | ||
| */ | ||
| public static void enableExperiment(String experiment) { | ||
| if (enabledExperiments == null) { | ||
| enabledExperiments = new HashSet<>(); | ||
| } | ||
| enabledExperiments.add(experiment); | ||
| } | ||
|
|
||
| /** | ||
| * Disables an experiment | ||
| */ | ||
| public static void disableExperiment(String experiment) { | ||
| if (enabledExperiments != null) { | ||
| enabledExperiments.remove(experiment); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Checks if an experiment is enabled | ||
| */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a matter of personal preference but these three methods have so clear names they probably don't require Javadoc. If you prefer keep it but please remove the |
||
| public static boolean isExperimentEnabled(String experiment) { | ||
| return enabledExperiments != null && enabledExperiments.contains(experiment); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add Javadoc explaining what the reason this class exist is please.