This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.

Phoenix.Channel.Helpers

Helpers

Convert your response type from a string to a message

assignResponseType : String -> Msg

Converts a string into a Msg

module Phoenix.Channel.Helpers exposing (assignResponseType) -- where
{-| Helpers

Convert your response type from a string to a message
@docs assignResponseType

-}
import Json.Decode exposing (decodeString)
import Phoenix.Channel.Model exposing (decodeSocketMessage, SocketMessage)
import Phoenix.Channel.Update exposing (Msg(..))


turnDecodedResponseIntoServerResponse : Result String SocketMessage -> Msg
turnDecodedResponseIntoServerResponse response =
  case response of
    Ok socketResponse ->
      case socketResponse.payload.status of
        "ok" ->
          SuccessfulResponse socketResponse
        _ ->
          ErrorResponse (socketResponse.payload.status)
    Err message ->
      ErrorResponse message

{-| Converts a string into a Msg
-}
assignResponseType : String -> Msg
assignResponseType =
    decodeString decodeSocketMessage
      >> turnDecodedResponseIntoServerResponse