mirror of
https://github.com/penpot/penpot.git
synced 2025-02-04 21:38:53 -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]
|
(defrecord Login [username password]
|
||||||
rs/UpdateEvent
|
rs/UpdateEvent
|
||||||
(-apply-update [_ state]
|
(-apply-update [_ state]
|
||||||
(merge state (dissoc (st/get-initial-state) :route)))
|
(merge state (dissoc (st/initial-state) :route)))
|
||||||
|
|
||||||
rs/WatchEvent
|
rs/WatchEvent
|
||||||
(-apply-watch [this state s]
|
(-apply-watch [this state s]
|
||||||
|
@ -72,7 +72,7 @@
|
||||||
rs/UpdateEvent
|
rs/UpdateEvent
|
||||||
(-apply-update [_ state]
|
(-apply-update [_ state]
|
||||||
(swap! storage dissoc :uxbox/auth)
|
(swap! storage dissoc :uxbox/auth)
|
||||||
(merge state (dissoc (st/get-initial-state) :route)))
|
(merge state (dissoc (st/initial-state) :route)))
|
||||||
|
|
||||||
rs/WatchEvent
|
rs/WatchEvent
|
||||||
(-apply-watch [_ state s]
|
(-apply-watch [_ state s]
|
||||||
|
|
|
@ -15,14 +15,13 @@
|
||||||
(enable-console-print!)
|
(enable-console-print!)
|
||||||
|
|
||||||
(defonce state (atom {}))
|
(defonce state (atom {}))
|
||||||
|
(defonce loader (atom false))
|
||||||
|
|
||||||
(def auth-l
|
(def auth-l
|
||||||
(-> (l/key :auth)
|
(-> (l/key :auth)
|
||||||
(l/focus-atom state)))
|
(l/focus-atom state)))
|
||||||
|
|
||||||
(def loader (atom false))
|
(defn initial-state
|
||||||
|
|
||||||
(defn- get-initial-state
|
|
||||||
[]
|
[]
|
||||||
{:dashboard {:project-order :name
|
{:dashboard {:project-order :name
|
||||||
:project-filter ""
|
:project-filter ""
|
||||||
|
@ -40,19 +39,10 @@
|
||||||
:projects-by-id {}
|
:projects-by-id {}
|
||||||
:pages-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
|
(defn init
|
||||||
"Initialize the state materialization."
|
"Initialize the state materialization."
|
||||||
[]
|
([] (init initial-state))
|
||||||
(as-> stream $
|
([& callbacks]
|
||||||
(rx/dedupe $)
|
(-> (reduce #(merge %1 (%2)) nil callbacks)
|
||||||
(rx/to-atom $ state)))
|
(rs/init)
|
||||||
|
(rx/to-atom state))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue