#2648 JS: dom::Win.hisPushState() - stash map can not contain Fantom types

SlimerDude Wed 4 Oct 2017

Using Win.hisPushState() to store simple value types like Str is fine.

But if I store a Fantom object, when I read it back during onEvent() then something is not quite right and an Err is thrown - Not a Fantom type: [object Object]

@Js class MyData {
    Str? data
}

...

Win.cur.hisPushState("foo", `bar`, ["myData":MyData() { data="foobar" }])

Win.cur.onEvent("popstate", false) |e| {
    myData := e.stash["myData"]

    echo(myData)                  // --> [object Object]
    echo(((MyData) myData).data)  // --> Err!
}

Throws "sys::Type.toFanType: Not a Fantom type: [object Object]"

andy Wed 4 Oct 2017

State must be serializable to JSON under the covers.

WinPeer does not fully implement how this might work (and not quite sure it should) -- its basically shimmed to support maps of primitive objects (Str, Int, Float, etc) that can be directly round-tripped from JSON.

Login or Signup to reply.