Closed behrad closed 11 years ago
In a task config, you can use whatever property you like to check whether it's a non-value. We like to use if
.
{ "$function": "console.print", "$args": "hello", "if": {$truth.is.out.there}" }
As for the else
clause, you can use $empty
to signal that the task's completed but returned a non-value:
[
{ "$function": "Math.floor", "$args": 0.1, "$set": "resultTruthy", "$empty": "resultFalsy" },
{ "if": "{$resultTruthy}", "$function": "console.print", "$args": "hello" },
{ "if": "{$resultFalsy}", "$function": "console.print", "$args": "bye-bye" }
] // would print `bye-bye' because 0 is a non-value in dataflo.ws
To use $empty, I tested your sample and it didn't work for me saying:
unsatisfied requirements: console.print => if; console.print => if;
I'm using version 0.0.38
@katspaugh I also check with 0.0.39, and $empty
is not working
I just noticed that $empty is working for void values: https://github.com/apla/dataflo.ws/blob/master/workflow.js#L350 I considered it to be working for all falsy values, as defined by common.isEmpty
@behrad thanks for digging it up, I didn't know myself.
@katspaugh I've also moved the empty call into task completion handler, where to set empty for all tasks (not only $function type of tasks), Can you merge with my pull request?
@apla can you merge it in?
How can I check condition or do branching?