0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-14 19:19:09 -05:00

Improved persistence subsystem.

Now is more effisient and only performs the
persistence operations only when persistent
datata is changed (not the whole state atom)
This commit is contained in:
Andrey Antukh 2015-12-23 15:44:03 +02:00
parent 8201df7014
commit 90dd207e88
3 changed files with 21 additions and 6 deletions

View file

@ -1,6 +1,7 @@
(ns uxbox.core (ns uxbox.core
(:require [beicon.core :as rx] (:require [beicon.core :as rx]
[uxbox.state :as s] [cats.labs.lens :as l]
[uxbox.state :as st]
[uxbox.router :as rt] [uxbox.router :as rt]
[uxbox.rstore :as rs] [uxbox.rstore :as rs]
[uxbox.ui :as ui] [uxbox.ui :as ui]
@ -8,12 +9,24 @@
(enable-console-print!) (enable-console-print!)
(defn main
"Initialize the storage subsystem."
[]
(let [lens (l/select-keys [:pages-by-id
:projects-by-id])
stream (->> (l/focus-atom lens st/state)
(rx/from-atom)
(rx/debounce 1000)
(rx/tap #(println "[save]")))]
(rx/on-value stream #(dl/persist-state %))))
(defonce +setup+ (defonce +setup+
(do (do
(println "bootstrap") (println "bootstrap")
(st/init)
(rt/init) (rt/init)
(ui/init) (ui/init)
(rs/emit! (dl/load-data)) (rs/emit! (dl/load-data))
(rx/on-value s/stream #(dl/persist-state %)))) (main)))

View file

@ -2,8 +2,6 @@
(:require [beicon.core :as rx] (:require [beicon.core :as rx]
[uxbox.rstore :as rs])) [uxbox.rstore :as rs]))
(enable-console-print!)
(defonce state (atom {})) (defonce state (atom {}))
(defonce stream (defonce stream
@ -17,4 +15,8 @@
:projects-by-id {} :projects-by-id {}
:pages-by-id {}})) :pages-by-id {}}))
(rx/to-atom stream state)
(defn init
"Initialize the state materialization."
[]
(rx/to-atom stream state))

View file

@ -43,7 +43,7 @@
[rum "0.6.0"] [rum "0.6.0"]
[bouncer "0.3.3"] [bouncer "0.3.3"]
[funcool/promesa "0.6.0"] [funcool/promesa "0.6.0"]
[funcool/beicon "0.3.0"] [funcool/beicon "0.4.0"]
[cljsjs/moment "2.10.6-0"] [cljsjs/moment "2.10.6-0"]
[figwheel-sidecar "0.5.0-2" :scope "test"] [figwheel-sidecar "0.5.0-2" :scope "test"]
[bidi "1.21.0"] [bidi "1.21.0"]