Open eztzachi opened 9 years ago
I think the challenge here will be to do this without any change to the basic RouteUnit, WorkUnit, LogicUnit and Looper. Then we can see if it can be enhanced otherwise?
Few things that made me busy today:
For reference:
OK, for now I am moving on with ScriptEngine using Groovy, and reflection (of course). It is also quite clear that the @PreCondition will reflect a Boolean expression. But what about the @PostCondition? Do we want is a Boolean expression as well, because sometimes it is just not enough, and more than that, it will require another level of translation. I am adding few example, and wait to hear what do you think.
Let's say that our generic T is class A:
Ex. 1 - Boolean Condition - the state of a by the end of the function is not clear (is the new a is 2, 5, -9) : @PreCondition(expression = "a != null && a.x == 1") @PostCondition(expression = "old.a.x < a.x") public static void useA(A a){ a.increaseX(); }
Ex.2 - Script execution - it is not only as simple as this @PreCondition(expression = "a != null && a.x == 1") @PostCondition(expression = "a.x=-9") public static void useA(A a){ a.x=-9 }
Ex.3 -Bollean condition - but it is not really clear what I should to with that @PreCondition(expression = "a != null") @PostCondition(expression = "a.map.get('hello')!=null") public static void useA(A a){ // something here }
Another issue here is how to implement it when the return value is an array - like in the LogicUnit
I think PostCondition being a boolean is everything we need - its a condition, it makes sense for it to be like that. Can you give an example where it should be something else?
About the array, I think the PostCondition should just apply to all elements of the array. Users could have a big “OR” between the post conditions, if they wanted to have different results. Perhaps we should also have an operator for “exists”, to make sure that a certain condition applies to at least one (or exactly one?) result.
On Sun, Jan 4, 2015 at 3:40 AM, eztzachi notifications@github.com wrote:
Another issue here is how to implement it when the return value is an array - like in the LogicUnit
Reply to this email directly or view it on GitHub: https://github.com/aviadbd/winter/issues/17#issuecomment-68617164
Lets put the array as a separate issue for now....
I do not think that a boolean itself is not enough. Let's take for example @PostCondition(expression = "a.map.get('hello')!=null"):
Let me know your thoughts
By the way, the PreCondition has a pretty simple implementation without any translation needed - just by using the eval function - since no change on the object is needed
Was first discussed on issue #12