Skip to content

Commit

Permalink
Merge pull request #13 from danstn/upgrade-to-0.18
Browse files Browse the repository at this point in the history
Upgrade to 0.18
  • Loading branch information
Søren Debois authored Dec 14, 2016
2 parents 6cc2e3c + acb0439 commit 0336a41
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 278 deletions.
4 changes: 2 additions & 2 deletions elm-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Parts"
],
"dependencies": {
"elm-lang/core": "4.0.0 <= v < 5.0.0"
"elm-lang/core": "5.0.0 <= v < 6.0.0"
},
"elm-version": "0.17.0 <= v < 0.18.0"
"elm-version": "0.18.0 <= v < 0.19.0"
}
18 changes: 11 additions & 7 deletions examples/0-counter-part.elm
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Main exposing (..)

import Html exposing (Html, button, div, text)
import Html.App as App
import Html.Events exposing (onClick)
import Dict

import Dict
import Counter
import Parts

Expand All @@ -17,6 +18,7 @@ main =
}



-- MODEL


Expand All @@ -25,13 +27,14 @@ type alias Model =
}


init : (Model, Cmd Msg)
init : ( Model, Cmd Msg )
init =
( { counter = Dict.empty }
, Cmd.none
)



-- UPDATE


Expand All @@ -40,14 +43,15 @@ type Msg
| CounterMsg (Parts.Msg Model Msg)


update : Msg -> Model -> (Model, Cmd Msg)
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Reset ->
init

CounterMsg msg' ->
Parts.update msg' model
CounterMsg msg_ ->
Parts.update msg_ model



-- VIEW
Expand All @@ -57,6 +61,6 @@ view : Model -> Html Msg
view model =
div
[]
[ Counter.render CounterMsg [0] model
[ Counter.render CounterMsg [ 0 ] model
, button [ onClick Reset ] [ text "RESET" ]
]
21 changes: 12 additions & 9 deletions examples/0-counter.elm
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module Main exposing (..)

import Counter
import Html exposing (Html, button, div, text)
Expand All @@ -8,7 +9,7 @@ import Html.Events exposing (onClick)
main : Program Never
main =
App.program
{ init = init 0
{ init = init 0
, update = update
, view = view
, subscriptions = always Sub.none
Expand All @@ -24,10 +25,10 @@ type alias Model =
}


init : Int -> (Model, Cmd Msg)
init : Int -> ( Model, Cmd Msg )
init x =
( { counter = Counter.init x }
, Cmd.none
, Cmd.none
)


Expand All @@ -40,21 +41,23 @@ type Msg
| CounterMsg Counter.Msg


update : Msg -> Model -> (Model, Cmd Msg)
update : Msg -> Model -> ( Model, Cmd Msg )
update message model =
case message of
Reset ->
init 0
init 0

CounterMsg msg ->
let
(counter', cmd) =
Counter.update msg model.counter
let
( counter_, cmd ) =
Counter.update msg model.counter
in
( { model | counter = counter' }
( { model | counter = counter_ }
, Cmd.map CounterMsg cmd
)



-- VIEW


Expand Down
20 changes: 12 additions & 8 deletions examples/1-counter-pair-part.elm
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module Main exposing (..)

import Html exposing (Html, button, div, text)
import Html.App as App
import Html.Events exposing (onClick)
import Dict

import Dict
import Counter
import Parts

Expand All @@ -17,6 +18,7 @@ main =
}



-- MODEL


Expand All @@ -25,13 +27,14 @@ type alias Model =
}


init : (Model, Cmd Msg)
init : ( Model, Cmd Msg )
init =
( { counter = Dict.empty }
, Cmd.none
)



-- UPDATE


Expand All @@ -40,14 +43,15 @@ type Msg
| CounterMsg (Parts.Msg Model Msg)


update : Msg -> Model -> (Model, Cmd Msg)
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Reset ->
init

CounterMsg msg' ->
Parts.update msg' model
CounterMsg msg_ ->
Parts.update msg_ model



-- VIEW
Expand All @@ -57,7 +61,7 @@ view : Model -> Html Msg
view model =
div
[]
[ Counter.render CounterMsg [0] model
, Counter.render CounterMsg [1] model
[ Counter.render CounterMsg [ 0 ] model
, Counter.render CounterMsg [ 1 ] model
, button [ onClick Reset ] [ text "RESET" ]
]
26 changes: 14 additions & 12 deletions examples/1-counter-pair.elm
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module Main exposing (..)

import Counter
import Html exposing (Html, button, div, text)
Expand All @@ -8,7 +9,7 @@ import Html.Events exposing (onClick)
main : Program Never
main =
App.program
{ init = init 0 0
{ init = init 0 0
, update = update
, view = view
, subscriptions = always Sub.none
Expand All @@ -25,12 +26,12 @@ type alias Model =
}


init : Int -> Int -> (Model, Cmd Msg)
init : Int -> Int -> ( Model, Cmd Msg )
init top bottom =
( { topCounter = Counter.init top
, bottomCounter = Counter.init bottom
}
, Cmd.none
, Cmd.none
)


Expand All @@ -44,31 +45,32 @@ type Msg
| Bottom Counter.Msg


update : Msg -> Model -> (Model, Cmd Msg)
update : Msg -> Model -> ( Model, Cmd Msg )
update message model =
case message of
Reset ->
init 0 0

Top msg ->
let
(counter', cmd) =
Counter.update msg model.topCounter
let
( counter_, cmd ) =
Counter.update msg model.topCounter
in
( { model | topCounter = counter' }
( { model | topCounter = counter_ }
, Cmd.map Top cmd
)

Bottom msg ->
let
(counter', cmd) =
Counter.update msg model.bottomCounter
let
( counter_, cmd ) =
Counter.update msg model.bottomCounter
in
( { model | bottomCounter = counter' }
( { model | bottomCounter = counter_ }
, Cmd.map Bottom cmd
)



-- VIEW


Expand Down
34 changes: 19 additions & 15 deletions examples/2-counter-list-part.elm
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
module Main exposing (..)

import Html exposing (Html, button, div, text)
import Html.App as App
import Html.Events exposing (onClick)
import Dict

import Dict
import Counter
import Parts


main : Program Never
main =
App.program
{ init = (init, Cmd.none)
{ init = ( init, Cmd.none )
, subscriptions = always Sub.none
, update = update
, view = view
}



-- MODEL


Expand All @@ -35,6 +37,7 @@ init =
}



-- UPDATE


Expand All @@ -45,42 +48,43 @@ type Msg


reset : Int -> Model -> Model
reset k model =
.reset (Counter.find [k]) model
reset k model =
.reset (Counter.find [ k ]) model


update : Msg -> Model -> (Model, Cmd Msg)
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Insert ->
Insert ->
( { model | last = model.last + 1 } |> reset (model.last + 1)
, Cmd.none
)

Remove ->
Remove ->
( { model | first = model.first + 1 } |> reset model.first
, Cmd.none
)

CounterMsg msg' ->
Parts.update msg' model
CounterMsg msg_ ->
Parts.update msg_ model



-- VIEW


view : Model -> Html Msg
view model =
let
let
remove =
button [ onClick Remove ] [ text "Remove" ]

insert =
button [ onClick Insert ] [ text "Add" ]

counters =
[model.first .. model.last]
|> List.map
(\idx -> Counter.render CounterMsg [idx] model)
List.range model.first model.last
|> List.map
(\idx -> Counter.render CounterMsg [ idx ] model)
in
div [] ([remove, insert] ++ counters)
div [] ([ remove, insert ] ++ counters)
Loading

0 comments on commit 0336a41

Please sign in to comment.