diff --git a/src/Internal/Values/StateManager.elm b/src/Internal/Values/StateManager.elm new file mode 100644 index 0000000..ac44e19 --- /dev/null +++ b/src/Internal/Values/StateManager.elm @@ -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 + +