Skip to content

Commit

Permalink
Fix documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSStewart committed Aug 29, 2021
1 parent c92386b commit 5f5acca
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 49 deletions.
File renamed without changes.
41 changes: 33 additions & 8 deletions src/Effect/Command.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Effect.Command exposing
( none, batch
( Command, none, batch, sendToJs, FrontendOnly, BackendOnly
, map
, BackendOnly, Command, FrontendOnly, PortToJs, sendToJs
)

{-|
Expand All @@ -18,7 +17,7 @@ module Effect.Command exposing
# Commands
@docs Cmd, none, batch
@docs Command, none, batch, sendToJs, FrontendOnly, BackendOnly
# Fancy Stuff
Expand All @@ -31,10 +30,30 @@ import Effect.Internal exposing (Command(..), NavigationKey, Subscription(..))
import Json.Encode


{-| `Command`s and `Subscription`s with this type variable indicate that they can only be used on the frontend.
import Command exposing (Command, FrontendOnly)
import Effect.File.Select
download : Command FrontendOnly toMsg msg
download =
Effect.File.Select "/my-file.txt"
-}
type alias FrontendOnly =
Effect.Internal.FrontendOnly


{-| `Command`s and `Subscription`s with this type variable indicate that they can only be used on the backend.
import Command exposing (BackendOnly, Command)
import Effect.Lamdera exposing (ClientId)
sendData : ClientId -> Command BackendOnly toMsg msg
sendData clientId =
Effect.Lamdera.sendToFrontend clientId data
-}
type alias BackendOnly =
Effect.Internal.BackendOnly

Expand Down Expand Up @@ -78,16 +97,22 @@ none =
None


{-| -}
{-| This function sends data to JS land. Below is an example of how to use it.
import Command
import Json.Encode
port copyToClipboardPort : Cmd Json.Encode.Value -> msg
copyToClipboard value =
Command.sendToJs "copyToClipboardPort" copyToClipboardPort value
-}
sendToJs : String -> (Json.Encode.Value -> Cmd msg) -> Json.Encode.Value -> Command FrontendOnly toMsg msg
sendToJs =
Port


type alias PortToJs =
{ portName : String, value : Json.Encode.Value }


{-| Transform the messages produced by a command.
Very similar to [`Html.map`](/packages/elm/html/latest/Html#map).
Expand Down
17 changes: 8 additions & 9 deletions src/Effect/Http.elm
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module Effect.Http exposing
( get, post, request
, Header, header
, emptyBody, stringBody, jsonBody
, Body, emptyBody, stringBody, jsonBody
, Expect(..), expectString, expectJson, expectWhatever, Error(..)
, expectStringResponse, Response(..)
, task, Resolver, stringResolver
, HttpBody
)

{-| This module parallels [elm/http's `Http` module](https://package.elm-lang.org/packages/elm/http/2.0.0/Http).
Expand Down Expand Up @@ -64,7 +63,7 @@ type alias Header =

{-| Represents the body of a `Request`.
-}
type alias HttpBody =
type alias Body =
Effect.Internal.HttpBody


Expand All @@ -91,7 +90,7 @@ get r =
-}
post :
{ url : String
, body : HttpBody
, body : Body
, expect : Expect msg
}
-> Command restriction toFrontend msg
Expand All @@ -113,7 +112,7 @@ request :
{ method : String
, headers : List Header
, url : String
, body : HttpBody
, body : Body
, expect : Expect msg
, timeout : Maybe Duration
, tracker : Maybe String
Expand Down Expand Up @@ -163,22 +162,22 @@ header =

{-| Create an empty body for your `Request`.
-}
emptyBody : HttpBody
emptyBody : Body
emptyBody =
EmptyBody


{-| Put some JSON value in the body of your `Request`. This will automatically
add the `Content-Type: application/json` header.
-}
jsonBody : Json.Encode.Value -> HttpBody
jsonBody : Json.Encode.Value -> Body
jsonBody value =
JsonBody value


{-| Put some string in the body of your `Request`.
-}
stringBody : String -> String -> HttpBody
stringBody : String -> String -> Body
stringBody contentType content =
StringBody
{ contentType = contentType
Expand Down Expand Up @@ -344,7 +343,7 @@ task :
{ method : String
, headers : List Header
, url : String
, body : HttpBody
, body : Body
, resolver : Resolver restriction x a
, timeout : Maybe Duration
}
Expand Down
7 changes: 2 additions & 5 deletions src/Effect/Lamdera.elm
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
module Effect.Lamdera exposing
( frontend, backend, sendToBackend, sendToFrontend, broadcast, onConnect, onDisconnect, ClientId, SessionId, Url, Document, Key, UrlRequest
, clientIdFromString, clientIdToString, sessionIdFromString, sessionIdToString
)
module Effect.Lamdera exposing (frontend, backend, sendToBackend, sendToFrontend, broadcast, onConnect, onDisconnect, ClientId, clientIdToString, clientIdFromString, SessionId, sessionIdToString, sessionIdFromString, Url, Document, Key, UrlRequest)

{-| backend
@docs frontend, backend, sendToBackend, sendToFrontend, broadcast, onConnect, onDisconnect, clientConnected_, clientDisconnected_, ClientId, SessionId, Url, Document, Key, UrlRequest
@docs frontend, backend, sendToBackend, sendToFrontend, broadcast, onConnect, onDisconnect, ClientId, clientIdToString, clientIdFromString, SessionId, sessionIdToString, sessionIdFromString, Url, Document, Key, UrlRequest
-}

Expand Down
19 changes: 15 additions & 4 deletions src/Effect/Subscription.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Effect.Subscription exposing
( none, batch
( Subscription, none, batch, fromJs
, map
, Subscription, fromJs
)

{-|
Expand All @@ -18,7 +17,7 @@ module Effect.Subscription exposing
# Subscriptions
@docs Sub, none, batch
@docs Subscription, none, batch, fromJs
# Fancy Stuff
Expand Down Expand Up @@ -72,7 +71,19 @@ none =
Effect.Internal.SubNone


{-| -}
{-| This function listens for data from JS land. Below is an example of how to use it.
import Subscription exposing (Subscription)
import Command exposing (FrontendOnly)
import Json.Decode
port scrollEventPort : (Json.Decode.value -> msg) -> Sub msg
copyToClipboard : (Json.Decode.value -> msg) -> Subscription FrontendOnly msg
copyToClipboard msg =
Subscription.fromJs "scrollEventPort" scrollEventPort msg
-}
fromJs : String -> ((Json.Decode.Value -> msg) -> Sub msg) -> (Json.Decode.Value -> msg) -> Subscription FrontendOnly msg
fromJs portName portFunction msg =
Effect.Internal.SubPort portName (portFunction msg) msg
Expand Down
Loading

0 comments on commit 5f5acca

Please sign in to comment.