-
Notifications
You must be signed in to change notification settings - Fork 74
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
fix: getToggle by name may not find the toggle #455
Conversation
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.
Looks like a sensible change to me: I love that we're explicit about returning undefined if the feature doesn't exist 😄 But I've got a question on relaxing function parameters: I'm not sure we should allow isFeatureEnabled
to be called with an undefined
feature. 🤔 But that said, I'm guessing we already do that today, so this PR only updates the code to reflect reality and does not do anything to address any issues?
isFeatureEnabled( | ||
feature: FeatureInterface | undefined, | ||
context: Context, | ||
fallback: Function, | ||
): boolean { |
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.
Why are we changing the accepted parameter value? Surely, there's no point in ever calling this with a feature that's undefined
? Wouldn't it be better to only allow you to call it with a defined feature?
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.
yes! Very good point, this is just the result of type refactoring, but I can look into this as it definitely makes sense!
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.
I think the more interesting question is: why is this method public? It's called by isEnabled
which takes a string, resolves a toggle and calls this with the results and therefore and be called with an undefined. But what else is actually using this?
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.
Ok, I analyzed the option of always receiving something defined, but that'd be a breaking change. Right now this method accepts undefined but the type system does not reflect that. The proof is this line in the method body:
unleash-client-node/src/client.ts
Lines 73 to 76 in 55274e4
isFeatureEnabled(feature: FeatureInterface, context: Context, fallback: Function): boolean { | |
if (!feature) { | |
return fallback(); | |
} |
So, we're not changing the parameter value, we're just making it reflect the reality
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.
Spec tests pass, change looks reasonable LGTM
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.
Nice. I consider this a bug-fix.
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [unleash-client](https://togithub.com/Unleash/unleash-client-node) | [`3.20.0` -> `3.21.0`](https://renovatebot.com/diffs/npm/unleash-client/3.20.0/3.21.0) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>Unleash/unleash-client-node</summary> ### [`v3.21.0`](https://togithub.com/Unleash/unleash-client-node/releases/tag/v3.21.0) [Compare Source](https://togithub.com/Unleash/unleash-client-node/compare/v3.20.0...v3.21.0) #### What's Changed - fix: getToggle by name may not find the toggle by [@​gastonfournier](https://togithub.com/gastonfournier) in [https://github.com/Unleash/unleash-client-node/pull/455](https://togithub.com/Unleash/unleash-client-node/pull/455) - chore: release 3.21.0 by [@​gastonfournier](https://togithub.com/gastonfournier) in [https://github.com/Unleash/unleash-client-node/pull/458](https://togithub.com/Unleash/unleash-client-node/pull/458) #### New Contributors - [@​gastonfournier](https://togithub.com/gastonfournier) made their first contribution in [https://github.com/Unleash/unleash-client-node/pull/455](https://togithub.com/Unleash/unleash-client-node/pull/455) **Full Changelog**: Unleash/unleash-client-node@v3.20.0...v3.21.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/Unleash/unleash). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMTAuMCIsInVwZGF0ZWRJblZlciI6IjM1LjExMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
About the changes
Node SDK interface should notify that getting a toggle by name can return undefined if the toggle does not exist:
https://github.com/Unleash/unleash/blob/d298b04cb2864b4853ca456e402714c98adaf932/src/lib/proxy/proxy-repository.ts#L75-L77