Skip to content

Instantly share code, notes, and snippets.

@saschatimme
Created April 6, 2017 14:08
Show Gist options
  • Save saschatimme/4550253a712ca352edba1154043c24f9 to your computer and use it in GitHub Desktop.
Save saschatimme/4550253a712ca352edba1154043c24f9 to your computer and use it in GitHub Desktop.
module Phoenix.Presence exposing (Presence, create, onChange, onJoins, onLeaves)
import Dict exposing (Dict)
import Json.Decode as JD exposing (Decoder, Value)
type alias Presence msg =
PhoenixPresence msg
type alias PhoenixPresence val msg =
{ onChange : Maybe (Dict String (List Value) -> msg)
, onJoins : Maybe (Dict String (List Value) -> msg)
, onLeaves : Maybe (Dict String (List Value) -> msg)
}
create : PhoenixPresence val msg
create =
{ onChange = Nothing
, onJoins = Nothing
, onLeaves = Nothing
}
onChange : (Dict String (List Value) -> msg) -> PhoenixPresence msg -> PhoenixPresence msg
onChange func presence =
{ presence | onChange = Just func }
onJoins : (Dict String (List Value) -> msg) -> PhoenixPresence msg -> PhoenixPresence msg
onJoins func presence =
{ presence | onJoins = Just func }
onLeaves : (Dict String (List Value) -> msg) -> PhoenixPresence msg -> PhoenixPresence msg
onLeaves func presence =
{ presence | onLeaves = Just func }
{- And in Channel -}
withPresence : Presence msg -> Channel msg -> Channel msg
withPresence presence chan =
{ chan | presence = Just presence }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment