Include Context in Envelope
parent
7254fcfaa4
commit
87a5919921
|
@ -2,6 +2,7 @@ module Internal.Values.Envelope exposing
|
||||||
( Envelope, init
|
( Envelope, init
|
||||||
, map, mapMaybe
|
, map, mapMaybe
|
||||||
, Settings, mapSettings, extractSettings
|
, Settings, mapSettings, extractSettings
|
||||||
|
, mapContext
|
||||||
, getContent, extract
|
, getContent, extract
|
||||||
, encode, decoder
|
, encode, decoder
|
||||||
)
|
)
|
||||||
|
@ -25,6 +26,11 @@ settings that can be adjusted manually.
|
||||||
@docs Settings, mapSettings, extractSettings
|
@docs Settings, mapSettings, extractSettings
|
||||||
|
|
||||||
|
|
||||||
|
## Context
|
||||||
|
|
||||||
|
@docs mapContext
|
||||||
|
|
||||||
|
|
||||||
## Extract
|
## Extract
|
||||||
|
|
||||||
@docs getContent, extract
|
@docs getContent, extract
|
||||||
|
@ -39,6 +45,7 @@ settings that can be adjusted manually.
|
||||||
import Internal.Config.Default as Default
|
import Internal.Config.Default as Default
|
||||||
import Internal.Tools.Decode as D
|
import Internal.Tools.Decode as D
|
||||||
import Internal.Tools.Encode as E
|
import Internal.Tools.Encode as E
|
||||||
|
import Internal.Values.Context as Context exposing (Context)
|
||||||
import Json.Decode as D
|
import Json.Decode as D
|
||||||
import Json.Encode as E
|
import Json.Encode as E
|
||||||
|
|
||||||
|
@ -51,6 +58,7 @@ define them in their type.
|
||||||
type Envelope a
|
type Envelope a
|
||||||
= Envelope
|
= Envelope
|
||||||
{ content : a
|
{ content : a
|
||||||
|
, context : Context
|
||||||
, settings : Settings
|
, settings : Settings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,8 +82,9 @@ potential tokens, values and settings included in the JSON.
|
||||||
-}
|
-}
|
||||||
decoder : D.Decoder a -> D.Decoder (Envelope a)
|
decoder : D.Decoder a -> D.Decoder (Envelope a)
|
||||||
decoder xDecoder =
|
decoder xDecoder =
|
||||||
D.map2 (\a b -> Envelope { content = a, settings = b })
|
D.map3 (\a b c -> Envelope { content = a, context = b, settings = c })
|
||||||
(D.field "content" xDecoder)
|
(D.field "content" xDecoder)
|
||||||
|
(D.field "context" Context.decoder)
|
||||||
(D.field "settings" decoderSettings)
|
(D.field "settings" decoderSettings)
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,6 +105,7 @@ encode : (a -> E.Value) -> Envelope a -> E.Value
|
||||||
encode encodeX (Envelope data) =
|
encode encodeX (Envelope data) =
|
||||||
E.object
|
E.object
|
||||||
[ ( "content", encodeX data.content )
|
[ ( "content", encodeX data.content )
|
||||||
|
, ( "context", Context.encode data.context )
|
||||||
, ( "settings", encodeSettings data.settings )
|
, ( "settings", encodeSettings data.settings )
|
||||||
, ( "version", E.string Default.currentVersion )
|
, ( "version", E.string Default.currentVersion )
|
||||||
]
|
]
|
||||||
|
@ -178,6 +188,7 @@ init : a -> Envelope a
|
||||||
init x =
|
init x =
|
||||||
Envelope
|
Envelope
|
||||||
{ content = x
|
{ content = x
|
||||||
|
, context = Context.init
|
||||||
, settings =
|
, settings =
|
||||||
{ currentVersion = Default.currentVersion
|
{ currentVersion = Default.currentVersion
|
||||||
, deviceName = Default.deviceName
|
, deviceName = Default.deviceName
|
||||||
|
@ -200,6 +211,18 @@ map : (a -> b) -> Envelope a -> Envelope b
|
||||||
map f (Envelope data) =
|
map f (Envelope data) =
|
||||||
Envelope
|
Envelope
|
||||||
{ content = f data.content
|
{ content = f data.content
|
||||||
|
, context = data.context
|
||||||
|
, settings = data.settings
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{-| Update the Context in the Envelope.
|
||||||
|
-}
|
||||||
|
mapContext : (Context -> Context) -> Envelope a -> Envelope a
|
||||||
|
mapContext f (Envelope data) =
|
||||||
|
Envelope
|
||||||
|
{ content = data.content
|
||||||
|
, context = f data.context
|
||||||
, settings = data.settings
|
, settings = data.settings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,6 +242,7 @@ mapSettings : (Settings -> Settings) -> Envelope a -> Envelope a
|
||||||
mapSettings f (Envelope data) =
|
mapSettings f (Envelope data) =
|
||||||
Envelope
|
Envelope
|
||||||
{ content = data.content
|
{ content = data.content
|
||||||
|
, context = data.context
|
||||||
, settings = f data.settings
|
, settings = f data.settings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue