From 3bf84a2a57f3d8ceeabe7543688799aa5432a7b7 Mon Sep 17 00:00:00 2001 From: Bram van den Heuvel Date: Mon, 30 Jan 2023 11:31:47 +0100 Subject: [PATCH] Add `StateManager` type --- src/Internal/Values/StateManager.elm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/Internal/Values/StateManager.elm 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 + +