I'm building my first application and I'm trying to store/restore the state of the application.
I was thinking to use symbols for keys or values for the state dictionary, but it does not work.
This works perfectly:
function onStart(state) {
if(state != null) {
Sys.println(state.get("hey")); //print "ho"
}
}
function onStop(state) {
state.put("hey", "ho");
}
This does not work:
function onStart(state) {
if(state != null) {
Sys.println(state.get(:hey));
}
}
function onStop(state) {
state.put(:hey, "ho");
}
Much more embarrassing, it is also not possible to store symbols as values of the state dictionary:
function onStart(state) {
if(state != null) {
var ho = state.get("hey"));
Sys.println(ho == :ho); //print false
}
}
function onStop(state) {
state.put("hey", :ho);
}
Moreover, in the last two cases, the simulator has a very confusing behavior: it returns the last valid state (i.e. if you execute these three pieces of code one after the other, you get {"hey" => "ho"} for the state in the second and third example).
Is it a bug? My understanding is that symbols are managed at compile time. So it should not be a problem to use them as key or value for the application state.
Matthieu.