mirror of
https://github.com/penpot/penpot.git
synced 2025-01-22 22:49:01 -05: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
|
||||
(:require-macros [uxbox.util.syntax :refer [define-once]])
|
||||
(:require [beicon.core :as rx]
|
||||
[cats.labs.lens :as l]
|
||||
[uxbox.rstore :as rs]
|
||||
|
@ -88,7 +89,7 @@
|
|||
(rx/buffer 2 1)
|
||||
(rx/map coords-delta)))
|
||||
|
||||
(defonce $$drag-subscription$$
|
||||
(define-once
|
||||
(as-> mouse-delta-s $
|
||||
(rx/filter #(deref shapes-dragging?) $)
|
||||
(rx/on-value $ (fn [delta]
|
||||
|
@ -113,7 +114,7 @@
|
|||
:width (- current-x start-x)
|
||||
:height (- current-y start-y)}))
|
||||
|
||||
(defonce $$selrect-subscription$$
|
||||
(define-once
|
||||
(let [ss (as-> (rx/from-atom selrect-dragging?) $
|
||||
(rx/dedupe $)
|
||||
(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
Reference in a new issue