serialization - What local-storage tooling does WebSharper provide? -



serialization - What local-storage tooling does WebSharper provide? -

in looking @ documentation websharper's local storage, setitem item string * string -> unit (and getitem string -> string).

this means i'll need convert want store strings , reverse retrieve them. or, set in way, i'll need serialize , de-serialize them. there way utilize behind-the-scenes conversion websharper rpc calls, or stuck using server-side library fspicker?

not built in yet, have been using helper module create local storage usable same way ref cell:

open intellifactory.websharper // helper handling localstorage, making stored value work ref cell. [<javascript; autoopen>] module localstorage = open intellifactory.websharper.html5 allow localstorage = window.self.localstorage type ivalue<'t> = abstract value: 't get, set allow [<inline>] ( ! ) (x: ivalue<_>) = x.value allow [<inline>] ( := ) (x: ivalue<_>) v = x.value <- v // redefining ref utilize ivalue type ref<'t> (value: 't) = allow mutable v = value interface ivalue<'t> fellow member this.value get() = v , set value = v <- value allow [<inline>] ref v = ref v allow incr = := !i + 1 allow decr = := !i - 1 type istorageitem<'t> = inherit ivalue<'t> abstract save: unit -> unit abstract delete: unit -> unit type jsonstorageitem<'t>(key, defaultval) = allow mutable value = none allow getvalue() = match value | v -> v | _ -> allow v = match localstorage.getitem key | null -> defaultval | s -> json.parse s :?> _ value <- v v interface istorageitem<'t> fellow member this.value get() = getvalue() , set v = seek localstorage.setitem(key, json.stringify v) value <- v _ -> javascript.alert "saving info storage failed." fellow member this.save() = seek localstorage.setitem(key, json.stringify (getvalue())) _ -> javascript.alert "saving info storage failed." fellow member this.delete() = localstorage.removeitem key value <- none allow [<inline>] getjsonstorage key defaultval = jsonstorageitem<_>(key, defaultval) :> istorageitem<_>

however can stringify/parse straight info objects: record, list, array, tuple , union types ok, no prototypes restored.

serialization f# local-storage websharper

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -