Update examples in Room docstrings after refactor
The examples given for safe and unsafe multiple message/event
sending are updated to match the call signatures introduced in
770423bcd2
pull/2/head
parent
1f0b817697
commit
ef9a22bde5
|
@ -168,10 +168,7 @@ roomId =
|
||||||
|
|
||||||
{-| Send an unformatted text message to a room.
|
{-| Send an unformatted text message to a room.
|
||||||
|
|
||||||
task =
|
sendMessage { room = someRoom, onResponse = MessageSent, text = "Hello!" }
|
||||||
room
|
|
||||||
|> sendMessage "Hello, world!"
|
|
||||||
|> Task.attempt onResponse
|
|
||||||
|
|
||||||
**Hint:** are you trying to send multiple messages at the same time? You might want to use `sendMessages` instead.
|
**Hint:** are you trying to send multiple messages at the same time? You might want to use `sendMessages` instead.
|
||||||
|
|
||||||
|
@ -188,17 +185,27 @@ This way, you will lose messages!
|
||||||
|
|
||||||
If you're intending to send the same message multiple times, this function will emphasize that these messages are not the same.
|
If you're intending to send the same message multiple times, this function will emphasize that these messages are not the same.
|
||||||
|
|
||||||
|
data = { room = someRoom, onResponse = MessageSent, text = "Hello!" }
|
||||||
|
|
||||||
-- SAFE
|
-- SAFE
|
||||||
Task.sequence [ sendMessage "Hello, world!", sendMessage "hi mom!" ]
|
Cmd.batch [ sendMessage data, sendMessage { data | text = "hi mom!" } ]
|
||||||
|
|
||||||
-- NOT SAFE
|
-- NOT SAFE
|
||||||
Task.sequence [ sendMessage "Hello, world!", sendMessage "Hello world!" ]
|
Cmd.batch [ sendMessage data, sendMessage data ]
|
||||||
|
|
||||||
-- SAFE
|
-- SAFE
|
||||||
Task.sequence <| sendMessages [ "Hello, world!", "hi mom!" ]
|
sendMessages
|
||||||
|
{ room = someRoom
|
||||||
|
, textPieces = [ "Hello!", "hi mom!" ]
|
||||||
|
, onResponse = MessageSent
|
||||||
|
}
|
||||||
|
|
||||||
-- SAFE
|
-- SAFE
|
||||||
Task.sequence <| sendMessages [ "Hello, world!", "Hello, world!" ]
|
sendMessages
|
||||||
|
{ room = someRoom
|
||||||
|
, textPieces = [ "Hello!", "Hello!" ]
|
||||||
|
, onResponse = MessageSent
|
||||||
|
}
|
||||||
|
|
||||||
-}
|
-}
|
||||||
sendMessages : { room : Room, textPieces : List String, onResponse : VaultUpdate -> msg } -> Cmd msg
|
sendMessages : { room : Room, textPieces : List String, onResponse : VaultUpdate -> msg } -> Cmd msg
|
||||||
|
@ -210,18 +217,19 @@ sendMessages { room, textPieces, onResponse } =
|
||||||
|
|
||||||
Keep in mind that this function is not safe to use if you're sending exactly the same messages multiple times:
|
Keep in mind that this function is not safe to use if you're sending exactly the same messages multiple times:
|
||||||
|
|
||||||
|
data =
|
||||||
|
{ content = E.object []
|
||||||
|
, eventType = "com.example.foo"
|
||||||
|
, room = someRoom
|
||||||
|
, stateKey = Nothing
|
||||||
|
, onResponse = EventSent
|
||||||
|
}
|
||||||
|
|
||||||
-- SAFE
|
-- SAFE
|
||||||
Task.sequence
|
Cmd.batch [ sendOneEvent data , sendOneEvent { data | content = E.int 0 } ]
|
||||||
[ sendOneEvent { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
|
|
||||||
, sendOneEvent { content = E.int 0, eventType = "com.example.foo", stateKey = Nothing } room
|
|
||||||
]
|
|
||||||
|
|
||||||
-- NOT SAFE
|
-- NOT SAFE
|
||||||
Task.sequence
|
Cmd.batch [ sendOneEvent data , sendOneEvent data ]
|
||||||
[ sendOneEvent { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
|
|
||||||
, sendOneEvent { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
|
|
||||||
]
|
|
||||||
|
|
||||||
-}
|
-}
|
||||||
sendOneEvent : { content : D.Value, eventType : String, room : Room, stateKey : Maybe String, onResponse : VaultUpdate -> msg } -> Cmd msg
|
sendOneEvent : { content : D.Value, eventType : String, room : Room, stateKey : Maybe String, onResponse : VaultUpdate -> msg } -> Cmd msg
|
||||||
sendOneEvent =
|
sendOneEvent =
|
||||||
|
@ -236,17 +244,25 @@ This function ensures that every messages is treated separately.
|
||||||
Keep in mind that this function doesn't send the events in order, it just makes them safe to send at the same time.
|
Keep in mind that this function doesn't send the events in order, it just makes them safe to send at the same time.
|
||||||
|
|
||||||
-- NOT SAFE
|
-- NOT SAFE
|
||||||
[ sendOneEvent { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
|
data =
|
||||||
, sendOneEvent { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
|
{ content = E.object []
|
||||||
]
|
, eventType = "com.example.foo"
|
||||||
|> Task.sequence
|
, room = someRoom
|
||||||
|
, stateKey = Nothing
|
||||||
|
, onResponse = EventSent
|
||||||
|
}
|
||||||
|
|
||||||
|
Cmd.batch [ sendOneEvent data , sendOneEvent data ]
|
||||||
|
|
||||||
-- SAFE
|
-- SAFE
|
||||||
[ { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
|
data =
|
||||||
, { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
|
{ content = E.object []
|
||||||
]
|
, eventType = "com.example.foo"
|
||||||
|> sendMultipleEvents
|
, stateKey = Nothing
|
||||||
|> Task.sequence
|
, onResponse = EventSent
|
||||||
|
}
|
||||||
|
|
||||||
|
sendMultipleEvents [ data, data ] someRoom
|
||||||
|
|
||||||
-}
|
-}
|
||||||
sendMultipleEvents : List { content : D.Value, eventType : String, stateKey : Maybe String, onResponse : VaultUpdate -> msg } -> Room -> Cmd msg
|
sendMultipleEvents : List { content : D.Value, eventType : String, stateKey : Maybe String, onResponse : VaultUpdate -> msg } -> Room -> Cmd msg
|
||||||
|
|
Loading…
Reference in New Issue