mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 23:49:45 -05:00
Make state initialization parametrizable.
This commit is contained in:
parent
cf2a838007
commit
1091ffa27a
2 changed files with 9 additions and 19 deletions
|
@ -49,7 +49,7 @@
|
|||
(defrecord Login [username password]
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(merge state (dissoc (st/get-initial-state) :route)))
|
||||
(merge state (dissoc (st/initial-state) :route)))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [this state s]
|
||||
|
@ -72,7 +72,7 @@
|
|||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(swap! storage dissoc :uxbox/auth)
|
||||
(merge state (dissoc (st/get-initial-state) :route)))
|
||||
(merge state (dissoc (st/initial-state) :route)))
|
||||
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
|
|
|
@ -15,14 +15,13 @@
|
|||
(enable-console-print!)
|
||||
|
||||
(defonce state (atom {}))
|
||||
(defonce loader (atom false))
|
||||
|
||||
(def auth-l
|
||||
(-> (l/key :auth)
|
||||
(l/focus-atom state)))
|
||||
|
||||
(def loader (atom false))
|
||||
|
||||
(defn- get-initial-state
|
||||
(defn initial-state
|
||||
[]
|
||||
{:dashboard {:project-order :name
|
||||
:project-filter ""
|
||||
|
@ -40,19 +39,10 @@
|
|||
:projects-by-id {}
|
||||
:pages-by-id {}})
|
||||
|
||||
(defn- on-error
|
||||
[error]
|
||||
;; Disable loader in case of error.
|
||||
(reset! loader false))
|
||||
|
||||
(rs/add-error-watcher :test on-error)
|
||||
|
||||
(defonce stream
|
||||
(rs/init (get-initial-state)))
|
||||
|
||||
(defn init
|
||||
"Initialize the state materialization."
|
||||
[]
|
||||
(as-> stream $
|
||||
(rx/dedupe $)
|
||||
(rx/to-atom $ state)))
|
||||
([] (init initial-state))
|
||||
([& callbacks]
|
||||
(-> (reduce #(merge %1 (%2)) nil callbacks)
|
||||
(rs/init)
|
||||
(rx/to-atom state))))
|
||||
|
|
Loading…
Add table
Reference in a new issue