Add documentation

pull/17/head
Bram 2024-03-29 11:28:04 +01:00
parent d41c31e8c1
commit ccefa2ed9b
2 changed files with 30 additions and 2 deletions

View File

@ -53,6 +53,8 @@ type Iddict a
, dict : Dict Int a , dict : Dict Int a
} }
{-| Define how an Iddict can be encoded and decoded to and from a JSON value.
-}
coder : Json.Coder a -> Json.Coder (Iddict a) coder : Json.Coder a -> Json.Coder (Iddict a)
coder x = coder x =
Json.object2 Json.object2

View File

@ -3,7 +3,7 @@ module Internal.Values.Timeline exposing
, empty, singleton , empty, singleton
, mostRecentEvents, mostRecentEventsFrom , mostRecentEvents, mostRecentEventsFrom
, insert, addSync , insert, addSync
, coder , coder, encode, decoder
) )
{-| {-|
@ -184,6 +184,8 @@ addSync batch timeline =
else else
connectITokenToIToken old start tl connectITokenToIToken old start tl
{-| Define how a Timeline can be encoded and decoded to and from a JSON value.
-}
coder : Json.Coder Timeline coder : Json.Coder Timeline
coder = coder =
Json.object5 Json.object5
@ -235,6 +237,8 @@ coder =
} }
) )
{-| Define how to encode and decode a IBatch to and from a JSON value.
-}
coderIBatch : Json.Coder IBatch coderIBatch : Json.Coder IBatch
coderIBatch = coderIBatch =
Json.object4 Json.object4
@ -271,6 +275,8 @@ coderIBatch =
} }
) )
{-| Define how to encode and decode a IBatchPTR to and from a JSON value.
-}
coderIBatchPTR : Json.Coder IBatchPTR coderIBatchPTR : Json.Coder IBatchPTR
coderIBatchPTR = coderIBatchPTR =
Json.map Json.map
@ -281,9 +287,13 @@ coderIBatchPTR =
} }
coderIBatchPTRValue coderIBatchPTRValue
{-| Define how to encode and decode a IBatchPTRValue to and from a JSON value.
-}
coderIBatchPTRValue : Json.Coder IBatchPTRValue coderIBatchPTRValue : Json.Coder IBatchPTRValue
coderIBatchPTRValue = Json.int coderIBatchPTRValue = Json.int
{-| Define how to encode and decode a IToken to and from a JSON value.
-}
coderIToken : Json.Coder IToken coderIToken : Json.Coder IToken
coderIToken = coderIToken =
Json.object5 Json.object5
@ -335,6 +345,8 @@ coderIToken =
} }
) )
{-| Define how to encode and decode a ITokenPTR to and from a JSON value.
-}
coderITokenPTR : Json.Coder ITokenPTR coderITokenPTR : Json.Coder ITokenPTR
coderITokenPTR = coderITokenPTR =
Json.maybe coderITokenPTRValue Json.maybe coderITokenPTRValue
@ -361,9 +373,13 @@ coderITokenPTR =
) )
} }
{-| Define how to encode and decode a ITokenPTRValue to and from a JSON value.
-}
coderITokenPTRValue : Json.Coder ITokenPTRValue coderITokenPTRValue : Json.Coder ITokenPTRValue
coderITokenPTRValue = Json.string coderITokenPTRValue = Json.string
{-| Define how to encode and decode a TokenValue to and from a JSON value.
-}
coderTokenValue : Json.Coder TokenValue coderTokenValue : Json.Coder TokenValue
coderTokenValue = Json.string coderTokenValue = Json.string
@ -438,6 +454,10 @@ connectITokenToIToken pointer1 pointer2 (Timeline tl) =
( _, _ ) -> ( _, _ ) ->
Timeline tl Timeline tl
{-| Timeline JSON decoder that helps decode a Timeline from JSON.
-}
decoder : Json.Decoder Timeline
decoder = Json.decode coder
{-| Create a new empty timeline. {-| Create a new empty timeline.
-} -}
@ -451,6 +471,10 @@ empty =
, tokens = Hashdict.empty .name , tokens = Hashdict.empty .name
} }
{-| Directly encode a Timeline into a JSON value.
-}
encode : Json.Encoder Timeline
encode = Json.encode coder
{-| Get an IBatch from the Timeline. {-| Get an IBatch from the Timeline.
-} -}
@ -584,7 +608,9 @@ mostRecentEvents : Filter -> Timeline -> List (List String)
mostRecentEvents filter (Timeline timeline) = mostRecentEvents filter (Timeline timeline) =
mostRecentFrom filter (Timeline timeline) timeline.mostRecentBatch mostRecentFrom filter (Timeline timeline) timeline.mostRecentBatch
{-| Instead of finding the most recent events from the latest sync, users can
also find the most recent events given a token value.
-}
mostRecentEventsFrom : Filter -> ITokenPTRValue -> Timeline -> List (List String) mostRecentEventsFrom : Filter -> ITokenPTRValue -> Timeline -> List (List String)
mostRecentEventsFrom filter tokenName timeline = mostRecentEventsFrom filter tokenName timeline =
mostRecentFrom filter timeline (ITokenPTR tokenName) mostRecentFrom filter timeline (ITokenPTR tokenName)