-
Notifications
You must be signed in to change notification settings - Fork 31
feat: custom storage option for React Native SDK #539
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
Merged
kinyoklion
merged 6 commits into
launchdarkly:main
from
oblador:react-native-custom-storage
Aug 27, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9dc5d88
Custom storage option for React Native SDK
oblador 18a1118
Merge branch 'main' into react-native-custom-storage
kinyoklion b0caf45
chore: Update documentation for the storage option.
kinyoklion e8d0195
feat: Add configuration validation for storage.
kinyoklion 66cb502
Merge branch 'main' into react-native-custom-storage
kinyoklion 5367815
chore: Test and lint.
kinyoklion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/sdk/react-native/src/ReactNativeLDClient.storage.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { AutoEnvAttributes, LDLogger } from '@launchdarkly/js-client-sdk-common'; | ||
|
|
||
| import ReactNativeLDClient from './ReactNativeLDClient'; | ||
|
|
||
| it('uses custom storage', async () => { | ||
| // This test just validates that the custom storage instance is being called. | ||
| // Other tests validate how the SDK interacts with storage generally. | ||
| const logger: LDLogger = { | ||
| error: jest.fn(), | ||
| warn: jest.fn(), | ||
| info: jest.fn(), | ||
| debug: jest.fn(), | ||
| }; | ||
| const myStorage = { | ||
| get: jest.fn(), | ||
| set: jest.fn(), | ||
| clear: jest.fn(), | ||
| }; | ||
| const client = new ReactNativeLDClient('mobile-key', AutoEnvAttributes.Enabled, { | ||
| sendEvents: false, | ||
| initialConnectionMode: 'offline', | ||
| logger, | ||
| storage: myStorage, | ||
| }); | ||
|
|
||
| await client.identify({ key: 'potato', kind: 'user' }, { timeout: 15 }); | ||
| expect(myStorage.get).toHaveBeenCalled(); | ||
| expect(myStorage.clear).not.toHaveBeenCalled(); | ||
| // Ensure the base client is not emitting a warning for this. | ||
| expect(logger.warn).not.toHaveBeenCalled(); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| import { LDLogger, Platform } from '@launchdarkly/js-client-sdk-common'; | ||
| import { LDLogger, Platform, Storage } from '@launchdarkly/js-client-sdk-common'; | ||
|
|
||
| import PlatformCrypto from './crypto'; | ||
| import PlatformEncoding from './PlatformEncoding'; | ||
| import PlatformInfo from './PlatformInfo'; | ||
| import PlatformRequests from './PlatformRequests'; | ||
| import PlatformStorage from './PlatformStorage'; | ||
|
|
||
| const createPlatform = (logger: LDLogger): Platform => ({ | ||
| const createPlatform = (logger: LDLogger, storage?: Storage): Platform => ({ | ||
| crypto: new PlatformCrypto(), | ||
| info: new PlatformInfo(logger), | ||
| requests: new PlatformRequests(logger), | ||
| encoding: new PlatformEncoding(), | ||
| storage: new PlatformStorage(logger), | ||
| storage: storage ?? new PlatformStorage(logger), | ||
| }); | ||
|
|
||
| export default createPlatform; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Additionally the options.ts file validates options.
The validation is only cursory and many examples are available in the common client
Configuration.ts.In this instance we should validate that storage is an object.
The other thing we need to do is remove it from the options passed to the base configuration. Otherwise it will log that it has received an unknown configuration.