mirror of
https://github.com/heyarne/airsonic-ui.git
synced 2026-05-07 02:33:39 +02:00
Use rf instead of re-frame
This commit is contained in:
parent
a75cdca9e1
commit
e911092113
6 changed files with 60 additions and 60 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
"This namespace contains some JS interop code to interact with an audio player
|
"This namespace contains some JS interop code to interact with an audio player
|
||||||
and receive information about the current playback status so we can use it in
|
and receive information about the current playback status so we can use it in
|
||||||
our re-frame app."
|
our re-frame app."
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as rf]
|
||||||
[airsonic-ui.audio.playlist :as playlist]
|
[airsonic-ui.audio.playlist :as playlist]
|
||||||
[goog.functions :refer [throttle]]))
|
[goog.functions :refer [throttle]]))
|
||||||
|
|
||||||
|
|
@ -29,13 +29,13 @@
|
||||||
|
|
||||||
|
|
||||||
(defn attach-listeners! [el]
|
(defn attach-listeners! [el]
|
||||||
(let [emit-audio-update (throttle #(re-frame/dispatch [:audio/update (->status el)]) 16)]
|
(let [emit-audio-update (throttle #(rf/dispatch [:audio/update (->status el)]) 16)]
|
||||||
(doseq [event ["loadstart" "progress" "play" "timeupdate" "pause"]]
|
(doseq [event ["loadstart" "progress" "play" "timeupdate" "pause"]]
|
||||||
(.addEventListener el event emit-audio-update))))
|
(.addEventListener el event emit-audio-update))))
|
||||||
|
|
||||||
;; effects to be fired from event handlers
|
;; effects to be fired from event handlers
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(rf/reg-fx
|
||||||
:audio/play
|
:audio/play
|
||||||
(fn [stream-url]
|
(fn [stream-url]
|
||||||
(when-not @audio
|
(when-not @audio
|
||||||
|
|
@ -45,19 +45,19 @@
|
||||||
(set! (.-src @audio) stream-url)
|
(set! (.-src @audio) stream-url)
|
||||||
(.play @audio)))
|
(.play @audio)))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(rf/reg-fx
|
||||||
:audio/pause
|
:audio/pause
|
||||||
(fn [_]
|
(fn [_]
|
||||||
(some-> @audio .pause)))
|
(some-> @audio .pause)))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(rf/reg-fx
|
||||||
:audio/stop
|
:audio/stop
|
||||||
(fn [_]
|
(fn [_]
|
||||||
(when-let [audio @audio]
|
(when-let [audio @audio]
|
||||||
(.pause audio)
|
(.pause audio)
|
||||||
(set! (.-currentTime audio) 0))))
|
(set! (.-currentTime audio) 0))))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(rf/reg-fx
|
||||||
:audio/toggle-play-pause
|
:audio/toggle-play-pause
|
||||||
(fn [_]
|
(fn [_]
|
||||||
(if-let [a @audio]
|
(if-let [a @audio]
|
||||||
|
|
@ -65,7 +65,7 @@
|
||||||
(.play a)
|
(.play a)
|
||||||
(.pause a)))))
|
(.pause a)))))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(rf/reg-fx
|
||||||
:audio/seek
|
:audio/seek
|
||||||
(fn [[percentage duration]]
|
(fn [[percentage duration]]
|
||||||
(set! (. @audio -currentTime)
|
(set! (. @audio -currentTime)
|
||||||
|
|
@ -78,16 +78,16 @@
|
||||||
[db _]
|
[db _]
|
||||||
(:audio db))
|
(:audio db))
|
||||||
|
|
||||||
(re-frame/reg-sub :audio/summary summary)
|
(rf/reg-sub :audio/summary summary)
|
||||||
|
|
||||||
(defn playlist
|
(defn playlist
|
||||||
"Lists the complete playlist"
|
"Lists the complete playlist"
|
||||||
[summary _]
|
[summary _]
|
||||||
(:playlist summary))
|
(:playlist summary))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(rf/reg-sub
|
||||||
:audio/playlist
|
:audio/playlist
|
||||||
(fn [_ _] (re-frame/subscribe [:audio/summary]))
|
(fn [_ _] (rf/subscribe [:audio/summary]))
|
||||||
playlist)
|
playlist)
|
||||||
|
|
||||||
(defn current-song
|
(defn current-song
|
||||||
|
|
@ -96,9 +96,9 @@
|
||||||
[playlist _]
|
[playlist _]
|
||||||
(playlist/peek playlist))
|
(playlist/peek playlist))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(rf/reg-sub
|
||||||
:audio/current-song
|
:audio/current-song
|
||||||
(fn [_ _] (re-frame/subscribe [:audio/playlist]))
|
(fn [_ _] (rf/subscribe [:audio/playlist]))
|
||||||
current-song)
|
current-song)
|
||||||
|
|
||||||
(defn playback-status
|
(defn playback-status
|
||||||
|
|
@ -106,9 +106,9 @@
|
||||||
[summary _]
|
[summary _]
|
||||||
(:playback-status summary))
|
(:playback-status summary))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(rf/reg-sub
|
||||||
:audio/playback-status
|
:audio/playback-status
|
||||||
(fn [_ _] (re-frame/subscribe [:audio/summary]))
|
(fn [_ _] (rf/subscribe [:audio/summary]))
|
||||||
playback-status)
|
playback-status)
|
||||||
|
|
||||||
(defn is-playing?
|
(defn is-playing?
|
||||||
|
|
@ -117,7 +117,7 @@
|
||||||
(and (not (:paused? playback-status))
|
(and (not (:paused? playback-status))
|
||||||
(not (:ended? playback-status))))
|
(not (:ended? playback-status))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(rf/reg-sub
|
||||||
:audio/is-playing?
|
:audio/is-playing?
|
||||||
(fn [_ _] (re-frame/subscribe [:audio/playback-status]))
|
(fn [_ _] (rf/subscribe [:audio/playback-status]))
|
||||||
is-playing?)
|
is-playing?)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
(ns airsonic-ui.components.audio-player.events
|
(ns airsonic-ui.components.audio-player.events
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as rf]
|
||||||
[airsonic-ui.audio.playlist :as playlist]
|
[airsonic-ui.audio.playlist :as playlist]
|
||||||
[airsonic-ui.api.helpers :as api]))
|
[airsonic-ui.api.helpers :as api]))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(rf/reg-event-fx
|
||||||
; sets up the db, starts to play a song and adds the rest to a playlist
|
; sets up the db, starts to play a song and adds the rest to a playlist
|
||||||
:audio-player/play-all
|
:audio-player/play-all
|
||||||
(fn [{:keys [db]} [_ songs start-idx]]
|
(fn [{:keys [db]} [_ songs start-idx]]
|
||||||
|
|
@ -12,17 +12,17 @@
|
||||||
{:audio/play (api/stream-url (:credentials db) (playlist/peek playlist))
|
{:audio/play (api/stream-url (:credentials db) (playlist/peek playlist))
|
||||||
:db (assoc-in db [:audio :playlist] playlist)})))
|
:db (assoc-in db [:audio :playlist] playlist)})))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(rf/reg-event-db
|
||||||
:audio-player/set-playback-mode
|
:audio-player/set-playback-mode
|
||||||
(fn [db [_ playback-mode]]
|
(fn [db [_ playback-mode]]
|
||||||
(update-in db [:audio :playlist] #(playlist/set-playback-mode % playback-mode))))
|
(update-in db [:audio :playlist] #(playlist/set-playback-mode % playback-mode))))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(rf/reg-event-db
|
||||||
:audio-player/set-repeat-mode
|
:audio-player/set-repeat-mode
|
||||||
(fn [db [_ repeat-mode]]
|
(fn [db [_ repeat-mode]]
|
||||||
(update-in db [:audio :playlist] #(playlist/set-repeat-mode % repeat-mode))))
|
(update-in db [:audio :playlist] #(playlist/set-repeat-mode % repeat-mode))))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:audio-player/next-song
|
:audio-player/next-song
|
||||||
(fn [{:keys [db]} _]
|
(fn [{:keys [db]} _]
|
||||||
(let [db (update-in db [:audio :playlist] playlist/next-song)
|
(let [db (update-in db [:audio :playlist] playlist/next-song)
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
{:db db
|
{:db db
|
||||||
:audio/play (api/stream-url (:credentials db) next)})))
|
:audio/play (api/stream-url (:credentials db) next)})))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:audio-player/previous-song
|
:audio-player/previous-song
|
||||||
(fn [{:keys [db]} _]
|
(fn [{:keys [db]} _]
|
||||||
(let [db (update-in db [:audio :playlist] playlist/previous-song)
|
(let [db (update-in db [:audio :playlist] playlist/previous-song)
|
||||||
|
|
@ -38,17 +38,17 @@
|
||||||
{:db db
|
{:db db
|
||||||
:audio/play (api/stream-url (:credentials db) prev)})))
|
:audio/play (api/stream-url (:credentials db) prev)})))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(rf/reg-event-db
|
||||||
:audio-player/enqueue-next
|
:audio-player/enqueue-next
|
||||||
(fn [db [_ song]]
|
(fn [db [_ song]]
|
||||||
(update-in db [:audio :playlist] #(playlist/enqueue-next % song))))
|
(update-in db [:audio :playlist] #(playlist/enqueue-next % song))))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(rf/reg-event-db
|
||||||
:audio-player/enqueue-last
|
:audio-player/enqueue-last
|
||||||
(fn [db [_ song]]
|
(fn [db [_ song]]
|
||||||
(update-in db [:audio :playlist] #(playlist/enqueue-last % song))))
|
(update-in db [:audio :playlist] #(playlist/enqueue-last % song))))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:audio-player/toggle-play-pause
|
:audio-player/toggle-play-pause
|
||||||
(fn [_ _]
|
(fn [_ _]
|
||||||
{:audio/toggle-play-pause nil}))
|
{:audio/toggle-play-pause nil}))
|
||||||
|
|
@ -60,9 +60,9 @@
|
||||||
(cond-> {:db (assoc-in db [:audio :playback-status] status)}
|
(cond-> {:db (assoc-in db [:audio :playback-status] status)}
|
||||||
(:ended? status) (assoc :dispatch [:audio-player/next-song])))
|
(:ended? status) (assoc :dispatch [:audio-player/next-song])))
|
||||||
|
|
||||||
(re-frame/reg-event-fx :audio/update audio-update)
|
(rf/reg-event-fx :audio/update audio-update)
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:audio-player/seek
|
:audio-player/seek
|
||||||
(fn [{:keys [db]} [_ percentage]]
|
(fn [{:keys [db]} [_ percentage]]
|
||||||
(let [duration (:duration (playlist/peek (get-in db [:audio :playlist])))]
|
(let [duration (:duration (playlist/peek (get-in db [:audio :playlist])))]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
(ns airsonic-ui.components.library.subs
|
(ns airsonic-ui.components.library.subs
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as rf]
|
||||||
[airsonic-ui.config :as conf]))
|
[airsonic-ui.config :as conf]))
|
||||||
|
|
||||||
;; first some helper functions to make the structure a bit clearer
|
;; first some helper functions to make the structure a bit clearer
|
||||||
|
|
@ -34,7 +34,7 @@
|
||||||
(map (fn [[k v]] [(inc k) v]))
|
(map (fn [[k v]] [(inc k) v]))
|
||||||
(into (sorted-map))))
|
(into (sorted-map))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(rf/reg-sub
|
||||||
:library/paginated
|
:library/paginated
|
||||||
:<- [:api/responses-for-endpoint "getAlbumList2"]
|
:<- [:api/responses-for-endpoint "getAlbumList2"]
|
||||||
paginated-library)
|
paginated-library)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
(ns airsonic-ui.core
|
(ns airsonic-ui.core
|
||||||
(:require [reagent.core :as reagent]
|
(:require [reagent.core :as reagent]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as rf]
|
||||||
;; 3rd party effects / coeffects
|
;; 3rd party effects / coeffects
|
||||||
[day8.re-frame.http-fx]
|
[day8.re-frame.http-fx]
|
||||||
[akiroz.re-frame.storage :as storage]
|
[akiroz.re-frame.storage :as storage]
|
||||||
|
|
@ -24,12 +24,12 @@
|
||||||
(println "dev mode")))
|
(println "dev mode")))
|
||||||
|
|
||||||
(defn mount-root []
|
(defn mount-root []
|
||||||
(re-frame/clear-subscription-cache!)
|
(rf/clear-subscription-cache!)
|
||||||
(reagent/render [views/main-panel] (.getElementById js/document "app")))
|
(reagent/render [views/main-panel] (.getElementById js/document "app")))
|
||||||
|
|
||||||
(defn ^:export init []
|
(defn ^:export init []
|
||||||
(storage/reg-co-fx! :airsonic-ui {:fx :store
|
(storage/reg-co-fx! :airsonic-ui {:fx :store
|
||||||
:cofx :store})
|
:cofx :store})
|
||||||
(re-frame/dispatch-sync [::events/initialize-app])
|
(rf/dispatch-sync [::events/initialize-app])
|
||||||
(dev-setup)
|
(dev-setup)
|
||||||
(mount-root))
|
(mount-root))
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
(ns airsonic-ui.events
|
(ns airsonic-ui.events
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as rf]
|
||||||
[ajax.core :as ajax]
|
[ajax.core :as ajax]
|
||||||
[airsonic-ui.routes :as routes]
|
[airsonic-ui.routes :as routes]
|
||||||
[airsonic-ui.db :as db]
|
[airsonic-ui.db :as db]
|
||||||
[airsonic-ui.api.helpers :as api]))
|
[airsonic-ui.api.helpers :as api]))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(rf/reg-fx
|
||||||
;; a simple effect to keep println statements out of our event handlers
|
;; a simple effect to keep println statements out of our event handlers
|
||||||
:log
|
:log
|
||||||
(fn [params]
|
(fn [params]
|
||||||
|
|
@ -31,9 +31,9 @@
|
||||||
(assoc effects :dispatch [:credentials/verify credentials])
|
(assoc effects :dispatch [:credentials/verify credentials])
|
||||||
effects)))
|
effects)))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(rf/reg-event-fx
|
||||||
::initialize-app
|
::initialize-app
|
||||||
[(re-frame/inject-cofx :store)]
|
[(rf/inject-cofx :store)]
|
||||||
initialize-app)
|
initialize-app)
|
||||||
|
|
||||||
(defn verify-credentials
|
(defn verify-credentials
|
||||||
|
|
@ -44,7 +44,7 @@
|
||||||
(if (every? string? ((juxt :u :p :server) credentials))
|
(if (every? string? ((juxt :u :p :server) credentials))
|
||||||
{:dispatch [:credentials/send-authentication-request credentials]}))
|
{:dispatch [:credentials/send-authentication-request credentials]}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx :credentials/verify verify-credentials)
|
(rf/reg-event-fx :credentials/verify verify-credentials)
|
||||||
|
|
||||||
;; ---
|
;; ---
|
||||||
;; auth logic
|
;; auth logic
|
||||||
|
|
@ -57,7 +57,7 @@
|
||||||
{:db (assoc db :credentials credentials)
|
{:db (assoc db :credentials credentials)
|
||||||
:dispatch [:credentials/send-authentication-request credentials]}))
|
:dispatch [:credentials/send-authentication-request credentials]}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx :credentials/user-login user-login)
|
(rf/reg-event-fx :credentials/user-login user-login)
|
||||||
|
|
||||||
(defn authentication-request
|
(defn authentication-request
|
||||||
"Tries to authenticate a user by requesting info about the given user, saving
|
"Tries to authenticate a user by requesting info about the given user, saving
|
||||||
|
|
@ -69,7 +69,7 @@
|
||||||
:on-success [:credentials/authentication-response credentials]
|
:on-success [:credentials/authentication-response credentials]
|
||||||
:on-failure [:api/failed-response]}}) ; <- we don't need endpoint and params here because the response is not cached
|
:on-failure [:api/failed-response]}}) ; <- we don't need endpoint and params here because the response is not cached
|
||||||
|
|
||||||
(re-frame/reg-event-fx :credentials/send-authentication-request authentication-request)
|
(rf/reg-event-fx :credentials/send-authentication-request authentication-request)
|
||||||
|
|
||||||
(defn authentication-response
|
(defn authentication-response
|
||||||
"Since we don't get real status codes, we have to look into the server's
|
"Since we don't get real status codes, we have to look into the server's
|
||||||
|
|
@ -79,7 +79,7 @@
|
||||||
[:credentials/authentication-failure response]
|
[:credentials/authentication-failure response]
|
||||||
[:credentials/authentication-success credentials response])})
|
[:credentials/authentication-success credentials response])})
|
||||||
|
|
||||||
(re-frame/reg-event-fx :credentials/authentication-response authentication-response)
|
(rf/reg-event-fx :credentials/authentication-response authentication-response)
|
||||||
|
|
||||||
(defn authentication-failure
|
(defn authentication-failure
|
||||||
"Removes all stored credentials and displays potential api errors to the user"
|
"Removes all stored credentials and displays potential api errors to the user"
|
||||||
|
|
@ -88,7 +88,7 @@
|
||||||
:store (dissoc store :credentials)
|
:store (dissoc store :credentials)
|
||||||
:db (dissoc db :credentials)})
|
:db (dissoc db :credentials)})
|
||||||
|
|
||||||
(re-frame/reg-event-fx :credentials/authentication-failure authentication-failure)
|
(rf/reg-event-fx :credentials/authentication-failure authentication-failure)
|
||||||
|
|
||||||
(defn authentication-success
|
(defn authentication-success
|
||||||
"Gets called after the server indicates that the credentials entered by a user
|
"Gets called after the server indicates that the credentials entered by a user
|
||||||
|
|
@ -99,7 +99,7 @@
|
||||||
(assoc :user (api/unwrap-response auth-response)))
|
(assoc :user (api/unwrap-response auth-response)))
|
||||||
:dispatch [::logged-in]})
|
:dispatch [::logged-in]})
|
||||||
|
|
||||||
(re-frame/reg-event-fx :credentials/authentication-success authentication-success)
|
(rf/reg-event-fx :credentials/authentication-success authentication-success)
|
||||||
|
|
||||||
(defn logged-in
|
(defn logged-in
|
||||||
[cofx _]
|
[cofx _]
|
||||||
|
|
@ -107,9 +107,9 @@
|
||||||
[::routes/library])]
|
[::routes/library])]
|
||||||
{:dispatch [:routes/do-navigation redirect]}))
|
{:dispatch [:routes/do-navigation redirect]}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(rf/reg-event-fx
|
||||||
::logged-in
|
::logged-in
|
||||||
[(re-frame/inject-cofx :routes/from-query-param :redirect)]
|
[(rf/inject-cofx :routes/from-query-param :redirect)]
|
||||||
logged-in)
|
logged-in)
|
||||||
|
|
||||||
(defn logout
|
(defn logout
|
||||||
|
|
@ -123,21 +123,21 @@
|
||||||
:db db/default-db
|
:db db/default-db
|
||||||
:audio/stop nil}))
|
:audio/stop nil}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx ::logout logout)
|
(rf/reg-event-fx ::logout logout)
|
||||||
|
|
||||||
;; ---
|
;; ---
|
||||||
;; routing
|
;; routing
|
||||||
;; ---
|
;; ---
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:routes/did-navigate
|
:routes/did-navigate
|
||||||
(fn [{:keys [db]} [_ route params query]]
|
(fn [{:keys [db]} [_ route params query]]
|
||||||
{:db (assoc db :routes/current-route [route params query])
|
{:db (assoc db :routes/current-route [route params query])
|
||||||
:dispatch-n (routes/route-events route params query)}))
|
:dispatch-n (routes/route-events route params query)}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:routes/unauthorized
|
:routes/unauthorized
|
||||||
[(re-frame/inject-cofx :routes/current-route)]
|
[(rf/inject-cofx :routes/current-route)]
|
||||||
(fn [{:routes/keys [current-route]} _]
|
(fn [{:routes/keys [current-route]} _]
|
||||||
{:dispatch [::logout :redirect-to current-route]}))
|
{:dispatch [::logout :redirect-to current-route]}))
|
||||||
|
|
||||||
|
|
@ -161,10 +161,10 @@
|
||||||
:dispatch-later [{:ms (get notification-duration level)
|
:dispatch-later [{:ms (get notification-duration level)
|
||||||
:dispatch [:notification/hide id]}]}))
|
:dispatch [:notification/hide id]}]}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx :notification/show show-notification)
|
(rf/reg-event-fx :notification/show show-notification)
|
||||||
|
|
||||||
(defn hide-notification
|
(defn hide-notification
|
||||||
[db [_ notification-id]]
|
[db [_ notification-id]]
|
||||||
(update db :notifications dissoc notification-id))
|
(update db :notifications dissoc notification-id))
|
||||||
|
|
||||||
(re-frame/reg-event-db :notification/hide hide-notification)
|
(rf/reg-event-db :notification/hide hide-notification)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
(ns airsonic-ui.routes
|
(ns airsonic-ui.routes
|
||||||
(:require [bide.core :as r]
|
(:require [bide.core :as r]
|
||||||
[cljs.reader :refer [read-string]]
|
[cljs.reader :refer [read-string]]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as rf]
|
||||||
[airsonic-ui.config :as conf]))
|
[airsonic-ui.config :as conf]))
|
||||||
|
|
||||||
(def default-route ::login)
|
(def default-route ::login)
|
||||||
|
|
@ -96,15 +96,15 @@
|
||||||
|
|
||||||
;; subscription returning the matched route for the current hashbang
|
;; subscription returning the matched route for the current hashbang
|
||||||
|
|
||||||
(re-frame/reg-sub :routes/current-route (fn [db _] (:routes/current-route db)))
|
(rf/reg-sub :routes/current-route (fn [db _] (:routes/current-route db)))
|
||||||
|
|
||||||
;; NOTE: There is some duplication here. The route events are provided as a
|
;; NOTE: There is some duplication here. The route events are provided as a
|
||||||
;; subscription but they are also invoked directly in events.cljs. It didn't
|
;; subscription but they are also invoked directly in events.cljs. It didn't
|
||||||
;; seem to justify pulling in a whole library and we need it in our top most view
|
;; seem to justify pulling in a whole library and we need it in our top most view
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(rf/reg-sub
|
||||||
:routes/events-for-current-route
|
:routes/events-for-current-route
|
||||||
(fn [db _] (re-frame/subscribe [:routes/current-route]))
|
(fn [db _] (rf/subscribe [:routes/current-route]))
|
||||||
(fn [current-route _] (apply route-events current-route)))
|
(fn [current-route _] (apply route-events current-route)))
|
||||||
|
|
||||||
;; these are helper effects we can use to navigate; the first two manage an atom
|
;; these are helper effects we can use to navigate; the first two manage an atom
|
||||||
|
|
@ -133,7 +133,7 @@
|
||||||
(apply r/navigate! router route)
|
(apply r/navigate! router route)
|
||||||
(dissoc context :event)))))
|
(dissoc context :event)))))
|
||||||
|
|
||||||
(re-frame/reg-event-fx :routes/do-navigation do-navigation (fn [& _] nil))
|
(rf/reg-event-fx :routes/do-navigation do-navigation (fn [& _] nil))
|
||||||
|
|
||||||
(defn can-access? [route]
|
(defn can-access? [route]
|
||||||
(or (not (protected-routes route))
|
(or (not (protected-routes route))
|
||||||
|
|
@ -143,8 +143,8 @@
|
||||||
[route-id params query]
|
[route-id params query]
|
||||||
#_(println "calling on-navigate with" route credentials')
|
#_(println "calling on-navigate with" route credentials')
|
||||||
(if (can-access? route-id)
|
(if (can-access? route-id)
|
||||||
(re-frame/dispatch [:routes/did-navigate route-id params query])
|
(rf/dispatch [:routes/did-navigate route-id params query])
|
||||||
(re-frame/dispatch [:routes/unauthorized route-id params query])))
|
(rf/dispatch [:routes/unauthorized route-id params query])))
|
||||||
|
|
||||||
(defn encode-route
|
(defn encode-route
|
||||||
"Takes a parsed route and returns a representation that's suitable for
|
"Takes a parsed route and returns a representation that's suitable for
|
||||||
|
|
@ -163,13 +163,13 @@
|
||||||
(r/match router (subs (.. js/window -location -hash) 1)))
|
(r/match router (subs (.. js/window -location -hash) 1)))
|
||||||
|
|
||||||
;; add the current route to our coeffect map
|
;; add the current route to our coeffect map
|
||||||
(re-frame/reg-cofx
|
(rf/reg-cofx
|
||||||
:routes/current-route
|
:routes/current-route
|
||||||
(fn [coeffects _]
|
(fn [coeffects _]
|
||||||
(assoc coeffects :routes/current-route (current-route))))
|
(assoc coeffects :routes/current-route (current-route))))
|
||||||
|
|
||||||
;; add route into from a URL parameter to our coeffect map
|
;; add route into from a URL parameter to our coeffect map
|
||||||
(re-frame/reg-cofx
|
(rf/reg-cofx
|
||||||
:routes/from-query-param
|
:routes/from-query-param
|
||||||
(fn [coeffects param]
|
(fn [coeffects param]
|
||||||
;; this allows us to encode a complete route in a url fragment; useful for
|
;; this allows us to encode a complete route in a url fragment; useful for
|
||||||
|
|
@ -184,5 +184,5 @@
|
||||||
:on-navigate on-navigate}))
|
:on-navigate on-navigate}))
|
||||||
([_] (start-routing!))) ;; <- 1-arity is for the re-frame effect exposed below
|
([_] (start-routing!))) ;; <- 1-arity is for the re-frame effect exposed below
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(rf/reg-fx
|
||||||
:routes/start-routing start-routing!)
|
:routes/start-routing start-routing!)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue