0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-22 14:39:45 -05:00

Add syntax helper for define once unnamed global instances.

This commit is contained in:
Andrey Antukh 2016-01-07 19:01:50 +02:00
parent ee6399b10d
commit c8a86b39d5
2 changed files with 13 additions and 2 deletions

View file

@ -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))

View 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))))