Skip to content
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

Niko/react native template update #548

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

nikomancy
Copy link
Contributor

@nikomancy nikomancy commented Dec 10, 2024

Updating the React Native SDK docs to use the new template for SDK docs.

Dependent on the Docusaurus 2.x -> 3.x update. Don't merge until that is in.

Copy link

netlify bot commented Dec 10, 2024

Deploy Preview for eppo-data-docs ready!

Name Link
🔨 Latest commit 900c542
🔍 Latest deploy log https://app.netlify.com/sites/eppo-data-docs/deploys/6764e79029cd9300089458b3
😎 Deploy Preview https://deploy-preview-548--eppo-data-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

…bandits aren't in the client SDKs per the spreadsheet.
Copy link
Contributor

@aarsilv aarsilv left a comment

Choose a reason for hiding this comment

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

Thanks for going over the React Native docs as well! Lots of great changes in here 👏

I left a bunch of comments but am requesting changes for a few main reasons:

  1. We should remove the old React Native section
  2. Currently, React Native SDK doesn't support persistent caching; we should remove all references
  3. There are some initialization options not yet exposed to React Native SDK that we should remove

@@ -0,0 +1,5 @@
{
"label": "React Native",
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll want to delete the old react native section

image

- String
- Boolean
- JSON
- Numeric
Copy link
Contributor

Choose a reason for hiding this comment

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

We also support Integer

- JSON
- Numeric

Depending on the values you pass to the getAssignment function, the SDK will return different results based on whether the subject details match the assignment rules you set in the Eppo UI.
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider making getAssignment() displayed as code and with the parenthesis to make it clear it is a function


This section will cover the different types of assignments that you can make with the Eppo SDK.

### Local Storage
Copy link
Contributor

Choose a reason for hiding this comment

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

The React Native SDK uses React Native Async Storage which, according to these docs, uses Local Storage for the web, SQLite for Android, and the filesystem for iOS.

Although we should probably ax this because we don't use it for caching at the moment (EppoAsyncStorage is always expired)

<FeatureCard
title="API Reference"
description="Reference for all SDK methods."
link="https://github.com/Eppo-exp/react-native-sdk"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not an API reference. These docs themselves are basically the API reference

<ApiOptionRef
name="persistentStore"
type="IAsyncStore"
defaultValue="Eppo provided"
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we should put in parenthesis so it's clear this isn't an actual class. (Eppo provided)

Comment on lines +97 to +104
<ApiOptionRef
name="skipInitialRequest"
type="boolean"
defaultValue="false"
>

Skip the initial request for a new configuration during initialization (if polling is enabled, this will still take place later)
</ApiOptionRef>
Copy link
Contributor

Choose a reason for hiding this comment

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

This one is not an option for React SDK

Comment on lines +124 to +145
<ApiOptionRef
name="useExpiredCache"
type="boolean"
defaultValue="false"
>

Consider initialization successfully complete without fetching updates, even if the configuration loaded from the cache is expired
</ApiOptionRef>

<ApiOptionRef
name="updateOnFetch"
type="'always' | 'expired' | 'empty'"
defaultValue="'always'"
>

Sets how the configuration is updated after a successful fetch:

- **always** - immediately start using the new configuration
- **expired** - immediately start using the new configuration only if the current one has expired
- **empty** - only use the new configuration if the current one is both expired and uninitialized/empty

</ApiOptionRef>
Copy link
Contributor

Choose a reason for hiding this comment

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

These two are currently not options for the ReactSDK either

Comment on lines +147 to +305

###### Prioritize fast initialization
If you want to optimize for the quickest time to initialization and serving assignments--even if those assignments may be out of date, you would want settings that:
- Immediately start using the new configuration after it is fetched
- Allow initializing with older configurations
- Reduce the initial fetch timeout and retries to quickly fall back to default values

Use the following configuration to achieve those goals:

```ts
import { init } from "@eppo/react-native-sdk";

await init({
apiKey: 'YOUR_API_KEY',
updateOnFetch: 'always', // Immediately start using the new configuration once it is fetched
maxCacheAgeSeconds: 300, // Don't even bother fetching updated configurations unless the last one is more than five minutes old
useExpiredCache: true, // If the cached configuration is expired, use it to serve assignments until an updated one is fetched
requestTimeoutMs: 500, // Give up on fetching updated configurations after half a second and--if this is the first-ever initialization--just serve default values
numInitialRequestRetries: 0, // Don't retry a failed initialization fetch
});
```

Note that when new configurations are loaded, the same flag may start getting a different assignment for the same session. If you want to avoid this, and have consistent assignments until the next initialization, change `updateOnFetch` to `empty`.
You could consider caches always expired so that it non-blocking loads an updated configuration to be used in the next session.

```ts
import { init } from "@eppo/react-native-sdk";

await init({
apiKey: 'YOUR_API_KEY',
maxCacheAgeSeconds: 0, // Always consider cached configurations expired
// Settings set to non-default values
updateOnFetch: 'empty', // Immediately start using the new configuration once it is fetched
useExpiredCache: true, // Always used the previously cached assignments
requestTimeoutMs: 500, // Give up on fetching updated configurations after half a second and--if this is the first-ever initialization--just serve default values
numInitialRequestRetries: 0, // Don't retry a failed initialization fetch
});
```

### Offline initialization

Eppo's SDK supports offline initialization. This is useful if you want to initialize the SDK with a configuration from your server SDK or other external process. In this mode the SDK will not attempt to fetch a configuration from Eppo's CDN, instead only using the provided values.

This function is synchronous and ready to handle assignments after it returns.

```javascript
import { offlineInit, Flag, ObfuscatedFlag } from "@eppo/react-native-sdk";

// configuration from your server SDK
const configurationJsonString: string = getConfigurationFromServer();

// The configuration will be not-obfuscated from your server SDK.
// If you have obfuscated flag values, you can use the `ObfuscatedFlag` type.
const flagsConfiguration: Record<string, Flag | ObfuscatedFlag> = JSON.parse(configurationJsonString);

offlineInit({
flagsConfiguration,
// If you have obfuscated flag values, you can use the `ObfuscatedFlag` type.
isObfuscated: true,
});
```

The `offlineInit` function accepts the following optional configuration arguments.

### Offline Initialization Options

<ApiOptionRef
name="assignmentLogger"
type="IAssignmentLogger"
typeUrl="https://github.com/Eppo-exp/js-client-sdk-common/blob/75c2ea1d91101d579138d07d46fca4c6ea4aafaf/src/assignment-logger.ts#L55-L62"
defaultValue="null"
>

A callback that sends each assignment to your data warehouse. Required only for experiment analysis.
</ApiOptionRef>
<ApiOptionRef
name="flagsConfiguration"
type="Record <string, Flag | ObfuscatedFlag>"
defaultValue="null"
>

The flags configuration to use for the SDK.
</ApiOptionRef>

<ApiOptionRef
name="isObfuscated"
type="boolean"
defaultValue="false"
>

Whether the flag values are obfuscated.
</ApiOptionRef>
<ApiOptionRef
name="throwOnFailedInitialization"
type="boolean"
defaultValue="true"
>

Throw an error if an error occurs during initialization.
</ApiOptionRef>
Copy link
Contributor

Choose a reason for hiding this comment

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

Configuration caching and offline initialization have not yet been exposed to the React SDK. The latter is in the works in a pre-release version. We should make sure part of launching includes updating the documentation.



## Advanced Configuration
Basic initialization is great for most use cases, but the SDK provides options that you can use during initialization to customize the behavior of the SDK.
Copy link
Contributor

Choose a reason for hiding this comment

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

We also have a baseUrl option which is where the SDK fetches configurations from. Some customers override this went they proxy configuration requests.

@aarsilv aarsilv assigned nikomancy and unassigned aarsilv Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants