Skip to content

Instantly share code, notes, and snippets.

@nqthqn
Created August 30, 2017 19:28
Show Gist options
  • Save nqthqn/a1a317aad39e70fc40e6a93a2b048efb to your computer and use it in GitHub Desktop.
Save nqthqn/a1a317aad39e70fc40e6a93a2b048efb to your computer and use it in GitHub Desktop.
Porting to Js
var app = Elm.Main.fullscreen()
app.ports.set.subscribe(function(keyValue) {
var [key, value] = keyValue
window.localStorage.setItem(key,
JSON.stringify(value)
)
})
app.ports.remove.subscribe(function(key) {
localStorage.removeItem(key)
})
app.ports.clear.subscribe(function(i) {
localStorage.clear()
})
port module Ports exposing (..)
import Json.Encode
type alias Key =
String
type alias Value =
Json.Encode.Value
port set : ( Key, Value ) -> Cmd msg
port remove : Key -> Cmd msg
port clear : () -> Cmd msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment