Add hook to transform toggles before updating #249
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.
I would like to propose a new configuration option for the unleash-proxy-client-js library that allows clients to asynchronously transform the list of feature toggles before the internal state is updated. This would provide a clean, flexible way to manage which toggles are updated, without overriding core logic such as the fetch method.
About the changes
In the current implementation, when the Unleash proxy client fetches toggles, it updates the internal state with the entire list of toggles returned by the proxy. This behavior works well for most scenarios, but introduces limitations for more complex use cases where only a subset of toggles should be processed. In our project, we want to update the list of feature flags with not very complex logic to not break the client and not to over-complicate the logic that could result in bad UX.
To work around this, I’m currently overriding the fetch method entirely, just to inject toggle transformation logic. However, this approach has significant downsides:
My actual goal is not to replace fetch, but simply to intercept or shape the list of toggles before they’re applied to the client.
Adding my PR to your existing codebase will provide the possibility to the users to dynamically modify or filter the list of toggles after they are fetched from the Unleash proxy or the Unleash Edge — but before they’re applied to the client.
This is especially useful for cases where toggle processing depends on external data, such as user roles, remote config, or custom logic that requires asynchronous operations.
When it could be to used:
Open issues
This PR Closes #248