0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-18 21:06:11 -05:00

Experiment for data definition

This commit is contained in:
alonso.torres 2024-04-15 17:48:03 +02:00 committed by Andrey Antukh
parent 127b481c38
commit 432e894344
2 changed files with 43 additions and 17 deletions

View file

@ -49,7 +49,10 @@
new-theme (get-in new-val [:profile :theme])] new-theme (get-in new-val [:profile :theme])]
(if (identical? old-theme new-theme) (if (identical? old-theme new-theme)
::not-changed ::not-changed
new-theme))) (if (= new-theme "default")
"dark"
new-theme))))
(defmethod handle-state-change :default (defmethod handle-state-change :default
[_ _ _] [_ _ _]

View file

@ -8,36 +8,59 @@
"RPC for plugins runtime." "RPC for plugins runtime."
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.record :as crc] [app.common.record :as crc]
[app.plugins.utils :as utils] [app.plugins.utils :as utils]
[app.util.object :as obj]
[cuerdas.core :as str])) [cuerdas.core :as str]))
(defn- fills (defn- make-fills
[shape] [fills]
;; TODO: Transform explicitly? ;; TODO: Transform explicitly?
(apply array (apply array
(->> (:fills shape) (->> fills
(map #(clj->js % {:keyword-fn (fn [k] (str/camel (name k)))}))))) (map #(clj->js % {:keyword-fn (fn [k] (str/camel (name k)))})))))
(deftype ShapeProxy (deftype ShapeProxy [_data]
[id Object
name (clone [_] (.log js/console (clj->js _data)))
type (delete [_] (.log js/console (clj->js _data)))
fills (appendChild [_] (.log js/console (clj->js _data))))
_data])
(crc/define-properties! (crc/define-properties!
ShapeProxy ShapeProxy
{:name js/Symbol.toStringTag {:name js/Symbol.toStringTag
:get (fn [] (str "ShapeProxy"))}) :get (fn [] (str "ShapeProxy"))})
(defn get-data
([this attr]
(-> this
(obj/get "_data")
(get attr)))
([this attr transform-fn]
(-> this
(get-data attr)
(transform-fn))))
(defn data->shape-proxy (defn data->shape-proxy
[data] [data]
(utils/hide-data!
(->ShapeProxy (dm/str (:id data)) (-> (->ShapeProxy data)
(:name data) (js/Object.defineProperties
(d/name (:type data)) #js {"_data" #js {:enumerable false}
(fills data)
data))) :id
#js {:get #(get-data (js* "this") :id str)
:enumerable true}
:name
#js {:get #(get-data (js* "this") :name)
;;:set (fn [] (prn "SET NAME"))
:enumerable true}
:fills
#js {:get #(get-data (js* "this") :fills make-fills)
;;:set (fn [] (prn "SET FILLS"))
:enumerable true}}
)))