mirror of
https://github.com/penpot/penpot.git
synced 2025-05-22 09:56:11 +02:00
✨ Refactor to the context api
This commit is contained in:
parent
7b508f2803
commit
0ffd82299f
7 changed files with 187 additions and 82 deletions
|
@ -8,8 +8,9 @@
|
|||
"RPC for plugins runtime."
|
||||
(:require
|
||||
[app.common.record :as crc]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.plugins.shape :as shape]
|
||||
[app.plugins.utils :as utils]))
|
||||
[app.plugins.utils :refer [get-data-fn]]))
|
||||
|
||||
(def ^:private
|
||||
xf-map-shape-proxy
|
||||
|
@ -17,9 +18,14 @@
|
|||
(map val)
|
||||
(map shape/data->shape-proxy)))
|
||||
|
||||
(deftype PageProxy [id name
|
||||
#_:clj-kondo/ignore _data]
|
||||
(deftype PageProxy [#_:clj-kondo/ignore _data]
|
||||
Object
|
||||
(getShapeById [_ id]
|
||||
(shape/data->shape-proxy (get (:objects _data) (uuid/uuid id))))
|
||||
|
||||
(getRoot [_]
|
||||
(shape/data->shape-proxy (get (:objects _data) uuid/zero)))
|
||||
|
||||
(findShapes [_]
|
||||
;; Returns a lazy (iterable) of all available shapes
|
||||
(apply array (sequence xf-map-shape-proxy (:objects _data)))))
|
||||
|
@ -31,8 +37,16 @@
|
|||
|
||||
(defn data->page-proxy
|
||||
[data]
|
||||
(utils/hide-data!
|
||||
(->PageProxy
|
||||
(str (:id data))
|
||||
(:name data)
|
||||
data)))
|
||||
|
||||
(crc/add-properties!
|
||||
(PageProxy. data)
|
||||
{:name "_data" :enumerable false}
|
||||
|
||||
{:name "id"
|
||||
:get (get-data-fn :id str)}
|
||||
|
||||
{:name "name"
|
||||
:get (get-data-fn :name)}
|
||||
|
||||
{:name "root"
|
||||
:get #(.getRoot ^js %)}))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue