π³
π³
π³
π³
Walking though the Elm woods
Searchβ¦
π³
π³
π³
π³
Walking though the Elm woods
Introduction
Structure of the book
Frequently asked questions
How can different types share data?
How to break Dependency Cycles?
How to structure an Elm project?
How to turn a Msg into a Cmd Msg?
How to update nested Records?
What are comparable types?
Why are Booleans bad?
π
Future topics
Recipes
Writing a Single Page Application
Making impossible states Impossible
Designing Elm package APIs
π
Future topics
Frameworks and packages
elm/parser
mdgriffith/elm-ui
π
Future topics
Powered By
GitBook
How to break Dependency Cycles?
Problem
Solution
Alternative Solution
Main.elm
import User exposing (User)
β
type Model =
Maybe User
β
type Msg =
UserSpecific User.Msg
Login String String
β
update : Msg -> Model -> (Model,Cmd Msg)
update msg =
case msg of
UserSpecific userMsg ->
User.update userMsg
Login name pass ->
Debug.todo "login user"
User.elm
import Main exposing (Msg)
β
type User =
..
β
type Msg =
..
updateUser : Msg -> User -> (Model,Cmd Msg)
β
viewUser : User -> Html Msg
Main.elm
import User exposing (User)
β
type Model =
Maybe User
β
type Msg =
UserSpecific User.Msg
Login String String
β
update : Msg -> Model -> (Model,Cmd Msg)
update msg =
case msg of
UserSpecific userMsg ->
User.update Just UserSpecific userMsg
Login name pass ->
Debug.todo "login user"
User.elm
type User =
..
β
type Msg =
..
updateUser : (User -> model) -> (Msg -> msg) -> Msg -> User -> (model,Cmd msg)
Main.elm
import User exposing (User)
β
type Model =
Maybe User
β
type Msg =
UserSpecific User.Msg
Login String String
β
update : Msg -> Model -> (Model,Cmd Msg)
update msg =
case msg of
UserSpecific userMsg ->
let
(user,msg) = User.update userMsg
in
(Just User,UserSpecific msg)
Login name pass ->
Debug.todo "login user"
User.elm
type User =
..
β
type Msg =
..
updateUser : Msg -> User -> (User,Cmd User.Msg)
Question
How to break out of the dependency cycles?
Answer
1.
Isolate the elements that both of the source modules need access to.
2.
Move the shared elements into a new module.
3.
Make the source module depend on the new Module.
Further Reading
π
Article:
High-Level Dependency Strategies in Elm
by Matthew Buscemi
Frequently asked questions - Previous
How can different types share data?
Next - Frequently asked questions
How to structure an Elm project?
Last modified
2yr ago
Copy link
Outline
Question
Answer
Further Reading