Skip to content

Conversation

@zhukaihan
Copy link
Contributor

@zhukaihan zhukaihan commented Oct 21, 2025

Custom storage interface and default implementation.

@zhukaihan zhukaihan marked this pull request as ready for review November 3, 2025 21:03
@zhukaihan zhukaihan requested review from a team and Copilot November 3, 2025 21:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for custom storage implementations in the Experiment client. The change allows users to provide their own storage backend while maintaining backward compatibility with the default AsyncStorage implementation.

Key changes:

  • Modified the Storage interface's get method to return Promise<string | null> instead of Promise<string> to match AsyncStorage's behavior
  • Added a storage configuration option to ExperimentConfig that accepts custom Storage implementations
  • Exported the Storage type from the main index to make it available to SDK consumers

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/types/storage.ts Updated return type of get method to include null
src/types/config.ts Added optional storage field to ExperimentConfig and included it in defaults
src/storage/local-storage.ts Updated LocalStorage.get return type to match interface
src/storage/cache.ts Removed default LocalStorage instantiation and unused import
src/index.ts Exported storage types for public API
src/experimentClient.ts Added logic to use custom storage or default to LocalStorage
tests/client.test.ts Added tests for custom storage functionality
mocks/setup.ts Added type assertion for navigator mock
Comments suppressed due to low confidence (1)

src/storage/cache.ts:76

  • The JSON.parse(rawValues) will throw an error if rawValues is null, which is now a valid return type from storage.get(). Add a null check before parsing: if (!rawValues) return; before line 76, or change the parsing to jsonValues = rawValues ? JSON.parse(rawValues) : {};
      jsonValues = JSON.parse(rawValues) || {};

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@promptless
Copy link

promptless bot commented Nov 3, 2025

📝 Documentation updates detected!

New suggestion: Document custom storage configuration for React Native Experiment SDK

@zhukaihan zhukaihan requested review from kyeh-amp and tyiuhc November 13, 2025 07:37
@zhukaihan zhukaihan merged commit 04f8663 into main Nov 19, 2025
9 checks passed
@zhukaihan zhukaihan deleted the add-custom-storage branch November 19, 2025 23:29
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