opal / opal-browser

Browser support for Opal.
MIT License
115 stars 36 forks source link

fix browser storage #52

Closed fazibear closed 9 years ago

meh commented 9 years ago

I'm pretty sure to recall that was on purpose, because the storage keys can only be strings.

fazibear commented 9 years ago

In this situation keys instead of "smth" become "\"smth\"". Example:

    storage[:test] = {}
    puts storage[:test] # => {}
    storage.reload
    puts storage[:test] # => nil
meh commented 9 years ago

Yes, it's intended, that way you can use anything as key, as is commong with Hash.

meh commented 9 years ago

It seems like something else is broken in the reloading.

fazibear commented 9 years ago

So maybe it should use to_s instead of to_json twice ?

    @data.each {|key, value|
      io << key.to_s.to_json << ":" << value.to_json << ","
    }
meh commented 9 years ago

Maybe .to_json.to_s.

fazibear commented 9 years ago

Both .to_json.to_s and .to_s.to_json work. And you suggest first one is better :+1:

meh commented 9 years ago

Merged.