How to break Dependency Cycles?

Problem
Solution
Alternative Solution
Main.elm
User.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"
Main.elm
User.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"
Main.elm
User.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"

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