mirror of
https://github.com/penpot/penpot.git
synced 2025-06-10 23:03:31 +02:00
✨ Add verify
macro for true runtime spec asserts.
This commits mainly renames the old `assert` to `verify` and adds new `assert` that laverages `:elide-asserts` on clojurescript and *assert* value on clojure. This approach enables an assert macro that does not performs any runtime checks and compiles to more performant code in both cases: development mode and production mode.
This commit is contained in:
parent
391b926397
commit
8057fb54a6
14 changed files with 126 additions and 109 deletions
|
@ -35,8 +35,8 @@
|
||||||
"Schedule the email for sending."
|
"Schedule the email for sending."
|
||||||
([email context] (send! db/pool email context))
|
([email context] (send! db/pool email context))
|
||||||
([conn email context]
|
([conn email context]
|
||||||
(us/assert fn? email)
|
(us/verify fn? email)
|
||||||
(us/assert map? context)
|
(us/verify map? context)
|
||||||
(let [defaults {:from (:email-from cfg/config)
|
(let [defaults {:from (:email-from cfg/config)
|
||||||
:reply-to (:email-reply-to cfg/config)}
|
:reply-to (:email-reply-to cfg/config)}
|
||||||
data (->> (merge defaults context)
|
data (->> (merge defaults context)
|
||||||
|
|
|
@ -43,8 +43,8 @@
|
||||||
width 200
|
width 200
|
||||||
height 200}
|
height 200}
|
||||||
:as opts}]
|
:as opts}]
|
||||||
(us/assert ::thumbnail-opts opts)
|
(us/verify ::thumbnail-opts opts)
|
||||||
(us/assert fs/path? input)
|
(us/verify fs/path? input)
|
||||||
(let [tmp (fs/create-tempfile :suffix (str "." format))
|
(let [tmp (fs/create-tempfile :suffix (str "." format))
|
||||||
opr (doto (IMOperation.)
|
opr (doto (IMOperation.)
|
||||||
(.addImage)
|
(.addImage)
|
||||||
|
@ -60,7 +60,7 @@
|
||||||
|
|
||||||
(defn make-thumbnail
|
(defn make-thumbnail
|
||||||
[input {:keys [width height format quality] :as opts}]
|
[input {:keys [width height format quality] :as opts}]
|
||||||
(us/assert ::thumbnail-opts opts)
|
(us/verify ::thumbnail-opts opts)
|
||||||
(let [[filename ext] (fs/split-ext (fs/name input))
|
(let [[filename ext] (fs/split-ext (fs/name input))
|
||||||
suffix (->> [width height quality format]
|
suffix (->> [width height quality format]
|
||||||
(interpose ".")
|
(interpose ".")
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
(defn- delete-project
|
(defn- delete-project
|
||||||
"Clean deleted projects."
|
"Clean deleted projects."
|
||||||
[{:keys [id] :as props}]
|
[{:keys [id] :as props}]
|
||||||
(us/assert ::delete-project props)
|
(us/verify ::delete-project props)
|
||||||
(db/with-atomic [conn db/pool]
|
(db/with-atomic [conn db/pool]
|
||||||
(-> (db/query-one conn [sql:delete-project id])
|
(-> (db/query-one conn [sql:delete-project id])
|
||||||
(p/then (constantly nil)))))
|
(p/then (constantly nil)))))
|
||||||
|
|
|
@ -266,7 +266,7 @@
|
||||||
|
|
||||||
(defn schedule!
|
(defn schedule!
|
||||||
[conn {:keys [name delay props queue key] :as options}]
|
[conn {:keys [name delay props queue key] :as options}]
|
||||||
(us/assert ::task-options options)
|
(us/verify ::task-options options)
|
||||||
(let [queue (if (string? queue) queue "default")
|
(let [queue (if (string? queue) queue "default")
|
||||||
duration (-> (tm/duration delay)
|
duration (-> (tm/duration delay)
|
||||||
(duration->pginterval))
|
(duration->pginterval))
|
||||||
|
|
|
@ -90,7 +90,7 @@
|
||||||
([id extra-context]
|
([id extra-context]
|
||||||
(s/assert keyword? id)
|
(s/assert keyword? id)
|
||||||
(fn [context]
|
(fn [context]
|
||||||
(us/assert ::context context)
|
(us/verify ::context context)
|
||||||
(when-let [spec (s/get-spec id)]
|
(when-let [spec (s/get-spec id)]
|
||||||
(s/assert spec context))
|
(s/assert spec context))
|
||||||
|
|
||||||
|
|
|
@ -110,15 +110,20 @@
|
||||||
|
|
||||||
;; --- Macros
|
;; --- Macros
|
||||||
|
|
||||||
(defn assert*
|
(defn spec-assert
|
||||||
[spec x]
|
[spec x]
|
||||||
(s/assert* spec x))
|
(s/assert* spec x))
|
||||||
|
|
||||||
#?(:clj
|
(defmacro assert
|
||||||
(defmacro assert
|
|
||||||
"Always active assertion macro (does not obey to :elide-asserts)"
|
"Always active assertion macro (does not obey to :elide-asserts)"
|
||||||
[spec x]
|
[spec x]
|
||||||
`(assert* ~spec ~x)))
|
(when *assert*
|
||||||
|
`(spec-assert ~spec ~x)))
|
||||||
|
|
||||||
|
(defmacro verify
|
||||||
|
"Always active assertion macro (does not obey to :elide-asserts)"
|
||||||
|
[spec x]
|
||||||
|
`(spec-assert ~spec ~x))
|
||||||
|
|
||||||
;; --- Public Api
|
;; --- Public Api
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
|
|
||||||
(defn login
|
(defn login
|
||||||
[{:keys [username password] :as data}]
|
[{:keys [username password] :as data}]
|
||||||
(us/assert ::login-params data)
|
(us/verify ::login-params data)
|
||||||
(ptk/reify ::login
|
(ptk/reify ::login
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -119,8 +119,8 @@
|
||||||
|
|
||||||
(defn request-profile-recovery
|
(defn request-profile-recovery
|
||||||
[data on-success]
|
[data on-success]
|
||||||
(us/assert ::recovery-request data)
|
(us/verify ::recovery-request data)
|
||||||
(us/assert fn? on-success)
|
(us/verify fn? on-success)
|
||||||
(ptk/reify ::request-profile-recovery
|
(ptk/reify ::request-profile-recovery
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
@ -141,7 +141,7 @@
|
||||||
|
|
||||||
(defn recover-profile
|
(defn recover-profile
|
||||||
[{:keys [token password on-error on-success] :as data}]
|
[{:keys [token password on-error on-success] :as data}]
|
||||||
(us/assert ::recover-profile data)
|
(us/verify ::recover-profile data)
|
||||||
(ptk/reify ::recover-profile
|
(ptk/reify ::recover-profile
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
|
|
||||||
(defn initialize
|
(defn initialize
|
||||||
[id]
|
[id]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(ptk/reify ::initialize
|
(ptk/reify ::initialize
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -71,7 +71,7 @@
|
||||||
|
|
||||||
(defn watch-page-changes
|
(defn watch-page-changes
|
||||||
[id]
|
[id]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(reify
|
(reify
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
@ -87,7 +87,7 @@
|
||||||
|
|
||||||
(defn pinned-history-fetched
|
(defn pinned-history-fetched
|
||||||
[items]
|
[items]
|
||||||
(us/assert ::history-entries items)
|
(us/verify ::history-entries items)
|
||||||
(ptk/reify ::pinned-history-fetched
|
(ptk/reify ::pinned-history-fetched
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -104,7 +104,7 @@
|
||||||
|
|
||||||
(defn fetch-pinned-history
|
(defn fetch-pinned-history
|
||||||
[id]
|
[id]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(ptk/reify ::fetch-pinned-history
|
(ptk/reify ::fetch-pinned-history
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state s]
|
(watch [_ state s]
|
||||||
|
@ -117,7 +117,7 @@
|
||||||
|
|
||||||
(defn history-fetched
|
(defn history-fetched
|
||||||
[items]
|
[items]
|
||||||
(us/assert ::history-entries items)
|
(us/verify ::history-entries items)
|
||||||
(ptk/reify ::history-fetched
|
(ptk/reify ::history-fetched
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -140,7 +140,7 @@
|
||||||
([id]
|
([id]
|
||||||
(fetch-history id nil))
|
(fetch-history id nil))
|
||||||
([id {:keys [since max]}]
|
([id {:keys [since max]}]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(ptk/reify ::fetch-history
|
(ptk/reify ::fetch-history
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state s]
|
(watch [_ state s]
|
||||||
|
@ -182,7 +182,7 @@
|
||||||
|
|
||||||
(defn select
|
(defn select
|
||||||
[version]
|
[version]
|
||||||
(us/assert int? version)
|
(us/verify int? version)
|
||||||
(ptk/reify ::select
|
(ptk/reify ::select
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -238,7 +238,7 @@
|
||||||
|
|
||||||
(defn history-updated
|
(defn history-updated
|
||||||
[item]
|
[item]
|
||||||
(us/assert ::history-entry item)
|
(us/verify ::history-entry item)
|
||||||
(ptk/reify ::history-item-updated
|
(ptk/reify ::history-item-updated
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
|
|
||||||
(defn collections-fetched
|
(defn collections-fetched
|
||||||
[items]
|
[items]
|
||||||
(us/assert (s/every ::collection-entity) items)
|
(us/verify (s/every ::collection-entity) items)
|
||||||
(ptk/reify ::collections-fetched
|
(ptk/reify ::collections-fetched
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -83,7 +83,7 @@
|
||||||
|
|
||||||
(defn collection-created
|
(defn collection-created
|
||||||
[item]
|
[item]
|
||||||
(us/assert ::collection-entity item)
|
(us/verify ::collection-entity item)
|
||||||
(ptk/reify ::collection-created
|
(ptk/reify ::collection-created
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -109,7 +109,7 @@
|
||||||
|
|
||||||
(defn collection-updated
|
(defn collection-updated
|
||||||
[item]
|
[item]
|
||||||
(us/assert ::collection-entity item)
|
(us/verify ::collection-entity item)
|
||||||
(CollectionUpdated. item))
|
(CollectionUpdated. item))
|
||||||
|
|
||||||
;; --- Update Collection
|
;; --- Update Collection
|
||||||
|
@ -161,7 +161,7 @@
|
||||||
|
|
||||||
(defn image-created
|
(defn image-created
|
||||||
[item]
|
[item]
|
||||||
(us/assert ::image-entity item)
|
(us/verify ::image-entity item)
|
||||||
(ptk/reify ::image-created
|
(ptk/reify ::image-created
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -174,8 +174,8 @@
|
||||||
(defn create-images
|
(defn create-images
|
||||||
([id files] (create-images id files identity))
|
([id files] (create-images id files identity))
|
||||||
([id files on-uploaded]
|
([id files on-uploaded]
|
||||||
(us/assert (s/nilable ::us/uuid) id)
|
(us/verify (s/nilable ::us/uuid) id)
|
||||||
(us/assert fn? on-uploaded)
|
(us/verify fn? on-uploaded)
|
||||||
(ptk/reify ::create-images
|
(ptk/reify ::create-images
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -225,7 +225,7 @@
|
||||||
|
|
||||||
(defn images-fetched
|
(defn images-fetched
|
||||||
[items]
|
[items]
|
||||||
(us/assert (s/every ::image-entity) items)
|
(us/verify (s/every ::image-entity) items)
|
||||||
(ptk/reify ::images-fetched
|
(ptk/reify ::images-fetched
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -239,7 +239,7 @@
|
||||||
(defn fetch-images
|
(defn fetch-images
|
||||||
"Fetch a list of images of the selected collection"
|
"Fetch a list of images of the selected collection"
|
||||||
[id]
|
[id]
|
||||||
(us/assert (s/nilable ::us/uuid) id)
|
(us/verify (s/nilable ::us/uuid) id)
|
||||||
(ptk/reify ::fetch-images
|
(ptk/reify ::fetch-images
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state s]
|
(watch [_ state s]
|
||||||
|
|
|
@ -134,7 +134,7 @@
|
||||||
|
|
||||||
(defn projects-fetched
|
(defn projects-fetched
|
||||||
[projects]
|
[projects]
|
||||||
(us/assert (s/every ::project) projects)
|
(us/verify (s/every ::project) projects)
|
||||||
(ptk/reify ::projects-fetched
|
(ptk/reify ::projects-fetched
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -158,7 +158,7 @@
|
||||||
|
|
||||||
(defn fetch-file
|
(defn fetch-file
|
||||||
[id]
|
[id]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(ptk/reify ::fetch-file
|
(ptk/reify ::fetch-file
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
@ -169,7 +169,7 @@
|
||||||
|
|
||||||
(defn files-fetched
|
(defn files-fetched
|
||||||
[files]
|
[files]
|
||||||
(us/assert (s/every ::file) files)
|
(us/verify (s/every ::file) files)
|
||||||
(ptk/reify ::files-fetched
|
(ptk/reify ::files-fetched
|
||||||
cljs.core/IDeref
|
cljs.core/IDeref
|
||||||
(-deref [_] files)
|
(-deref [_] files)
|
||||||
|
@ -227,7 +227,7 @@
|
||||||
|
|
||||||
(defn delete-project
|
(defn delete-project
|
||||||
[id]
|
[id]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(ptk/reify ::delete-project
|
(ptk/reify ::delete-project
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -242,7 +242,7 @@
|
||||||
|
|
||||||
(defn delete-file
|
(defn delete-file
|
||||||
[id]
|
[id]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(ptk/reify ::delete-file
|
(ptk/reify ::delete-file
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -273,7 +273,7 @@
|
||||||
|
|
||||||
(defn go-to
|
(defn go-to
|
||||||
[file-id]
|
[file-id]
|
||||||
(us/assert ::us/uuid file-id)
|
(us/verify ::us/uuid file-id)
|
||||||
(ptk/reify ::go-to
|
(ptk/reify ::go-to
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
@ -284,7 +284,7 @@
|
||||||
|
|
||||||
(defn go-to-project
|
(defn go-to-project
|
||||||
[id]
|
[id]
|
||||||
(us/assert (s/nilable ::us/uuid) id)
|
(us/verify (s/nilable ::us/uuid) id)
|
||||||
(ptk/reify ::go-to-project
|
(ptk/reify ::go-to-project
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
@ -299,7 +299,7 @@
|
||||||
|
|
||||||
(defn fetch-pages
|
(defn fetch-pages
|
||||||
[file-id]
|
[file-id]
|
||||||
(us/assert ::us/uuid file-id)
|
(us/verify ::us/uuid file-id)
|
||||||
(reify
|
(reify
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state s]
|
(watch [_ state s]
|
||||||
|
@ -310,7 +310,7 @@
|
||||||
|
|
||||||
(defn pages-fetched
|
(defn pages-fetched
|
||||||
[pages]
|
[pages]
|
||||||
(us/assert (s/every ::page) pages)
|
(us/verify (s/every ::page) pages)
|
||||||
(ptk/reify ::pages-fetched
|
(ptk/reify ::pages-fetched
|
||||||
IDeref
|
IDeref
|
||||||
(-deref [_] pages)
|
(-deref [_] pages)
|
||||||
|
@ -326,7 +326,7 @@
|
||||||
(defn fetch-page
|
(defn fetch-page
|
||||||
"Fetch page by id."
|
"Fetch page by id."
|
||||||
[id]
|
[id]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(reify
|
(reify
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state s]
|
(watch [_ state s]
|
||||||
|
@ -337,7 +337,7 @@
|
||||||
|
|
||||||
(defn page-fetched
|
(defn page-fetched
|
||||||
[data]
|
[data]
|
||||||
(us/assert ::page data)
|
(us/verify ::page data)
|
||||||
(ptk/reify ::page-fetched
|
(ptk/reify ::page-fetched
|
||||||
IDeref
|
IDeref
|
||||||
(-deref [_] data)
|
(-deref [_] data)
|
||||||
|
@ -368,7 +368,7 @@
|
||||||
|
|
||||||
(defn page-created
|
(defn page-created
|
||||||
[{:keys [id file-id] :as page}]
|
[{:keys [id file-id] :as page}]
|
||||||
(us/assert ::page page)
|
(us/verify ::page page)
|
||||||
(ptk/reify ::page-created
|
(ptk/reify ::page-created
|
||||||
cljs.core/IDeref
|
cljs.core/IDeref
|
||||||
(-deref [_] page)
|
(-deref [_] page)
|
||||||
|
@ -393,8 +393,8 @@
|
||||||
|
|
||||||
(defn rename-page
|
(defn rename-page
|
||||||
[id name]
|
[id name]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(us/assert string? name)
|
(us/verify string? name)
|
||||||
(ptk/reify ::rename-page
|
(ptk/reify ::rename-page
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -452,7 +452,7 @@
|
||||||
|
|
||||||
(defn page-persisted
|
(defn page-persisted
|
||||||
[{:keys [id] :as page}]
|
[{:keys [id] :as page}]
|
||||||
(us/assert ::page page)
|
(us/verify ::page page)
|
||||||
(ptk/reify ::page-persisted
|
(ptk/reify ::page-persisted
|
||||||
cljs.core/IDeref
|
cljs.core/IDeref
|
||||||
(-deref [_] page)
|
(-deref [_] page)
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
(defn watch-page-changes
|
(defn watch-page-changes
|
||||||
[id]
|
[id]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(ptk/reify ::watch-page-changes
|
(ptk/reify ::watch-page-changes
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
|
|
||||||
(defn save-undo-entry
|
(defn save-undo-entry
|
||||||
[id]
|
[id]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(letfn [(cons-entry [stack entry]
|
(letfn [(cons-entry [stack entry]
|
||||||
(let [stack (cons entry stack)]
|
(let [stack (cons entry stack)]
|
||||||
(if (> (count stack) MAX-STACK-SIZE)
|
(if (> (count stack) MAX-STACK-SIZE)
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
|
|
||||||
(defn profile-fetched
|
(defn profile-fetched
|
||||||
[data]
|
[data]
|
||||||
(us/assert ::profile-fetched data)
|
(us/verify ::profile-fetched data)
|
||||||
(ptk/reify ::profile-fetched
|
(ptk/reify ::profile-fetched
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -73,9 +73,9 @@
|
||||||
|
|
||||||
(defn form->update-profile
|
(defn form->update-profile
|
||||||
[data on-success on-error]
|
[data on-success on-error]
|
||||||
(us/assert ::update-profile-params data)
|
(us/verify ::update-profile-params data)
|
||||||
(us/assert fn? on-error)
|
(us/verify fn? on-error)
|
||||||
(us/assert fn? on-success)
|
(us/verify fn? on-success)
|
||||||
(reify
|
(reify
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state s]
|
(watch [_ state s]
|
||||||
|
@ -102,9 +102,9 @@
|
||||||
|
|
||||||
(defn update-password
|
(defn update-password
|
||||||
[data {:keys [on-success on-error]}]
|
[data {:keys [on-success on-error]}]
|
||||||
(us/assert ::update-password-params data)
|
(us/verify ::update-password-params data)
|
||||||
(us/assert fn? on-success)
|
(us/verify fn? on-success)
|
||||||
(us/assert fn? on-error)
|
(us/verify fn? on-error)
|
||||||
(reify
|
(reify
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state s]
|
(watch [_ state s]
|
||||||
|
@ -132,6 +132,6 @@
|
||||||
(defn update-photo
|
(defn update-photo
|
||||||
([file] (update-photo file (constantly nil)))
|
([file] (update-photo file (constantly nil)))
|
||||||
([file done]
|
([file done]
|
||||||
(us/assert ::file file)
|
(us/verify ::file file)
|
||||||
(us/assert fn? done)
|
(us/verify fn? done)
|
||||||
(UpdatePhoto. file done)))
|
(UpdatePhoto. file done)))
|
||||||
|
|
|
@ -127,7 +127,7 @@
|
||||||
|
|
||||||
(defn handle-who
|
(defn handle-who
|
||||||
[{:keys [users] :as msg}]
|
[{:keys [users] :as msg}]
|
||||||
(us/assert set? users)
|
(us/verify set? users)
|
||||||
(ptk/reify ::handle-who
|
(ptk/reify ::handle-who
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -279,8 +279,8 @@
|
||||||
(defn initialize
|
(defn initialize
|
||||||
"Initialize the workspace state."
|
"Initialize the workspace state."
|
||||||
[file-id page-id]
|
[file-id page-id]
|
||||||
(us/assert ::us/uuid file-id)
|
(us/verify ::us/uuid file-id)
|
||||||
(us/assert ::us/uuid page-id)
|
(us/verify ::us/uuid page-id)
|
||||||
(ptk/reify ::initialize
|
(ptk/reify ::initialize
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
@ -303,7 +303,7 @@
|
||||||
|
|
||||||
(defn- initialize-layout
|
(defn- initialize-layout
|
||||||
[file-id]
|
[file-id]
|
||||||
(us/assert ::us/uuid file-id)
|
(us/verify ::us/uuid file-id)
|
||||||
(ptk/reify ::initialize-layout
|
(ptk/reify ::initialize-layout
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -311,7 +311,7 @@
|
||||||
|
|
||||||
(defn- initialize-file
|
(defn- initialize-file
|
||||||
[file-id]
|
[file-id]
|
||||||
(us/assert ::us/uuid file-id)
|
(us/verify ::us/uuid file-id)
|
||||||
(ptk/reify ::initialize-file
|
(ptk/reify ::initialize-file
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -345,8 +345,8 @@
|
||||||
|
|
||||||
(defn finalize
|
(defn finalize
|
||||||
[file-id page-id]
|
[file-id page-id]
|
||||||
(us/assert ::us/uuid file-id)
|
(us/verify ::us/uuid file-id)
|
||||||
(us/assert ::us/uuid page-id)
|
(us/verify ::us/uuid page-id)
|
||||||
(ptk/reify ::finalize
|
(ptk/reify ::finalize
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -404,7 +404,7 @@
|
||||||
|
|
||||||
(defn toggle-layout-flag
|
(defn toggle-layout-flag
|
||||||
[flag]
|
[flag]
|
||||||
(us/assert keyword? flag)
|
(us/verify keyword? flag)
|
||||||
(ptk/reify ::toggle-layout-flag
|
(ptk/reify ::toggle-layout-flag
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -418,7 +418,7 @@
|
||||||
|
|
||||||
(defn activate-flag
|
(defn activate-flag
|
||||||
[flag]
|
[flag]
|
||||||
(us/assert keyword? flag)
|
(us/verify keyword? flag)
|
||||||
(ptk/reify ::activate-flag
|
(ptk/reify ::activate-flag
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -430,7 +430,7 @@
|
||||||
|
|
||||||
(defn deactivate-flag
|
(defn deactivate-flag
|
||||||
[flag]
|
[flag]
|
||||||
(us/assert keyword? flag)
|
(us/verify keyword? flag)
|
||||||
(ptk/reify ::deactivate-flag
|
(ptk/reify ::deactivate-flag
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -438,7 +438,7 @@
|
||||||
|
|
||||||
(defn toggle-flag
|
(defn toggle-flag
|
||||||
[flag]
|
[flag]
|
||||||
(us/assert keyword? flag)
|
(us/verify keyword? flag)
|
||||||
(ptk/reify ::toggle-flag
|
(ptk/reify ::toggle-flag
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
@ -559,7 +559,7 @@
|
||||||
|
|
||||||
;; (defn initialize-alignment
|
;; (defn initialize-alignment
|
||||||
;; [id]
|
;; [id]
|
||||||
;; (us/assert ::us/uuid id)
|
;; (us/verify ::us/uuid id)
|
||||||
;; (ptk/reify ::initialize-alignment
|
;; (ptk/reify ::initialize-alignment
|
||||||
;; ptk/WatchEvent
|
;; ptk/WatchEvent
|
||||||
;; (watch [_ state stream]
|
;; (watch [_ state stream]
|
||||||
|
@ -617,7 +617,7 @@
|
||||||
|
|
||||||
(defn add-shape
|
(defn add-shape
|
||||||
[data]
|
[data]
|
||||||
(us/assert ::shape-attrs data)
|
(us/verify ::shape-attrs data)
|
||||||
(let [id (uuid/next)]
|
(let [id (uuid/next)]
|
||||||
(ptk/reify ::add-shape
|
(ptk/reify ::add-shape
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
|
@ -646,7 +646,7 @@
|
||||||
|
|
||||||
(defn add-canvas
|
(defn add-canvas
|
||||||
[data]
|
[data]
|
||||||
(us/assert ::shape-attrs data)
|
(us/verify ::shape-attrs data)
|
||||||
(let [id (uuid/next)]
|
(let [id (uuid/next)]
|
||||||
(ptk/reify ::add-canvas
|
(ptk/reify ::add-canvas
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
|
@ -695,7 +695,7 @@
|
||||||
|
|
||||||
(defn select-shape
|
(defn select-shape
|
||||||
[id]
|
[id]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(ptk/reify ::select-shape
|
(ptk/reify ::select-shape
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -755,8 +755,8 @@
|
||||||
|
|
||||||
(defn update-shape
|
(defn update-shape
|
||||||
[id attrs]
|
[id attrs]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(us/assert ::shape-attrs attrs)
|
(us/verify ::shape-attrs attrs)
|
||||||
(ptk/reify ::update-shape
|
(ptk/reify ::update-shape
|
||||||
IBatchedChange
|
IBatchedChange
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
|
@ -767,7 +767,7 @@
|
||||||
|
|
||||||
(defn update-options
|
(defn update-options
|
||||||
[opts]
|
[opts]
|
||||||
(us/assert ::cp/options opts)
|
(us/verify ::cp/options opts)
|
||||||
(ptk/reify ::update-options
|
(ptk/reify ::update-options
|
||||||
IBatchedChange
|
IBatchedChange
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
|
@ -778,7 +778,7 @@
|
||||||
|
|
||||||
(defn update-selected-shapes
|
(defn update-selected-shapes
|
||||||
[attrs]
|
[attrs]
|
||||||
(s/assert ::shape-attrs attrs)
|
(us/verify ::shape-attrs attrs)
|
||||||
(ptk/reify ::update-selected-shapes
|
(ptk/reify ::update-selected-shapes
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
@ -819,8 +819,8 @@
|
||||||
|
|
||||||
(defn move-selected
|
(defn move-selected
|
||||||
[direction align?]
|
[direction align?]
|
||||||
(us/assert ::direction direction)
|
(us/verify ::direction direction)
|
||||||
(us/assert boolean? align?)
|
(us/verify boolean? align?)
|
||||||
|
|
||||||
(ptk/reify ::move-selected
|
(ptk/reify ::move-selected
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
|
@ -872,8 +872,8 @@
|
||||||
|
|
||||||
(defn rename-shape
|
(defn rename-shape
|
||||||
[id name]
|
[id name]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(us/assert string? name)
|
(us/verify string? name)
|
||||||
(ptk/reify ::rename-shape
|
(ptk/reify ::rename-shape
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -894,7 +894,7 @@
|
||||||
|
|
||||||
(defn order-selected-shapes
|
(defn order-selected-shapes
|
||||||
[loc]
|
[loc]
|
||||||
(us/assert ::direction loc)
|
(us/verify ::direction loc)
|
||||||
(ptk/reify ::move-selected-layer
|
(ptk/reify ::move-selected-layer
|
||||||
IBatchedChange
|
IBatchedChange
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
|
@ -924,8 +924,8 @@
|
||||||
|
|
||||||
(defn temporal-shape-order-change
|
(defn temporal-shape-order-change
|
||||||
[id index]
|
[id index]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(us/assert number? index)
|
(us/verify number? index)
|
||||||
(ptk/reify ::change-shape-order
|
(ptk/reify ::change-shape-order
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -953,8 +953,8 @@
|
||||||
|
|
||||||
(defn change-canvas-order
|
(defn change-canvas-order
|
||||||
[{:keys [id index] :as params}]
|
[{:keys [id index] :as params}]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(us/assert ::us/number index)
|
(us/verify ::us/number index)
|
||||||
(ptk/reify ::change-canvas-order
|
(ptk/reify ::change-canvas-order
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -969,7 +969,7 @@
|
||||||
(defn initial-selection-align
|
(defn initial-selection-align
|
||||||
"Align the selection of shapes."
|
"Align the selection of shapes."
|
||||||
[ids]
|
[ids]
|
||||||
(us/assert ::set-of-uuid ids)
|
(us/verify ::set-of-uuid ids)
|
||||||
(ptk/reify ::initialize-shapes-align-in-bulk
|
(ptk/reify ::initialize-shapes-align-in-bulk
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
@ -986,8 +986,8 @@
|
||||||
|
|
||||||
(defn assoc-temporal-modifier-in-bulk
|
(defn assoc-temporal-modifier-in-bulk
|
||||||
[ids xfmt]
|
[ids xfmt]
|
||||||
(us/assert ::set-of-uuid ids)
|
(us/verify ::set-of-uuid ids)
|
||||||
(us/assert gmt/matrix? xfmt)
|
(us/verify gmt/matrix? xfmt)
|
||||||
(ptk/reify ::assoc-temporal-modifier-in-bulk
|
(ptk/reify ::assoc-temporal-modifier-in-bulk
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -997,8 +997,8 @@
|
||||||
"Apply the same displacement delta to all shapes identified by the
|
"Apply the same displacement delta to all shapes identified by the
|
||||||
set if ids."
|
set if ids."
|
||||||
[ids delta]
|
[ids delta]
|
||||||
(us/assert ::set-of-uuid ids)
|
(us/verify ::set-of-uuid ids)
|
||||||
(us/assert gpt/point? delta)
|
(us/verify gpt/point? delta)
|
||||||
(letfn [(process-shape [state id]
|
(letfn [(process-shape [state id]
|
||||||
(let [prev (get-in state [:workspace-data :shapes-by-id id :modifier-mtx] (gmt/matrix))
|
(let [prev (get-in state [:workspace-data :shapes-by-id id :modifier-mtx] (gmt/matrix))
|
||||||
xfmt (gmt/translate prev delta)]
|
xfmt (gmt/translate prev delta)]
|
||||||
|
@ -1038,7 +1038,7 @@
|
||||||
|
|
||||||
(defn commit-changes
|
(defn commit-changes
|
||||||
[changes]
|
[changes]
|
||||||
(us/assert ::cp/changes changes)
|
(us/verify ::cp/changes changes)
|
||||||
(ptk/reify ::commit-changes
|
(ptk/reify ::commit-changes
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -1060,7 +1060,7 @@
|
||||||
|
|
||||||
(defn shapes-changes-commited
|
(defn shapes-changes-commited
|
||||||
[{:keys [page-id version changes] :as params}]
|
[{:keys [page-id version changes] :as params}]
|
||||||
(us/assert ::shapes-changes-commited params)
|
(us/verify ::shapes-changes-commited params)
|
||||||
(ptk/reify ::shapes-changes-commited
|
(ptk/reify ::shapes-changes-commited
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -1126,14 +1126,26 @@
|
||||||
of the shape using the width and height attrs
|
of the shape using the width and height attrs
|
||||||
instread final point of coordinates."
|
instread final point of coordinates."
|
||||||
[id dimensions]
|
[id dimensions]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(us/assert ::update-dimensions dimensions)
|
(us/verify ::update-dimensions dimensions)
|
||||||
(ptk/reify ::update-dimensions
|
(ptk/reify ::update-dimensions
|
||||||
IBatchedChange
|
IBatchedChange
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(update-in state [:workspace-data :shapes-by-id id] geom/resize-dim dimensions))))
|
(update-in state [:workspace-data :shapes-by-id id] geom/resize-dim dimensions))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn update-rect-dimensions
|
||||||
|
[id attr value]
|
||||||
|
(us/verify ::us/uuid id)
|
||||||
|
(us/verify #{:width :height} attr)
|
||||||
|
(us/verify ::us/number value)
|
||||||
|
(ptk/reify ::update-rect-dimensions
|
||||||
|
IBatchedChange
|
||||||
|
ptk/UpdateEvent
|
||||||
|
(update [_ state]
|
||||||
|
(update-in state [:workspace-data :shapes-by-id id] geom/resize-rect attr value))))
|
||||||
|
|
||||||
;; --- Shape Proportions
|
;; --- Shape Proportions
|
||||||
|
|
||||||
(defn toggle-shape-proportion-lock
|
(defn toggle-shape-proportion-lock
|
||||||
|
@ -1156,8 +1168,8 @@
|
||||||
|
|
||||||
(defn update-position
|
(defn update-position
|
||||||
[id position]
|
[id position]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(us/assert ::position position)
|
(us/verify ::position position)
|
||||||
(ptk/reify ::update-position
|
(ptk/reify ::update-position
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -1169,9 +1181,9 @@
|
||||||
(defn update-path
|
(defn update-path
|
||||||
"Update a concrete point in the path shape."
|
"Update a concrete point in the path shape."
|
||||||
[id index delta]
|
[id index delta]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(us/assert ::us/integer index)
|
(us/verify ::us/integer index)
|
||||||
(us/assert gpt/point? delta)
|
(us/verify gpt/point? delta)
|
||||||
(ptk/reify ::update-path
|
(ptk/reify ::update-path
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -1203,7 +1215,7 @@
|
||||||
|
|
||||||
(defn hide-shape
|
(defn hide-shape
|
||||||
[id]
|
[id]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(ptk/reify ::hide-shape
|
(ptk/reify ::hide-shape
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -1211,7 +1223,7 @@
|
||||||
|
|
||||||
(defn show-shape
|
(defn show-shape
|
||||||
[id]
|
[id]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(ptk/reify ::hide-shape
|
(ptk/reify ::hide-shape
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -1237,7 +1249,7 @@
|
||||||
|
|
||||||
(defn block-shape
|
(defn block-shape
|
||||||
[id]
|
[id]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(ptk/reify ::hide-shape
|
(ptk/reify ::hide-shape
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -1245,7 +1257,7 @@
|
||||||
|
|
||||||
(defn unblock-shape
|
(defn unblock-shape
|
||||||
[id]
|
[id]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(ptk/reify ::hide-shape
|
(ptk/reify ::hide-shape
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -1271,7 +1283,7 @@
|
||||||
|
|
||||||
(defn select-canvas
|
(defn select-canvas
|
||||||
[id]
|
[id]
|
||||||
(us/assert ::us/uuid id)
|
(us/verify ::us/uuid id)
|
||||||
(ptk/reify ::select-canvas
|
(ptk/reify ::select-canvas
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
|
@ -1292,7 +1304,7 @@
|
||||||
|
|
||||||
(defn go-to-page
|
(defn go-to-page
|
||||||
[page-id]
|
[page-id]
|
||||||
(us/assert ::us/uuid page-id)
|
(us/verify ::us/uuid page-id)
|
||||||
(ptk/reify ::go-to
|
(ptk/reify ::go-to
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
|
|
|
@ -36,6 +36,6 @@
|
||||||
|
|
||||||
(defn initialize-alignment
|
(defn initialize-alignment
|
||||||
[params]
|
[params]
|
||||||
(us/assert ::initialize-alignment-params params)
|
(us/verify ::initialize-alignment-params params)
|
||||||
(let [message (assoc params :cmd :grid-init)]
|
(let [message (assoc params :cmd :grid-init)]
|
||||||
(uw/send! worker message)))
|
(uw/send! worker message)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue