@@ -11,24 +11,36 @@ import Ur.Deconstructor as D
1111import Ur.Sub.Internal
1212
1313
14−{-| -}
14+{-| Like `Sub` from `Platform.Sub`, but for Urbit subscriptions.
15+-}
1516type alias Sub msg =
1617 Ur.Sub.Internal.Sub msg
1718
1819
19−{-| -}
20+{-| Creates an Urbit subscription.
21+
22+ subscribe
23+ { ship = ship
24+ , app = "journal"
25+ , path = [ "updates" ]
26+ , deconstructor = decodeJournalUpdate |> D.map GotUpdate
27+ }
28+
29+-}
2030subscribe : { ship : String, app : String, path : List String, deconstructor : D.Deconstructor (msg -> msg) msg } -> Sub msg
2131subscribe { ship, app, path, deconstructor } =
2232 Dict.singleton ( ship, app, path ) deconstructor |> Ur.Sub.Internal.Sub
2333
2434
25−{-| -}
35+{-| A subscription that does exactly nothing. (Does not subscribe to anything)
36+-}
2637none : Sub msg
2738none =
2839 Ur.Sub.Internal.Sub Dict.empty
2940
3041
31−{-| -}
42+{-| Batch multiple subscriptions into one.
43+-}
3244batch : List (Sub msg) -> Sub msg
3345batch subs =
3446 subs |> List.map (\(Ur.Sub.Internal.Sub dict) -> dict) |> List.foldl Dict.union Dict.empty |> Ur.Sub.Internal.Sub