aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2017-09-13 21:48:04 +0200
committerNoah Loomans <noahloomans@gmail.com>2017-09-13 21:48:04 +0200
commit5348b220c8ec071eee01578f0ea525e28d3a5c3f (patch)
tree29725415cc884227081c44b832d3daff46c9068d
parent83034116b02497576d97bffc9e91a5476cc60d41 (diff)
Mode DecodeFlags and Model to seperate files
-rw-r--r--elm-package.json2
-rw-r--r--src/client/elm/DecodeFlags.elm54
-rw-r--r--src/client/elm/Main.elm73
-rw-r--r--src/client/elm/Model.elm19
-rw-r--r--src/client/static/elm.js68
5 files changed, 111 insertions, 105 deletions
diff --git a/elm-package.json b/elm-package.json
index f422b20..8063189 100644
--- a/elm-package.json
+++ b/elm-package.json
@@ -4,7 +4,7 @@
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
- "."
+ "src/client/elm"
],
"exposed-modules": [],
"dependencies": {
diff --git a/src/client/elm/DecodeFlags.elm b/src/client/elm/DecodeFlags.elm
new file mode 100644
index 0000000..5acc4f9
--- /dev/null
+++ b/src/client/elm/DecodeFlags.elm
@@ -0,0 +1,54 @@
+module DecodeFlags exposing (Flags, init)
+
+import Json.Decode exposing (Decoder, andThen, fail, string, succeed)
+import Json.Decode.Pipeline exposing (decode, required)
+import Model exposing (..)
+
+
+type alias Flags =
+ Json.Decode.Value
+
+
+init : Flags -> ( Model, Cmd msg )
+init flags =
+ case Json.Decode.decodeValue decodeUsers flags of
+ Ok user ->
+ ( Model user, Cmd.none )
+
+ Err err ->
+ Debug.crash err
+
+
+decodeUsers : Decoder (List User)
+decodeUsers =
+ Json.Decode.list decodeUser
+
+
+decodeUser : Decoder User
+decodeUser =
+ decode User
+ |> required "type" decodeUserType
+ |> required "value" string
+
+
+decodeUserType : Json.Decode.Decoder UserType
+decodeUserType =
+ string
+ |> andThen
+ (\s ->
+ case s of
+ "s" ->
+ succeed Student
+
+ "c" ->
+ succeed Class
+
+ "t" ->
+ succeed Teacher
+
+ "r" ->
+ succeed Room
+
+ _ ->
+ fail ("What the f*ck is " ++ s ++ "?")
+ )
diff --git a/src/client/elm/Main.elm b/src/client/elm/Main.elm
index de1f1fe..e59889d 100644
--- a/src/client/elm/Main.elm
+++ b/src/client/elm/Main.elm
@@ -1,9 +1,8 @@
module Main exposing (..)
import Html exposing (..)
-import Json.Decode exposing (Decoder, andThen, fail, string, succeed)
-import Json.Decode.Pipeline exposing (decode, required)
-
+import Model exposing (Model)
+import DecodeFlags exposing (Flags, init)
main : Program Flags Model msg
main =
@@ -14,74 +13,6 @@ main =
, subscriptions = subscriptions
}
-
-type alias Flags =
- Json.Decode.Value
-
-
-type alias Model =
- { users : List User
- }
-
-
-type alias User =
- { type_ : UserType
- , value : String
- }
-
-
-type UserType
- = Class
- | Teacher
- | Room
- | Student
-
-
-init : Flags -> ( Model, Cmd msg )
-init flags =
- case Json.Decode.decodeValue decodeUsers flags of
- Ok user ->
- ( Model user, Cmd.none )
-
- Err err ->
- Debug.crash err
-
-
-decodeUsers : Decoder (List User)
-decodeUsers =
- Json.Decode.list decodeUser
-
-
-decodeUser : Decoder User
-decodeUser =
- decode User
- |> required "type" decodeUserType
- |> required "value" string
-
-
-decodeUserType : Json.Decode.Decoder UserType
-decodeUserType =
- string
- |> andThen
- (\s ->
- case s of
- "s" ->
- succeed Student
-
- "c" ->
- succeed Class
-
- "t" ->
- succeed Teacher
-
- "r" ->
- succeed Room
-
- _ ->
- fail ("What the f*ck is " ++ s ++ "?")
- )
-
-
update : msg -> Model -> ( Model, Cmd msg )
update msg model =
( model, Cmd.none )
diff --git a/src/client/elm/Model.elm b/src/client/elm/Model.elm
new file mode 100644
index 0000000..8f4c6a6
--- /dev/null
+++ b/src/client/elm/Model.elm
@@ -0,0 +1,19 @@
+module Model exposing (..)
+
+
+type alias Model =
+ { users : List User
+ }
+
+
+type alias User =
+ { type_ : UserType
+ , value : String
+ }
+
+
+type UserType
+ = Class
+ | Teacher
+ | Room
+ | Student
diff --git a/src/client/static/elm.js b/src/client/static/elm.js
index cbab2b5..99bf4cb 100644
--- a/src/client/static/elm.js
+++ b/src/client/static/elm.js
@@ -7875,41 +7875,31 @@ var _elm_lang$html$Html$summary = _elm_lang$html$Html$node('summary');
var _elm_lang$html$Html$menuitem = _elm_lang$html$Html$node('menuitem');
var _elm_lang$html$Html$menu = _elm_lang$html$Html$node('menu');
-var _user$project$Main$subscriptions = function (model) {
- return _elm_lang$core$Platform_Sub$none;
-};
-var _user$project$Main$view = function (model) {
- return _elm_lang$html$Html$text(
- _elm_lang$core$Basics$toString(model));
-};
-var _user$project$Main$update = F2(
- function (msg, model) {
- return {ctor: '_Tuple2', _0: model, _1: _elm_lang$core$Platform_Cmd$none};
- });
-var _user$project$Main$Model = function (a) {
+var _user$project$Model$Model = function (a) {
return {users: a};
};
-var _user$project$Main$User = F2(
+var _user$project$Model$User = F2(
function (a, b) {
return {type_: a, value: b};
});
-var _user$project$Main$Student = {ctor: 'Student'};
-var _user$project$Main$Room = {ctor: 'Room'};
-var _user$project$Main$Teacher = {ctor: 'Teacher'};
-var _user$project$Main$Class = {ctor: 'Class'};
-var _user$project$Main$decodeUserType = A2(
+var _user$project$Model$Student = {ctor: 'Student'};
+var _user$project$Model$Room = {ctor: 'Room'};
+var _user$project$Model$Teacher = {ctor: 'Teacher'};
+var _user$project$Model$Class = {ctor: 'Class'};
+
+var _user$project$DecodeFlags$decodeUserType = A2(
_elm_lang$core$Json_Decode$andThen,
function (s) {
var _p0 = s;
switch (_p0) {
case 's':
- return _elm_lang$core$Json_Decode$succeed(_user$project$Main$Student);
+ return _elm_lang$core$Json_Decode$succeed(_user$project$Model$Student);
case 'c':
- return _elm_lang$core$Json_Decode$succeed(_user$project$Main$Class);
+ return _elm_lang$core$Json_Decode$succeed(_user$project$Model$Class);
case 't':
- return _elm_lang$core$Json_Decode$succeed(_user$project$Main$Teacher);
+ return _elm_lang$core$Json_Decode$succeed(_user$project$Model$Teacher);
case 'r':
- return _elm_lang$core$Json_Decode$succeed(_user$project$Main$Room);
+ return _elm_lang$core$Json_Decode$succeed(_user$project$Model$Room);
default:
return _elm_lang$core$Json_Decode$fail(
A2(
@@ -7919,36 +7909,48 @@ var _user$project$Main$decodeUserType = A2(
}
},
_elm_lang$core$Json_Decode$string);
-var _user$project$Main$decodeUser = A3(
+var _user$project$DecodeFlags$decodeUser = A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'value',
_elm_lang$core$Json_Decode$string,
A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'type',
- _user$project$Main$decodeUserType,
- _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$decode(_user$project$Main$User)));
-var _user$project$Main$decodeUsers = _elm_lang$core$Json_Decode$list(_user$project$Main$decodeUser);
-var _user$project$Main$init = function (flags) {
- var _p1 = A2(_elm_lang$core$Json_Decode$decodeValue, _user$project$Main$decodeUsers, flags);
+ _user$project$DecodeFlags$decodeUserType,
+ _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$decode(_user$project$Model$User)));
+var _user$project$DecodeFlags$decodeUsers = _elm_lang$core$Json_Decode$list(_user$project$DecodeFlags$decodeUser);
+var _user$project$DecodeFlags$init = function (flags) {
+ var _p1 = A2(_elm_lang$core$Json_Decode$decodeValue, _user$project$DecodeFlags$decodeUsers, flags);
if (_p1.ctor === 'Ok') {
return {
ctor: '_Tuple2',
- _0: _user$project$Main$Model(_p1._0),
+ _0: _user$project$Model$Model(_p1._0),
_1: _elm_lang$core$Platform_Cmd$none
};
} else {
return _elm_lang$core$Native_Utils.crashCase(
- 'Main',
+ 'DecodeFlags',
{
- start: {line: 44, column: 5},
- end: {line: 49, column: 28}
+ start: {line: 14, column: 5},
+ end: {line: 19, column: 28}
},
_p1)(_p1._0);
}
};
+
+var _user$project$Main$subscriptions = function (model) {
+ return _elm_lang$core$Platform_Sub$none;
+};
+var _user$project$Main$view = function (model) {
+ return _elm_lang$html$Html$text(
+ _elm_lang$core$Basics$toString(model));
+};
+var _user$project$Main$update = F2(
+ function (msg, model) {
+ return {ctor: '_Tuple2', _0: model, _1: _elm_lang$core$Platform_Cmd$none};
+ });
var _user$project$Main$main = _elm_lang$html$Html$programWithFlags(
- {init: _user$project$Main$init, update: _user$project$Main$update, view: _user$project$Main$view, subscriptions: _user$project$Main$subscriptions})(_elm_lang$core$Json_Decode$value);
+ {init: _user$project$DecodeFlags$init, update: _user$project$Main$update, view: _user$project$Main$view, subscriptions: _user$project$Main$subscriptions})(_elm_lang$core$Json_Decode$value);
var Elm = {};
Elm['Main'] = Elm['Main'] || {};