mirror of
https://github.com/penpot/penpot.git
synced 2025-06-06 06:31:38 +02:00
Add syntax helper for define once unnamed global instances.
This commit is contained in:
parent
ee6399b10d
commit
c8a86b39d5
2 changed files with 13 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
||||||
(ns uxbox.ui.workspace.base
|
(ns uxbox.ui.workspace.base
|
||||||
|
(:require-macros [uxbox.util.syntax :refer [define-once]])
|
||||||
(:require [beicon.core :as rx]
|
(:require [beicon.core :as rx]
|
||||||
[cats.labs.lens :as l]
|
[cats.labs.lens :as l]
|
||||||
[uxbox.rstore :as rs]
|
[uxbox.rstore :as rs]
|
||||||
|
@ -88,7 +89,7 @@
|
||||||
(rx/buffer 2 1)
|
(rx/buffer 2 1)
|
||||||
(rx/map coords-delta)))
|
(rx/map coords-delta)))
|
||||||
|
|
||||||
(defonce $$drag-subscription$$
|
(define-once
|
||||||
(as-> mouse-delta-s $
|
(as-> mouse-delta-s $
|
||||||
(rx/filter #(deref shapes-dragging?) $)
|
(rx/filter #(deref shapes-dragging?) $)
|
||||||
(rx/on-value $ (fn [delta]
|
(rx/on-value $ (fn [delta]
|
||||||
|
@ -113,7 +114,7 @@
|
||||||
:width (- current-x start-x)
|
:width (- current-x start-x)
|
||||||
:height (- current-y start-y)}))
|
:height (- current-y start-y)}))
|
||||||
|
|
||||||
(defonce $$selrect-subscription$$
|
(define-once
|
||||||
(let [ss (as-> (rx/from-atom selrect-dragging?) $
|
(let [ss (as-> (rx/from-atom selrect-dragging?) $
|
||||||
(rx/dedupe $)
|
(rx/dedupe $)
|
||||||
(rx/merge $ (rx/of false))
|
(rx/merge $ (rx/of false))
|
||||||
|
|
10
frontend/uxbox/util/syntax.cljc
Normal file
10
frontend/uxbox/util/syntax.cljc
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
(ns uxbox.util.syntax
|
||||||
|
(:refer-clojure :exclude [defonce]))
|
||||||
|
|
||||||
|
(defmacro define-once
|
||||||
|
[& body]
|
||||||
|
(let [sym (gensym "uxbox-")]
|
||||||
|
`(cljs.core/defonce ~sym
|
||||||
|
(do ~@body
|
||||||
|
nil))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue