I want to decrease a counter by 1 every time listIcon is clicked, but the decrease is only firing once.
counterValue = 3counter.templateFormatter = (value) -> Math.round(value)
counter.animate template: counterValue
listIcon.onClick -> print "trigger" counter.animate template: counterValue - 1
How can I get this to fire until the counter is 0, where it stops?
The problem you have is that clicking listIcon animates the counter to a number equal to whatever counterValue is minus 1. This will always be 2, because you never set the value of counterValue to that new value-minus-one.
The solution is to decrement the counterValue and then animate to it. Then put it all under a conditional that won't do anything if counterValue reaches 0.
thanks for the replies and the explanation, makes a lot of sense now