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

DjangoChannels

Utilities

streamDemultiplexer : String -> (String -> streamType) -> streamType -> streamType

Deal with streams from a WebsocketDemultiplexer.

module DjangoChannels
    exposing
        ( streamDemultiplexer
        )

{-|

# Utilities
@docs streamDemultiplexer

-}

-- Core modules

import Json.Decode exposing (Decoder, string, field, list)


{-| Deal with streams from a WebsocketDemultiplexer.
-}
streamDemultiplexer : String -> (String -> streamType) -> streamType -> streamType
streamDemultiplexer data stringToStream notFoundStream =
    case Json.Decode.decodeString (field "stream" string) data of
        Ok stream ->
            stringToStream stream

        Err _ ->
            notFoundStream