You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are manipulating Configs in a few places in our code and using a good bit of nesting. I find the code to be rather messy because of the need to manipulate String formats to define keys and the final ConfigValueFactory.fromAnyRef() call for the actual value. I am interested in submitting a PR to modify the Config interface based on what I have done to simplify our code. But first I want to ask for feedback on the high level idea. Would this violate some design principal, etc?
To make our code more legible I have created a small helper class that wraps a Config instance. The helper lets the user add values by invoking a method which accepts Object.... The first n-1 elements of the array are converted into a . delimited String which is used as a key. The final element of the array is put through ConfigValueFactory.fromAnyRef().
new Helper()
.withHelperValue(k1, k2, k3, "value goes here")
The benefit is amplified when there are multiple calls to .withValue . Further, I added to the helper class a withFallback wrapper so that it can handle interspersed calls to withHelperValue and withFallback.
I think that the only thing that would be needed to add this functionality to Config itself would be something like withKeyValue(Object...). The implementation in SimpleConfig is fairly obvious.
The text was updated successfully, but these errors were encountered:
We are manipulating Configs in a few places in our code and using a good bit of nesting. I find the code to be rather messy because of the need to manipulate String formats to define keys and the final
ConfigValueFactory.fromAnyRef()
call for the actual value. I am interested in submitting a PR to modify the Config interface based on what I have done to simplify our code. But first I want to ask for feedback on the high level idea. Would this violate some design principal, etc?To make our code more legible I have created a small helper class that wraps a Config instance. The helper lets the user add values by invoking a method which accepts
Object...
. The first n-1 elements of the array are converted into a.
delimited String which is used as a key. The final element of the array is put through ConfigValueFactory.fromAnyRef().The result is that lines like this
Can be replaced with:
The benefit is amplified when there are multiple calls to
.withValue
. Further, I added to the helper class awithFallback
wrapper so that it can handle interspersed calls towithHelperValue
andwithFallback
.A rough interface for the class is:
I think that the only thing that would be needed to add this functionality to
Config
itself would be something likewithKeyValue(Object...)
. The implementation inSimpleConfig
is fairly obvious.The text was updated successfully, but these errors were encountered: