liqula / react-hs

A GHCJS binding to React based on the Flux design. The flux design pushes state and complicated logic out of the view, allowing the rendering functions and event handlers to be pure Haskell functions.
32 stars 10 forks source link

How to interact with localStorage #32

Open tysonzero opened 7 years ago

tysonzero commented 7 years ago

It would be really cool if there was a way to automatically, or perhaps just using a small number of helper functions, save and load store data in local storage. In my case I am storing authentication tokens, and I definitely don't want them removed by a refresh. What is the best way to do this at the moment, and if the current way isn't particularly easy how would I go about making a PR for the above?

fisx commented 7 years ago

Haven't done that yet, not sure it's supported by the library. What I would do in such cases is look up the browser functions that do this, wrap them in foreign declarations with some simple marshalling into haskell types around them, and then start using them.

If you want local storage support to go into the library, you can either post pseudo-code here or open a PR right away, whichever is easier for you.

tysonzero commented 7 years ago

Yeah that sounds good, will do that at some point. Out of interest how is everyone dealing with things like login tokens and such currently then?

fisx commented 7 years ago

We're using https://github.com/zerobuzz/servant-cookie-session. This takes care of authenticating and protecting the session, but there is certainly room for a higher-level library to make things more convenient.

fisx commented 7 years ago

See also: #29. I propose somebody write an example as described by @tysonzero there and we close both #29 and #32 with that.