I am struggling with circular addiction in ClojureScript. I test this language for a month, never worked with real (Clojure).
I have a client application that uses secretary as a router. When I define my routes, they perform the functions of a handler, click values โโon history-channel, which are then consumed by the main application component that displays certain views. So the values โโthat I click on my routes contain a link to the function view. This view function is an om component that displays a given location. In these presentation functions, I often need to create links, URLs elsewhere in the application. These URLs are generated from the same handler functions that reference them. This is how my circular addiction is born. What is an elegant way to solve 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)}]]))))