Skip to content

Commit

Permalink
Refactor out web-storage-state-store instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinqian00 committed Feb 24, 2025
1 parent 8809269 commit f6ad999
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/lib/com/yetanalytics/re_oidc.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@
(doto (UserManager. (clj->js config))
(reg-events! lifecycle-callbacks))))

(defn- web-storage-state-store
[store]
(let [store* (case store
:local-storage
js/window.localStorage
:session-storage
js/window.sessionStorage
;; custom
store)]
(new WebStorageStateStore #js {:store store*})))

(re-frame/reg-fx
::init-fx
(fn [{:keys [config
Expand All @@ -87,26 +98,9 @@
:as init-input}]
(swap! user-manager
init!
(assoc
config
"stateStore"
(new WebStorageStateStore
#js {:store (case state-store
:local-storage
js/window.localStorage
:session-storage
js/window.sessionStorage
;; custom
state-store)})
"userStore"
(new WebStorageStateStore
#js {:store (case user-store
:local-storage
js/window.localStorage
:session-storage
js/window.sessionStorage
;; custom
user-store)}))
(assoc config
"stateStore" (web-storage-state-store state-store)
"userStore" (web-storage-state-store user-store))
(select-keys init-input
[:on-user-loaded
:on-user-unloaded]))))
Expand Down

0 comments on commit f6ad999

Please sign in to comment.