I'm struggling with a circular dependency in ClojureScript. I'm trying out this language for a month, haven't ever worked with the real thing (Clojure).
I have a client side app that uses secretary as a router. When I'm defining my routes, they're handler functions, push values to the history-channel, which is then consumed by the main app component that displays particular views. Thus, the values I push from my routes, contain a reference to the view function. This view function are om components that render the given location. In these view functions, I often need to generate links, URLs to other locations in the app. These URLs are generated from the same handler functions that references them. That's how my circular dependency is born. What is an elegant way to resolve it?
router -> views -> router
-- route.cljs
(ns myapp.route
(:require [secretary.core :as secretary :include-macros true :refer [defroute]]
[myapp.views.welcome :as welcome]
[myapp.views.some :as some]))
(defroute home "/" {}
(put! history-chan {:token "/"
:view welcome/view}))
(defroute some "/some" {}
(put! history-chan {:token "/some"
:view some/view}))
-- welcome.cljs
(ns myapp.views.welcome
(:require [om.core :as om :include-macros true]
[sablono.core :as html :refer-macros [html]]
[myapp.route :as route]))
(defn view [state owner]
(reify
om/IRender
(render [_]
(html [:div [:a {:href (route/some)}]]))))