- In terminal, run
elm package install elm-lang/mouse
- Also run
elm package install elm-lang/keyboard
- Rename the module MouseFollow
- Import Mouse and Keyboard
- In the definition of
main
, changeApp.beginnerProgram
toApp.program
- In the argument of
App.program
, changemodel = model
toinit = init
- Add
subscriptions = subscriptions
to the argument ofApp.program
- Below the model, add a new type declaration for
init
- We want
init
to be a tuple containing aModel
and aCmd Msg
- We want
- Define
init
to be a tuple containingmodel
andCmd.none
- Below
update
, add a new type declaration forsubscriptions
- We want
subscriptions
to accept aModel
and return aSub Msg
- We want
- Define
subscriptions
to take an argumentmodel
and returnSub.none
- Remove
DisplayToggle
from the type declaration ofMsg
- Also remove the
DisplayToggle
case from the definition ofupdate
- Change the type declaration of
update
to return a tuple containing aModel
and aCmd Msg
- In the
NoOp
case ofupdate
, return a tuple containingmodel
andCmd.none
- Remove
viewListItem
and its type declaration - In the
view
, output an emptydiv
- Change the type declaration of
model
- Remove the current properties
- Add
x
andy
as integers - Add
code
as a string
- Change the definition of
model
- Set
x
andy
to be zero - Set
code
to be the string containing the number one
- Set
- Import
Html.Attributes
exposing(..)
- Style the
div
in the view:- Give it a
1px
black border - Set the
display
toinline-block
- Set its
position
toabsolute
- Give it
10px
ofpadding
- Give it a
- Give it some dynamic features:
- Set the
left
positioning tox
- Set the
top
positioning toy
- Use
code
as the contents
- Set the
- Add
MouseMsg
andKeyMsg
to the type declaration ofMsg
MouseMsg
takes an argument of typeMouse.Position
KeyMsg
takes an argument of typeKeyboard.KeyCode
- Add
MouseMsg
to theupdate
case with an argument namedposition
:- Change
x
toposition.x
- Change
y
toposition.y
- Include
Cmd.none
in the returned tuple
- Change
- Add
KeyMsg
to theupdate
case with an argument namedkeycode
:- Change
code
on the model to the string version ofkeycode
- Include
Cmd.none
in the returned tuple
- Change
- Replace
Sub.none
withSub.batch
, which takes a list as its argument - Add
Mouse.moves
to the list, withMouseMsg
as its argument - Add
Keyboard.downs
to the list, withKeyMsg
as its argument