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

Modify Provider to keep the latest flags even when it is remounted #238

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

Conversation

bufferings
Copy link

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

#237

Describe the solution you've provided

Provide a clear and concise description of what you expect to happen.

Describe alternatives you've considered

Provide a clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context about the pull request here.

Comment on lines 43 to 44
const initialFlags = options?.bootstrap && options.bootstrap !== 'localStorage' ? options.bootstrap : fetchedFlags;
let currentFlags = initialFlags;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can just re-use the initialFlags variable for this purpose:

Suggested change
const initialFlags = options?.bootstrap && options.bootstrap !== 'localStorage' ? options.bootstrap : fetchedFlags;
let currentFlags = initialFlags;
let initialFlags = options?.bootstrap && options.bootstrap !== 'localStorage' ? options.bootstrap : fetchedFlags;

Copy link
Author

Choose a reason for hiding this comment

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

@yusinto

Thank you for your suggestion! After I changed to use initialFlags, I felt the variable was no longer initial. So I tried to use currentFlags. Please could you have a look at it? If it's better to use initialFlags instead of currentFlags or any better names, please let me know and I would change it.

Comment on lines +48 to +49
unproxiedFlags: currentFlags,
...getFlagsProxy(ldClient, currentFlags, reactOptions, targetFlags),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
unproxiedFlags: currentFlags,
...getFlagsProxy(ldClient, currentFlags, reactOptions, targetFlags),
unproxiedFlags: initialFlags,
...getFlagsProxy(ldClient, initialFlags, reactOptions, targetFlags),

Comment on lines 57 to 58
const updatedUnproxiedFlags = { ...unproxiedFlags, ...updates };
currentFlags = updatedUnproxiedFlags;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const updatedUnproxiedFlags = { ...unproxiedFlags, ...updates };
currentFlags = updatedUnproxiedFlags;
initialFlags = { ...unproxiedFlags, ...updates };

@@ -54,6 +55,7 @@ export default async function asyncWithLDProvider(config: AsyncProviderConfig) {
if (Object.keys(updates).length > 0) {
setLDData(({ unproxiedFlags }) => {
const updatedUnproxiedFlags = { ...unproxiedFlags, ...updates };
currentFlags = updatedUnproxiedFlags;

return {
unproxiedFlags: updatedUnproxiedFlags,
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace updatedUnproxiedFlags with initialFlags in the return object:

Suggested change
unproxiedFlags: updatedUnproxiedFlags,
unproxiedFlags: initialFlags,
...getFlagsProxy(ldClient, initialFlags, reactOptions, targetFlags),

src/asyncWithLDProvider.tsx Show resolved Hide resolved
src/asyncWithLDProvider.test.tsx Outdated Show resolved Hide resolved
src/asyncWithLDProvider.test.tsx Outdated Show resolved Hide resolved
src/asyncWithLDProvider.test.tsx Outdated Show resolved Hide resolved
@bufferings bufferings requested a review from yusinto March 15, 2024 23:20
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.

None yet

2 participants