I have the following code running inside a reducer:
Circuit.log("---");
Circuit.log("reducer action=", action);
Circuit.log("reducer before state=", state);
let notFinished = state.total.lessThan(requiredVotes);
let mustCount = notFinished && action.isValid;
Circuit.log("reducer notFinished=", notFinished, "isValid=", action.isValid, " mustCount=", mustCount);
state.total = Circuit.if(mustCount, state.total.add(1), state.total);
state.positive = Circuit.if(mustCount && action.positive, state.positive.add(1), state.positive);
state.negative = Circuit.if(mustCount && action.negative, state.negative.add(1), state.negative);
state.ignored = Circuit.if(mustCount && action.ignore, state.ignored.add(1), state.ignored);
Circuit.log("reducer after state=", state);
return state;
In the test case I am using requiredVotes = 3 and it should process 4 actions. The log is:
...
reducer action= { ignore: false, isValid: true, negative: false, positive: true }
reducer before state= { ignored: '0', negative: '0', positive: '2', total: '2' }
reducer notFinished= true isValid= true mustCount= true
reducer after state= { ignored: '0', negative: '0', positive: '3', total: '3' }
---
reducer action= { ignore: false, isValid: true, negative: false, positive: true }
reducer before state= { ignored: '0', negative: '0', positive: '3', total: '3' }
reducer notFinished= false isValid= true mustCount= true
reducer after state= { ignored: '0', negative: '0', positive: '4', total: '4' }
---
PROBLEM: the 4th time variable notFinished is false and isValid is true, and so mustCount should be false as it is evaluated using notFinished && isValid.
**But it is true !!! What is happening here ? **