-
Notifications
You must be signed in to change notification settings - Fork 19
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
chore: RN provider and hooks attempt 2 #321
Merged
Merged
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
cbfd5b1
chore: initial commit.
yusinto da01855
chore: added npm commands to run natively.
yusinto fc41787
chore: fixed wrong listener argument shape. fixed missing error argum…
yusinto 7eb9de5
Delete index.test.tsx
7813408
Update index.ts
c0e4577
fix: erroneous stream uri path
06f08a9
fix: emit ready when put is finished.
yusinto afd4680
fix: override createStreamUriPath so client sdks can specify custom p…
yusinto 9ff4930
fix: createStreamUriPath returns string now.
yusinto ced9caa
fix: fix broken tests related to fromLDContext arg being undefined.
yusinto 51aef40
chore: allow mock streamprocessor to return custom json. starting to …
f8f6c23
chore: return a promise from identify and fix unit tests.
dea6e45
chore: added newline.
efc36ee
chore: removed unused listeners. revert eventSource to private. remov…
900f654
chore: removed variation:error and variation:success. only set ldcont…
yusinto 9d458f2
chore: improve readme.
yusinto 66499d0
chore: refactored promise creation to a separate function.
yusinto cbd13cc
chore: added basic tests.
yusinto cfba59b
Update welcome.tsx
yusinto 0c70c03
fix: disable events for unit tests.
yusinto 5c76d3f
fix: variation calls to fallback to ldClient.
yusinto 9838b07
Update packages/shared/sdk-client/src/LDClientImpl.ts
yusinto 335d3c9
fix: close streamer first before starting. test listener count.
yusinto a419b86
chore: added tsdoc for hooks. corrected LDClient variation tsdoc errors.
yusinto 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 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 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 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 |
---|---|---|
|
@@ -34,3 +34,6 @@ yarn-error.* | |
|
||
# typescript | ||
*.tsbuildinfo | ||
|
||
ios | ||
android |
This file contains 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,44 +1,18 @@ | ||
import { CLIENT_SIDE_SDK_KEY } from '@env'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { StyleSheet, Text, View } from 'react-native'; | ||
import { MOBILE_KEY } from '@env'; | ||
|
||
import { init, type LDClientImpl } from '@launchdarkly/react-native-client-sdk'; | ||
import { LDProvider, ReactNativeLDClient } from '@launchdarkly/react-native-client-sdk'; | ||
|
||
const context = { kind: 'user', key: 'test-user-1' }; | ||
|
||
export default function App() { | ||
const [ldc, setLdc] = useState<LDClientImpl>(); | ||
const [flag, setFlag] = useState<boolean>(false); | ||
import Welcome from './src/welcome'; | ||
|
||
useEffect(() => { | ||
init(CLIENT_SIDE_SDK_KEY, context) | ||
.then((c) => { | ||
setLdc(c); | ||
}) | ||
.catch((e) => console.log(e)); | ||
}, []); | ||
|
||
useEffect(() => { | ||
const f = ldc?.boolVariation('dev-test-flag', false); | ||
setFlag(f ?? false); | ||
}, [ldc]); | ||
const featureClient = new ReactNativeLDClient(MOBILE_KEY); | ||
const context = { kind: 'user', key: 'test-user-1' }; | ||
|
||
const App = () => { | ||
return ( | ||
<View style={styles.container}> | ||
<Text>{flag ? <>devTestFlag: {`${flag}`}</> : <>loading...</>}</Text> | ||
</View> | ||
<LDProvider client={featureClient} context={context}> | ||
<Welcome /> | ||
</LDProvider> | ||
); | ||
} | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
box: { | ||
width: 60, | ||
height: 60, | ||
marginVertical: 20, | ||
}, | ||
}); | ||
export default App; |
This file contains 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 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 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 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 { StyleSheet, Text, View } from 'react-native'; | ||
|
||
import { useBoolVariation, useLDDataSourceStatus } from '@launchdarkly/react-native-client-sdk'; | ||
|
||
export default function Welcome() { | ||
const { error, status } = useLDDataSourceStatus(); | ||
const flag = useBoolVariation('dev-test-flag', false); | ||
console.log(`============== status: ${status}`); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<Text>Welcome to LaunchDarkly</Text> | ||
<Text>status: {status}</Text> | ||
<Text>error: {error?.message}</Text> | ||
<Text>devTestFlag: {`${flag}`}</Text> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
box: { | ||
width: 60, | ||
height: 60, | ||
marginVertical: 20, | ||
}, | ||
}); |
This file contains 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,4 +1,4 @@ | ||
declare module '@env' { | ||
// eslint-disable-next-line import/prefer-default-export | ||
export const CLIENT_SIDE_SDK_KEY: string; | ||
export const MOBILE_KEY: string; | ||
} |
This file contains 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 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
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. These are just basic tests for now. I will add more soon in a separate PR. |
This file contains 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,23 @@ | ||
import { type LDContext } from '@launchdarkly/js-client-sdk-common'; | ||
|
||
import ReactNativeLDClient from './ReactNativeLDClient'; | ||
|
||
describe('ReactNativeLDClient', () => { | ||
let ldc: ReactNativeLDClient; | ||
|
||
beforeEach(() => { | ||
ldc = new ReactNativeLDClient('mob-test'); | ||
}); | ||
|
||
test('constructor', () => { | ||
expect(ldc.sdkKey).toEqual('mob-test'); | ||
}); | ||
|
||
test('createStreamUriPath', () => { | ||
const context: LDContext = { kind: 'user', key: 'test-user-key-1' }; | ||
|
||
expect(ldc.createStreamUriPath(context)).toEqual( | ||
'/meval/eyJraW5kIjoidXNlciIsImtleSI6InRlc3QtdXNlci1rZXktMSJ9', | ||
); | ||
}); | ||
}); |
This file contains 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,18 @@ | ||
import { | ||
base64UrlEncode, | ||
LDClientImpl, | ||
type LDContext, | ||
type LDOptions, | ||
} from '@launchdarkly/js-client-sdk-common'; | ||
|
||
import platform from './platform'; | ||
|
||
export default class ReactNativeLDClient extends LDClientImpl { | ||
constructor(sdkKey: string, options: LDOptions = {}) { | ||
super(sdkKey, platform, options); | ||
} | ||
|
||
override createStreamUriPath(context: LDContext) { | ||
return `/meval/${base64UrlEncode(JSON.stringify(context), platform.encoding!)}`; | ||
} | ||
} |
This file contains 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,6 @@ | ||
import useLDClient from './useLDClient'; | ||
import useLDDataSourceStatus from './useLDDataSourceStatus'; | ||
|
||
export * from './variation'; | ||
|
||
export { useLDDataSourceStatus, useLDClient }; |
This file contains 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,10 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { context, ReactContext } from '../provider/reactContext'; | ||
|
||
const useLDClient = () => { | ||
const { client } = useContext<ReactContext>(context); | ||
return client; | ||
}; | ||
|
||
export default useLDClient; |
10 changes: 10 additions & 0 deletions
10
packages/sdk/react-native/src/hooks/useLDDataSourceStatus.ts
This file contains 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,10 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { context, ReactContext } from '../provider/reactContext'; | ||
|
||
const useLDDataSourceStatus = () => { | ||
const { dataSource } = useContext<ReactContext>(context); | ||
return dataSource; | ||
}; | ||
|
||
export default useLDDataSourceStatus; |
This file contains 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,2 @@ | ||
export * from './useVariation'; | ||
export * from './useTypedVariation'; |
Oops, something went wrong.
Oops, something went wrong.
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.
We need react for
useMemo
.