vendredi 18 avril 2014

Small FSM like code in javascript


Vote count:

0




In an html page I have 2 checkboxes that "complement" each other.

In a nutshell only the following states are valid (will explain this):



Checkbox1 Checkbox2
TRUE FALSE
TRUE TRUE


Also note that when checkbox2 is clicked to be set to true then I programmatically click checkbox1 to be checked.

Of course both can be FALSE but this is a state that I ignore.

What I mean so far is that I use these checkboxes to do a running sum over a table or rows. According to these states I add the amounts or subtract. What I have done works but it seems error-prone and hard to extend. Basically I keep a few global variables which I set/reset according to the states of the checkbox and in one case to signify the previous state and the following state.

Is there a nice way to implement an FSM like code around this functionality I have?



asked 2 mins ago

Jim

2,661





Aucun commentaire:

Enregistrer un commentaire