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

feat: make updateToggles and sendMetrics available as public methods #226

Merged
merged 5 commits into from
Aug 14, 2024

Conversation

jeremiewtd
Copy link
Contributor

About the changes

In order to manage contexts where the internal refresh mechanism does not correspond to technical needs or constraints (Service Workers for example), we propose to make the updateToggles and sendMetrics methods available as public as discussed in this conversation.

Closes second part of #201

@Tymek Tymek self-requested a review August 14, 2024 08:27
Copy link

@melindafekete melindafekete left a comment

Choose a reason for hiding this comment

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

Docs LGTM ✅

src/index.test.ts Outdated Show resolved Hide resolved
@@ -2268,3 +2289,54 @@ describe('Experimental options togglesStorageTTL enabled', () => {
});
});
});

describe('updateToggles', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wanted to suggest that we don't add the word toggles in the public API since we already migrated most UI facing code to flags instead of toggles. But since we already have a public method called getAllToggles in this SDK then introducing another convention adds more confusion rather than improving clarity.

Copy link
Contributor

Choose a reason for hiding this comment

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

So no action needed IMO

README.md Outdated

## Manage your own refresh mechanism

If you do not want to use the internal refresh mechanism provided by the `refreshInterval` or `metricsInterval` options, you can handle it yourself using the public `updateToggles` and `sendMetrics` methods.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest that we give more guidance to others willing to try this approach. What I'm missing is the information that we should skip calling the start method on initialization.

Copy link
Contributor

@kwasniew kwasniew Aug 14, 2024

Choose a reason for hiding this comment

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

e.g. "You can opt out of the Unleash feature flag auto-refresh mechanism by not calling the start method. In this case, it becomes your responsibility to call updateToggles and sendMetrics. This approach is useful in environments that do not support the setInterval API, such as service workers."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to call the start method (no initial fetch otherwise) but what is needed is to set disableMetrics: true and/or disableRefresh: true in the options in order to handle it ourselves.

Copy link
Contributor

@kwasniew kwasniew Aug 14, 2024

Choose a reason for hiding this comment

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

Ah of course. You're right. Let's document it then to be extra clear in this section :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doc updated

Copy link
Contributor

@kwasniew kwasniew left a comment

Choose a reason for hiding this comment

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

I like the change as it opens more DIY options. Also very good test coverage. Thanks @jeremiewtd !

@kwasniew kwasniew merged commit 4b58250 into Unleash:main Aug 14, 2024
3 checks passed
@kwasniew
Copy link
Contributor

kwasniew commented Aug 14, 2024

@jeremiewtd We've just released 3.6.0-beta.1 to npm. Feel free to use it in your context and provide feedback. Once we're happy with the results we can cut a non-beta 3.6.0 release.

@ivarconr ivarconr mentioned this pull request Aug 23, 2024
@jeremiewtd
Copy link
Contributor Author

@jeremiewtd We've just released 3.6.0-beta.1 to npm. Feel free to use it in your context and provide feedback. Once we're happy with the results we can cut a non-beta 3.6.0 release.

@kwasniew we have been using beta.0 for over two weeks and beta.1 for few days and everything is working as expected for us

@kwasniew
Copy link
Contributor

kwasniew commented Aug 29, 2024

@jeremiewtd Thank you! We've been just discussing if we can cut a new version so your feedback is very timely :) cc @ivarconr

@ivarconr
Copy link
Member

thumbsup @kwasniew

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.

5 participants