How to break Dependency Cycles?
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"import Main exposing (Msg)
type User =
..
type Msg =
..
updateUser : Msg -> User -> (Model,Cmd Msg)
viewUser : User -> Html Msgimport 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"type User =
..
type Msg =
..
updateUser : (User -> model) -> (Msg -> msg) -> Msg -> User -> (model,Cmd msg)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"type User =
..
type Msg =
..
updateUser : Msg -> User -> (User,Cmd User.Msg)Question
How to break out of the dependency cycles?
Answer
Isolate the elements that both of the source modules need access to.
Move the shared elements into a new module.
Make the source module depend on the new Module.
Further Reading
📄Article: High-Level Dependency Strategies in Elm by Matthew Buscemi
Last updated
Was this helpful?