on master help sign in
Added basic readme (#5)
commitd3af60357f13f8adbb93411301bda243d8e6744b authoriko <mail@iko.soy> dateSun 18 Jun 2023, 13:03 (3 years ago) parent30946b3
2 files changed+32
README.md+32 res/airlock.jpeg
README.mdnew file+32
@@ -0,0 +1,32 @@
1+# Airlock
2+
3+![](res/airlock.jpeg)
4+
5+## Usage
6+
7+### FFI
8+
9+Urbit subscriptions require [server-side event (SSE)](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events).
10+Unfortunately, Elm does not provide a native implementation.
11+This means that we will need to use [JS FFI (aka ports)](https://guide.elm-lang.org/interop/ports.html).
12+
13+#### Setting up the Elm side
14+
15+You would need to declare two ports for Airlock to use:
16+
17+1. `port createEventSource : String -> Cmd msg`
18+
19+ This sets up the SSE channel.
20+2. `port onEventSourceMessage : (JD.Value -> msg) -> Sub msg`
21+ This recieves the actual messages from the SSE channel.
22+
23+These two functions need to be passed to one of the functions from `Ur.Run` module.
24+The functions in `Ur.Run` are the same as functions from `Browser`, but have a couple of extra urbit-specific fields.
25+
26+#### Setting up the JS side
27+
28+The SSE JS code is neatly packed into [example/fetch-event-source.js](example/fetch-event-source.js).
29+All you need to do is pass them to Elm ports like in [example/script.js](example/script.js).
30+
31+You can see a full working example in [example](example).
32+
res/airlock.jpegnew file

Binary file not shown.