-
Notifications
You must be signed in to change notification settings - Fork 6
feat: custom storage #59
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
Conversation
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.
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
Storageinterface'sgetmethod to returnPromise<string | null>instead ofPromise<string>to match AsyncStorage's behavior - Added a
storageconfiguration option toExperimentConfigthat accepts customStorageimplementations - Exported the
Storagetype 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 ifrawValuesisnull, which is now a valid return type fromstorage.get(). Add a null check before parsing:if (!rawValues) return;before line 76, or change the parsing tojsonValues = rawValues ? JSON.parse(rawValues) : {};
jsonValues = JSON.parse(rawValues) || {};
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
📝 Documentation updates detected! New suggestion: Document custom storage configuration for React Native Experiment SDK |
Custom storage interface and default implementation.