Subscribe now

Elm Weekly Drip #11 and Exercise: Support PresenceDiff Types [06.10.2016]

NOTE: This week is our first combined linkdump and exercise since moving to 5-a-week. We'll start with the links, followed by the exercise.

Some articles on Elm Types; convincing your co-workers to give it a shot; explanations for the present Native situation; a paper that has consumed my life; a React-based immutability-focused rich text editor to integrate with ports; a mental model for Elm 0.17's program loop.

Exercise: Support PresenceDiff Types

In yesterday's exercise, we began adding support for Phoenix.Presence to elm-phoenix-socket. For today's exercise, build a PresenceDiff type and a decoder for it, and Debug.log it in the appropriate branch in the update case statement. Here's the JSON and my first stab at the PresenceDiff type:

  "leaves": {},
  "joins": {
    "travis": {
      "metas": [
          "phx_ref": "g20AAAAIBIaaARgeac4=",
          "online_at": "{1465, 503519, 989318}",
          "device": "browser"

So it looks like leaves and joins both contain values of type PresenceState, so let's define a new type for PresenceDiff:

type alias PresenceDiff =
    { leaves : PresenceState
    , joins : PresenceState

All that's left is to build a Json.Decode.Decoder for the presence_diff message, and use it in that update branch.