cap-js-community / feature-toggle-library

SAP BTP feature toggle library enables Node.js applications using the SAP Cloud Application Programming Model to maintain live-updatable feature toggles via Redis.
https://cap-js-community.github.io/feature-toggle-library/
Apache License 2.0
5 stars 2 forks source link

The values passed to change handlers should never be null #64

Closed rlindner81 closed 5 months ago

rlindner81 commented 6 months ago

The change handlers don't hold state and can't resolve null to the fallback value, so they should always get the actual value...

There is also a subtlety here, where using null for a scoped value can cause the new value to not be the fallback value, because another, broader scoped value could still apply.

rlindner81 commented 5 months ago

⚠️ The changeHandler and scope concepts are tricky to mix. Because the newValue that the changeHandler gets is only relative to the scopeMap that was last touched. And sometimes multiple values change at once with the clearSubScopes option. The easiest fix is making sure that the changeHandler is only called after the change happened internally and then the code in the changeHandler can do a get with the relevant runtime scopes that they care about... Still, for superficial use-cases with no scopes involved, it would be nice if the changeHandler callback API gives you the newValue directly.