Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Elm 0.19. #7

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ setup: client-setup server-setup
build: client-build server-build

client-setup:
(cd client ; elm package install -y)

client-build:
(cd client ; make)
Expand Down
40 changes: 24 additions & 16 deletions client/Main.elm
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
module Main exposing (..)
module Main exposing (FromServer(..), FromUi(..), ItemId, Model, Msg(..), fromServer, init, main, update, view, viewItem)

import Browser
import Api exposing (..)
import Dict exposing (..)
import Html exposing (..)
import Html exposing (program)
import Html.Events exposing (..)
import Http
import Api exposing (..)
import Debug
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you get rid of Debug since it is not allowed to be used in production code or published packages? In 0.19 there are only functions for numbers and toString has to be implemented by the user.

https://package.elm-lang.org/packages/elm/core/latest/Debug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix this up later tonight. I was just getting something minimally working, and know Debug got deprecated (and a good thing too!).



main : Program Never Model Msg
main : Program () Model Msg
main =
program
{ init = init
Browser.element
{ init = \() -> init
, update = update
, subscriptions = \_ -> Sub.none
, view = view
Expand Down Expand Up @@ -42,7 +43,7 @@ init =
state =
{ items = empty, addItemInput = "", error = Nothing }
in
( state, fetch )
( state, fetch )



Expand Down Expand Up @@ -81,10 +82,14 @@ update message s =
)

NewItem item ->
{ s | items = insert item.id item s.items } ! []
( { s | items = insert item.id item s.items }
, Cmd.none
)

Delete id ->
{ s | items = remove id s.items } ! []
( { s | items = remove id s.items }
, Cmd.none
)

FromUi fromUi ->
case fromUi of
Expand All @@ -99,13 +104,16 @@ update message s =
newState =
{ s | addItemInput = "" }
in
if new == "" then
update (Error "empty field") s
else
( newState, cmd )
if new == "" then
update (Error "empty field") s

else
( newState, cmd )

AddItemInputChange t ->
{ s | addItemInput = t } ! []
( { s | addItemInput = t }
, Cmd.none
)

Done id ->
( s, Http.send (fromServer (\NoContent -> Delete id)) (deleteApiItemByItemId id) )
Expand All @@ -121,7 +129,7 @@ fromServer msgConstructor result =
FromServer <| msgConstructor content

Err error ->
Error <| toString error
Error <| Debug.toString error



Expand All @@ -131,7 +139,7 @@ fromServer msgConstructor result =
view : Model -> Html Msg
view state =
div [] <|
[ text (toString state)
[ text (Debug.toString state)
, br [] []
]
++ List.map (viewItem << Tuple.second) (toList state.items)
Expand Down
2 changes: 1 addition & 1 deletion client/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
../assets/index.html: Api.elm Main.elm
elm make --yes Main.elm
elm make Main.elm
mv index.html ../assets/

Api.elm: GenerateElm.hs ../server/src/Api.hs
Expand Down
16 changes: 0 additions & 16 deletions client/elm-package.json

This file was deleted.

30 changes: 30 additions & 0 deletions client/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"type": "application",
"source-directories": [
"."
],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"NoRedInk/elm-json-decode-pipeline": "1.0.0",
"elm/browser": "1.0.0",
"elm/core": "1.0.0",
"elm/html": "1.0.0",
"elm/http": "1.0.0",
"elm/url": "1.0.0",
"elm/json": "1.0.0"
},
"indirect": {
"elm/time": "1.0.0",
"elm/virtual-dom": "1.0.0"
}
},
"test-dependencies": {
"direct": {
"elm-explorations/test": "1.1.0"
},
"indirect": {
"elm/random": "1.0.0"
}
}
}
8 changes: 4 additions & 4 deletions client/tests/Tests.elm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Tests exposing (..)
module Tests exposing (addItemButton, tests)

import Test exposing (..)
import Main exposing (..)
import Expect
import Main exposing (..)
import Test exposing (..)


tests : Test
Expand All @@ -27,4 +27,4 @@ addItemButton =
result =
new.addItemInput
in
Expect.equal "" result
Expect.equal "" result
21 changes: 0 additions & 21 deletions client/tests/elm-package.json

This file was deleted.

41 changes: 22 additions & 19 deletions example-servant-elm.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
-- This file has been generated from package.yaml by hpack version 0.17.1.
-- This file has been generated from package.yaml by hpack version 0.28.2.
--
-- see: https://github.com/sol/hpack
--
-- hash: 1ad3309cc41055c81ccb4f2ce09f92329551ad94ce0888d36cde5cd31d502ea5

name: example-servant-elm
version: 0.0.0
Expand All @@ -12,19 +14,20 @@ executable server
hs-source-dirs:
server/src
build-depends:
base
, warp
, aeson
, wai-make-assets
, servant-elm
aeson
, base
, containers
, servant
, wai
, servant-elm
, servant-server
, transformers
, containers
, wai
, wai-make-assets
, warp
other-modules:
Api
App
Paths_example_servant_elm
default-language: Haskell2010

test-suite spec
Expand All @@ -34,24 +37,24 @@ test-suite spec
server/test
server/src
build-depends:
base
, warp
, aeson
, wai-make-assets
, servant-elm
, servant
, wai
, servant-server
, transformers
aeson
, base
, containers
, warp >= 3.2.3
, hspec
, servant-client
, http-client
, http-types
, servant
, servant-client
, servant-elm
, servant-server
, transformers
, wai
, wai-make-assets
, warp >=3.2.3
other-modules:
AppSpec
Api
App
Main
Paths_example_servant_elm
default-language: Haskell2010
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resolver: lts-8.21
resolver: lts-12.12

packages:
- location: ./.
Expand Down