Renamed to fission-codes/webnative-elm. It is published under that name, and new versions come out there.
Versions published as fission-suite/webnative-elm still install under that name. 9 versions of 9 come from the new location (see their notes).
Rerouted (renamed, verified). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/fission-codes/webnative-elm.
What we checked: The repo moved to github.com/fission-codes/webnative-elm. Rebuilt with git archive from commit 51298c074411 of https://github.com/fission-codes/webnative-elm (zip prefix fission-suite-webnative-elm-51298c0/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 d71c860ac0aee89af4bf857a8cb19139a74eb6e9.
The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.
Details · package.elm-lang.org's zip: https://github.com/fission-suite/webnative-elm/zipball/1.0.0/
A thin wrapper around webnative for Elm.
elm install fission-suite/webnative-elm
npm install webnative-elm webnativeSetup the necessary ports on your Elm app.
port module Ports exposing (..)
import Webnative
port webnativeRequest : Webnative.Request -> Cmd msg
port wnfsRequest : Webnative.Request -> Cmd msg
port wnfsResponse : (Webnative.Response -> msg) -> Sub msgThen import the javascript portion of this library to connect up the ports.
import * as webnative from "webnative"
import * as webnativeElm from "webnative-elm"
// elmApp = Elm.Main.init()
webnative
.initialise({
permissions: {
app: { creator: "Fission", name: "Example" }
}
})
.then(state => {
webnativeElm.setup(elmApp, state.fs)
})Once we have that setup, we need can write our webnative Elm code.
import Webnative
import Wnfs
type Msg
= ReadWnfsFile
| WriteToWnfsFile
--
| GotWnfsResponse
type Tag
= ReadHelloTxt
| Mutation
base : Wnfs.Base Webnative.Response
base =
Wnfs.AppData
{ creator = "Fission"
, name = "Example"
}
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
ReadWnfsFile ->
{ path = [ "hello.txt" ]
, tag = tagToString ReadHelloTxt
}
|> Wnfs.readUtf8 base
|> Ports.wnfsRequest
|> Tuple.pair model
WriteToWnfsFile ->
"👋"
|> Wnfs.writeUtf8 base
{ path = [ "hello.txt" ]
, tag = tagToString Mutation
}
|> Ports.wnfsRequest
|> Tuple.pair model
--
GotWnfsResponse response ->
case Wnfs.decodeResponse tagFromString response of
Ok ( ReadHelloTxt, Wnfs.Utf8Content helloContents ) ->
-- Do something with content from hello.txt
Ok ( Mutation, _ ) ->
( model
, Ports.wnfsRequest Wnfs.publish
)
Err errString ->
-- Decoding, or tag parse, error.
-- TAG ENCODING/DECODING
tagToString : Tag -> String
tagToString tag =
case tag of
ReadHelloTxt -> "ReadHelloTxt"
Mutation -> "Mutation"
tagFromString : String -> Result String Tag
tagFromString string =
case string of
"ReadHelloTxt" -> Ok ReadHelloTxt
"Mutation" -> Ok Mutation
_ -> Err "Invalid tag"You can chain webnative commands in Elm by providing a tag, which is then attached to the response. In the following example I have a custom type for my tags, which I then encode/decode to/from a string.
type Tag = Mutation
-- Request
Wnfs.writeUtf8 base
{ path = [ "hello.txt" ]
, tag = tagToString Mutation
}
-- Response
case Wnfs.decodeResponse tagFromString response of
Ok ( Mutation, _ ) ->
( model
, Ports.wnfsRequest Wnfs.publish
)We don't support all the functions from webnative yet.
For now you can do the following from Elm:
More coming later.
Let us know if you have any requests.
You can customise the port names by passing in a third parameter.
webnativeElm.setup(elmApp, state.fs, {
webnative: {
incoming: "webnativeRequest"
},
wnfs: {
incoming: "wnfsRequest",
outgoing: "wnfsResponse"
}
})