Minor structure refactor.

Make forms and messages modules independent of
store location (making them plugables).
This commit is contained in:
Andrey Antukh 2017-01-13 22:01:13 +01:00
parent 8c28a8c0a7
commit 08b0a096eb
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
87 changed files with 573 additions and 505 deletions

View file

@ -2,22 +2,19 @@
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
;; Copyright (c) 2015-2017 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.util.router
(:require [bide.core :as r]
[beicon.core :as rx]
[potok.core :as ptk]
[uxbox.store :as st]))
(enable-console-print!)
[uxbox.main.store :as st]))
(defonce +router+ nil)
;; --- Update Location (Event)
(defrecord UpdateLocation [id params]
(deftype UpdateLocation [id params]
ptk/UpdateEvent
(update [_ state]
(let [route (merge {:id id}
@ -35,7 +32,7 @@
;; --- Navigate (Event)
(defrecord Navigate [id params]
(deftype Navigate [id params]
ptk/EffectEvent
(effect [_ state stream]
(r/navigate! +router+ id params)))
@ -49,22 +46,16 @@
;; --- Public Api
(defn init
([routes]
(init routes nil))
([routes {:keys [default] :or {default :auth/login}}]
(let [opts {:on-navigate #(st/emit! (update-location %1 %2))
([store routes]
(init store routes nil))
([store routes {:keys [default] :or {default :auth/login}}]
(let [opts {:on-navigate #(ptk/emit! store (update-location %1 %2))
:default default}
router (-> (r/router routes)
(r/start! opts))]
(set! +router+ router)
router)))
(defn go
"Redirect the user to other url."
([id] (go id nil))
([id params]
(st/emit! (navigate id params))))
(defn route-for
"Given a location handler and optional parameter map, return the URI
for such handler and parameters."