Skip to content

Commit

Permalink
Rename MyEvent to GameEvent
Browse files Browse the repository at this point in the history
What a bad name I found. This commit closes #2.

Also, the GameLogic module wasn't used in the event handler, so
it got removed from the import list.
  • Loading branch information
franckverrot committed Feb 26, 2017
1 parent 74d6f2e commit 3ca591d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 39 deletions.
36 changes: 18 additions & 18 deletions build/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8979,27 +8979,15 @@ var _user$project$Model$Model = F3(
return {boxes: a, currentPlayer: b, winner: c};
});

var _user$project$MyEvent$Reset = {ctor: 'Reset'};
var _user$project$MyEvent$CheckWinner = F3(
var _user$project$GameEvent$Reset = {ctor: 'Reset'};
var _user$project$GameEvent$CheckWinner = F3(
function (a, b, c) {
return {ctor: 'CheckWinner', _0: a, _1: b, _2: c};
});
var _user$project$MyEvent$Clicked = function (a) {
var _user$project$GameEvent$Clicked = function (a) {
return {ctor: 'Clicked', _0: a};
};

var _user$project$GameLogic$noneUnclaimed = function (ary) {
return _elm_lang$core$Native_Utils.eq(
0,
_elm_lang$core$Array$length(
A2(
_elm_lang$core$Array$filter,
function (x) {
return _elm_lang$core$Native_Utils.eq(x, _user$project$Player$Unclaimed);
},
ary)));
};

var _user$project$EventHandlers_OnClicked$onClicked = F2(
function (model, index) {
var leaveBoardIntact = function (player) {
Expand All @@ -9026,7 +9014,7 @@ var _user$project$EventHandlers_OnClicked$onClicked = F2(
{
ctor: '_Tuple2',
_0: A2(_p1._0, model.currentPlayer, model.boxes),
_1: A2(_user$project$MyEvent$CheckWinner, model.currentPlayer, _p1._1)
_1: A2(_user$project$GameEvent$CheckWinner, model.currentPlayer, _p1._1)
});
}(
function (box) {
Expand All @@ -9043,6 +9031,18 @@ var _user$project$EventHandlers_OnClicked$onClicked = F2(
A2(_elm_lang$core$Array$get, index, model.boxes))));
});

var _user$project$GameLogic$noneUnclaimed = function (ary) {
return _elm_lang$core$Native_Utils.eq(
0,
_elm_lang$core$Array$length(
A2(
_elm_lang$core$Array$filter,
function (x) {
return _elm_lang$core$Native_Utils.eq(x, _user$project$Player$Unclaimed);
},
ary)));
};

var _user$project$Update$winningCombos = {
ctor: '::',
_0: {
Expand Down Expand Up @@ -9334,7 +9334,7 @@ var _user$project$View$view = function (model) {
_elm_lang$html$Html$button,
{
ctor: '::',
_0: _elm_lang$html$Html_Events$onClick(_user$project$MyEvent$Reset),
_0: _elm_lang$html$Html_Events$onClick(_user$project$GameEvent$Reset),
_1: {
ctor: '::',
_0: _user$project$View$class(
Expand Down Expand Up @@ -9392,7 +9392,7 @@ var _user$project$View$view = function (model) {
{
ctor: '::',
_0: _elm_lang$html$Html_Events$onClick(
_user$project$MyEvent$Clicked(index)),
_user$project$GameEvent$Clicked(index)),
_1: {
ctor: '::',
_0: _user$project$View$class(
Expand Down
5 changes: 2 additions & 3 deletions src/EventHandlers/OnClicked.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ module EventHandlers.OnClicked exposing ( onClicked )
import Array exposing (..)
import Maybe exposing (..)
import Model exposing (..)
import MyEvent exposing (..)
import GameEvent exposing (..)
import Player exposing (..)
import Task exposing (..)
import Time exposing (..)
import GameLogic exposing (noneUnclaimed)

{-| onClicked -}
onClicked : Model -> Int -> (Model, Cmd MyEvent)
onClicked : Model -> Int -> (Model, Cmd GameEvent)
onClicked model index =
let
markBoxForPlayer player = set index player
Expand Down
6 changes: 3 additions & 3 deletions src/MyEvent.elm → src/GameEvent.elm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module MyEvent exposing ( MyEvent(Clicked, CheckWinner, Reset)
)
module GameEvent exposing ( GameEvent(Clicked, CheckWinner, Reset)
)
import Player exposing (..)
import Time exposing (..)

type MyEvent = Clicked Int
type GameEvent = Clicked Int
| CheckWinner Player Bool Time
| Reset
12 changes: 6 additions & 6 deletions src/Main.elm
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Html exposing (program)
import Model exposing (Model, initialModel)
import MyEvent exposing (MyEvent)
import Update exposing (update)
import View exposing (view)
import Html exposing (program)
import Model exposing (Model, initialModel)
import GameEvent exposing (GameEvent)
import Update exposing (update)
import View exposing (view)

main : Program Never Model MyEvent
main : Program Never Model GameEvent
main = program { init = (initialModel, Cmd.none)
, view = view
, update = update
Expand Down
2 changes: 1 addition & 1 deletion src/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Model exposing ( Model
import Array exposing (..)
import Player exposing (..)

type alias Model = { boxes : Array Player
type alias Model = { boxes : Array Player
, currentPlayer : Player
, winner : Maybe Player
}
Expand Down
4 changes: 2 additions & 2 deletions src/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Array exposing (..)
import EventHandlers.OnClicked
import GameLogic exposing (noneUnclaimed)
import Model exposing (..)
import MyEvent exposing (..)
import GameEvent exposing (..)
import Player exposing (..)

changePlayer : Player -> Player
Expand Down Expand Up @@ -48,7 +48,7 @@ playerWon player model =
True -> Ok player
False -> Err "Not there yet!"

update : MyEvent -> Model -> (Model, Cmd MyEvent)
update : GameEvent -> Model -> (Model, Cmd GameEvent)
update msg model =
case msg of
Reset -> initialModel ! []
Expand Down
4 changes: 2 additions & 2 deletions src/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Model exposing (..)
import MyEvent exposing (..)
import GameEvent exposing (..)
import Player exposing (..)

{ id, class, classList } =
indexNamespace

view : Model -> Html MyEvent
view : Model -> Html GameEvent
view model =
let
box index = get index model.boxes
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/UpdateTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import Test exposing (..)
import Expect
import Array
import Model exposing (initialModel)
import MyEvent exposing (MyEvent(Clicked, CheckWinner, Reset))
import Player exposing (Player (A, B, Unclaimed))
import Update exposing (changePlayer, currentPlayerWinning, update)
import Time exposing (second)
import GameEvent exposing (GameEvent(Clicked, CheckWinner, Reset))
import Player exposing (Player (A, B, Unclaimed))
import Update exposing (changePlayer, currentPlayerWinning, update)
import Time exposing (second)

updateTests : List Test
updateTests = [ describe "Update.update"
Expand Down

0 comments on commit 3ca591d

Please sign in to comment.