Skip to content

Instantly share code, notes, and snippets.

@frpaulas
Created November 2, 2015 15:03
Show Gist options
  • Save frpaulas/2fcdf2bc5ef0922303ac to your computer and use it in GitHub Desktop.
Save frpaulas/2fcdf2bc5ef0922303ac to your computer and use it in GitHub Desktop.
module NoteSaver where
import Html exposing (..)
import Html.Attributes exposing (class)
import StartApp
import Effects
app =
StartApp.start
{ init = (initialModel)
, update = update
, view = view
, inputs = [incomingActions]
}
main: Signal Html
main =
app.html
-- MODEL
type alias Note =
{ id: Int
, donor_id: Int
, memo: String
}
type alias Model =
List Note
initialModel: Model
initialModel =
[ {id = 1, donor_id = 1001, memo = "Some note 1"}
, {id = 2, donor_id = 1001, memo = "Some note 2"}
]
-- PORT
port noteList : Signal Model
incomingActions: Signal Action
incomingActions =
Signal.map SetNotes noteList
-- UPDATE
type Action
= NoOp
| SetNotes Model
update action model =
case action of
NoOp ->
model
SetNotes notes ->
(notes, Effects.none)
-- VIEW
view: Model -> Html
view model =
ul [class "notes"] (List.map noteItem model)
noteItem: Note -> Html
noteItem note =
li [class "note_memo"] [ text (toString note.memo) ]
@frpaulas
Copy link
Author

frpaulas commented Nov 2, 2015

ln 10 should be { init = (initialModel, Effects.none) and throws
-- TYPE MISMATCH ------------------------------------------------- NoteSaver.elm

The 1st argument to function start has an unexpected type.

9| StartApp.start
10|> { init = (initialModel, Effects.none)
11|> , update = update
12|> , view = view
13|> , inputs = [incomingActions]
14|> }

As I infer the type of values flowing through your program, I see a conflict
between these two types:

List

(Model)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment