I wants to change some property or run scripts when particular state exits.
In formal, I will use a variable to save the previous state. When the state changing, checking previous state and determine whether run scripts. But code will more redundant as number of state increase. How can I simplify that?
e.g. How to simplify following code?
Item {
property var work
property var preState
states: [
State {
name: "state1";
...
},
State {
name: "state2";
...
}
...
State {
name: "stateN";
...
}
]
onStateChanged: {
if (preState == "state1") {
...
} else if (preState == "state2") {
...
} else if (preState == "stateN") {
...
}
}
...
}