0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-10 09:08:31 -05:00

Move pages-l lense to sitemap ns and add small optimizations to base lenses.

This commit is contained in:
Andrey Antukh 2016-03-19 19:10:11 +02:00
parent 289ac74553
commit 2201339887
2 changed files with 28 additions and 22 deletions

View file

@ -22,42 +22,35 @@
;; Lenses ;; Lenses
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def ^:static project-l (def ^:const workspace-l
(as-> (l/in [:workspace]) $
(l/focus-atom $ st/state)))
(def ^:const project-l
(letfn [(getter [state] (letfn [(getter [state]
(let [project (get-in state [:workspace :project])] (let [project (get-in state [:workspace :project])]
(get-in state [:projects-by-id project])))] (get-in state [:projects-by-id project])))]
(as-> (ul/getter getter) $ (as-> (ul/getter getter) $
(l/focus-atom $ st/state)))) (l/focus-atom $ st/state))))
(def ^:static page-l (def ^:const page-l
(letfn [(getter [state] (letfn [(getter [state]
(let [page (get-in state [:workspace :page])] (let [page (get-in state [:workspace :page])]
(get-in state [:pages-by-id page])))] (get-in state [:pages-by-id page])))]
(as-> (ul/getter getter) $ (as-> (ul/getter getter) $
(l/focus-atom $ st/state)))) (l/focus-atom $ st/state))))
(def ^:static pages-l
(letfn [(getter [state]
(let [project (get-in state [:workspace :project])]
(stpr/project-pages state project)))]
(as-> (ul/getter getter) $
(l/focus-atom $ st/state))))
(def ^:static workspace-l
(as-> (l/in [:workspace]) $
(l/focus-atom $ st/state)))
(def ^:static selected-shapes-l (def ^:static selected-shapes-l
(as-> (l/in [:workspace :selected]) $ (as-> (l/in [:selected]) $
(l/focus-atom $ st/state))) (l/focus-atom $ workspace-l)))
(def ^:static toolboxes-l (def ^:static toolboxes-l
(as-> (l/in [:workspace :toolboxes]) $ (as-> (l/in [:toolboxes]) $
(l/focus-atom $ st/state))) (l/focus-atom $ workspace-l)))
(def ^:static flags-l (def ^:static flags-l
(as-> (l/in [:workspace :flags]) $ (as-> (l/in [:flags]) $
(l/focus-atom $ st/state))) (l/focus-atom $ workspace-l)))
(def ^:static shapes-by-id-l (def ^:static shapes-by-id-l
(as-> (l/key :shapes-by-id) $ (as-> (l/key :shapes-by-id) $

View file

@ -14,6 +14,7 @@
[uxbox.router :as r] [uxbox.router :as r]
[uxbox.rstore :as rs] [uxbox.rstore :as rs]
[uxbox.state :as st] [uxbox.state :as st]
[uxbox.state.project :as stpr]
[uxbox.shapes :as shapes] [uxbox.shapes :as shapes]
[uxbox.library :as library] [uxbox.library :as library]
[uxbox.data.projects :as dp] [uxbox.data.projects :as dp]
@ -24,12 +25,24 @@
[uxbox.ui.icons :as i] [uxbox.ui.icons :as i]
[uxbox.ui.mixins :as mx] [uxbox.ui.mixins :as mx]
[uxbox.ui.lightbox :as lightbox] [uxbox.ui.lightbox :as lightbox]
[uxbox.util.lens :as ul]
[uxbox.util.data :refer (read-string parse-int)] [uxbox.util.data :refer (read-string parse-int)]
[uxbox.util.dom :as dom])) [uxbox.util.dom :as dom]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Lenses
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def ^:static pages-l
(letfn [(getter [state]
(let [project (get-in state [:workspace :project])]
(stpr/project-pages state project)))]
(as-> (ul/getter getter) $
(l/focus-atom $ st/state))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Component ;; Component
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn page-item-render (defn page-item-render
[own page total active?] [own page total active?]
@ -60,7 +73,7 @@
(defn sitemap-toolbox-render (defn sitemap-toolbox-render
[own] [own]
(let [project (rum/react wb/project-l) (let [project (rum/react wb/project-l)
pages (rum/react wb/pages-l) pages (rum/react pages-l)
current (rum/react wb/page-l) current (rum/react wb/page-l)
create #(lightbox/open! :page-form {:page {:project (:id project)}}) create #(lightbox/open! :page-form {:page {:project (:id project)}})
close #(rs/emit! (dw/toggle-flag :sitemap))] close #(rs/emit! (dw/toggle-flag :sitemap))]