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 all 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
57 changes: 41 additions & 16 deletions client/Main.elm
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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 (..)


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 +42,7 @@ init =
state =
{ items = empty, addItemInput = "", error = Nothing }
in
( state, fetch )
( state, fetch )



Expand Down Expand Up @@ -81,10 +81,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 +103,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,8 +128,26 @@ fromServer msgConstructor result =
FromServer <| msgConstructor content

Err error ->
Error <| toString error
Error <| httpErrorToString error


httpErrorToString : Http.Error -> String
httpErrorToString error =
case error of
Http.BadUrl s ->
"bad url: " ++ s

Http.Timeout ->
"timeout"

Http.NetworkError ->
"network error"

Http.BadStatus response ->
"bad status: " ++ response.status.message

Http.BadPayload debugString response ->
"bad payload: " ++ debugString


-- VIEW
Expand All @@ -131,7 +156,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.

44 changes: 24 additions & 20 deletions example-servant-elm.cabal
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
-- This file has been generated from package.yaml by hpack version 0.17.1.
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.31.1.
--
-- see: https://github.com/sol/hpack
--
-- hash: 513a2cd1e4573d0f1227c7eb6dae73ca6154d9eda5362f5f6bcd1ab29ee7f921

name: example-servant-elm
version: 0.0.0
build-type: Simple
cabal-version: >= 1.10

executable server
main-is: Main.hs
hs-source-dirs:
server/src
build-depends:
base
, warp
, aeson
, wai-make-assets
, servant-elm
aeson
, base
, containers
, servant
, wai
, servant-elm >=0.6.0.2
, 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 +38,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 >=0.6.0.2
, 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 package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies:
- warp
- aeson
- wai-make-assets
- servant-elm
- servant-elm >= 0.6.0.2
- servant
- wai
- servant-server
Expand Down
12 changes: 5 additions & 7 deletions server/src/Api.hs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeOperators #-}

module Api where

import Data.Aeson
import Data.Proxy
import GHC.Generics
import Servant.API
import Servant.Elm (ElmType)
import qualified Elm.Derive
import Elm.Module

type Api =
"api" :>
Expand All @@ -30,8 +30,6 @@ data Item
id :: ItemId,
text :: String
}
deriving (Show, Eq, Generic)
deriving (Show, Eq)

instance ElmType Item
instance ToJSON Item
instance FromJSON Item
Elm.Derive.deriveBoth Elm.Derive.defaultOptions ''Item
13 changes: 7 additions & 6 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
resolver: lts-8.21
resolver: lts-13.24

packages:
- location: ./.
- location:
git: https://www.github.com/soenkehahn/wai-make-assets
commit: c72a924
extra-dep: true
- '.'

extra-deps:
- servant-elm-0.6.0.2
- elm-bridge-0.5.1
- wai-make-assets-0.2