Conversation
jasmith-hs
left a comment
There was a problem hiding this comment.
This is definitely more sustainable than the current approach, and it lets you define features for extensions of Jinjava!
|
|
||
| import java.util.function.Supplier; | ||
|
|
||
| public class DelegatingFeatureActivationStrategy implements FeatureActivationStrategy { |
There was a problem hiding this comment.
I think DisabledFeatureActivationStrategy, DelegatingFeatureActivationStrategy, and StaticFeatureActivationStrategy are redundant implementations as you can use a lambda:
FeatureConfig
.newBuilder()
.add(name1, () -> false)
.add(name2, () -> true)
.add(name3, supplier)There was a problem hiding this comment.
Agreed. I wanted some simple and standard way to get strategies that were always or off. I removed those classes and added some static delegating strategies instead.
There was a problem hiding this comment.
The DelegatingFeatureActivationStrategy boilerplate can be removed too
There was a problem hiding this comment.
Done and also isActive now gets Context objects so it can make decisions based on other data that's in there, perhaps a user or customer userid.
| public static final FeatureActivationStrategy INACTIVE = DelegatingFeatureActivationStrategy.of( | ||
| () -> false | ||
| ); | ||
| public static final FeatureActivationStrategy ACTIVE = DelegatingFeatureActivationStrategy.of( | ||
| () -> true | ||
| ); |
There was a problem hiding this comment.
| public static final FeatureActivationStrategy INACTIVE = DelegatingFeatureActivationStrategy.of( | |
| () -> false | |
| ); | |
| public static final FeatureActivationStrategy ACTIVE = DelegatingFeatureActivationStrategy.of( | |
| () -> true | |
| ); | |
| public static final FeatureActivationStrategy INACTIVE = () -> false; | |
| public static final FeatureActivationStrategy ACTIVE = () -> true; |
|
|
||
| import java.util.function.Supplier; | ||
|
|
||
| public class DelegatingFeatureActivationStrategy implements FeatureActivationStrategy { |
There was a problem hiding this comment.
The DelegatingFeatureActivationStrategy boilerplate can be removed too
When building #1065, I didn't like adding yet another property to the JinjavaConfig builder. I figured we could use a simple Feature Flags implementation.
Partially inspired by https://ff4j.org/ and https://www.togglz.org/ .
This can replace any boolean configs like enablePreciseDivideFilter, enableRecursiveMacroCalls, failOnUnknownTokens, nestedInterpretationEnabled and more in the future.