Add `StateManager` type

pull/1/head
Bram van den Heuvel 2023-01-30 11:31:47 +01:00
parent a5af1c40a0
commit 3bf84a2a57
1 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,28 @@
module Internal.Values.StateManager exposing (..)
import Dict exposing (Dict)
import Internal.Values.Event as Event exposing (Event)
type alias StateManager = Dict (String, String) Event
getStateEvent : String -> String -> StateManager -> Maybe Event
getStateEvent eventType stateKey =
Dict.get ( eventType, stateKey )
updateRoomStateWith : StateManager -> StateManager -> StateManager
updateRoomStateWith = Dict.union
fromEventList : List Event -> StateManager
fromEventList =
List.filterMap
(\event ->
event
|> Event.stateKey
|> Maybe.map
(\key ->
( ( Event.contentType event, key ), event )
)
)
>> Dict.fromList