summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/popup/src/Struct/Model.elm')
-rw-r--r--src/popup/src/Struct/Model.elm66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/popup/src/Struct/Model.elm b/src/popup/src/Struct/Model.elm
new file mode 100644
index 0000000..6742e96
--- /dev/null
+++ b/src/popup/src/Struct/Model.elm
@@ -0,0 +1,66 @@
+module Struct.Model exposing
+ (
+ Type,
+ new,
+ invalidate,
+ reset,
+ clear_error
+ )
+
+-- Elm -------------------------------------------------------------------------
+import Array
+
+-- Extension -------------------------------------------------------------------
+import Struct.Flags
+import Struct.Error
+import Struct.Player
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+type alias Type =
+ {
+ flags: Struct.Flags.Type,
+ error: (Maybe Struct.Error.Type),
+ players: (Array.Array Struct.Player.Type),
+ query_index: Int,
+ notify: Bool
+ }
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+new : Struct.Flags.Type -> Type
+new flags =
+ {
+ flags = flags,
+ error = Nothing,
+ players =
+ (Array.push
+ (Struct.Player.default)
+ (Array.fromList (Struct.Flags.get_players flags))
+ ),
+ query_index = -1,
+ notify = False
+ }
+
+reset : Type -> Type
+reset model =
+ {model |
+ error = Nothing,
+ notify = False,
+ query_index = -1
+ }
+
+invalidate : Struct.Error.Type -> Type -> Type
+invalidate err model =
+ {model |
+ error = (Just err)
+ }
+
+clear_error : Type -> Type
+clear_error model = {model | error = Nothing}