Make components lazy by default.

This commit is contained in:
Andrey Antukh 2017-04-08 14:00:49 +02:00
parent c65e13a31f
commit 491d91b1ee
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
2 changed files with 11 additions and 3 deletions

View file

@ -2,7 +2,7 @@
;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;; ;;
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz> ;; Copyright (c) 2016-2017 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.util.mixins (ns uxbox.util.mixins
(:require [rum.core :as rum] (:require [rum.core :as rum]
@ -43,9 +43,11 @@
(defmacro defc (defmacro defc
[& args] [& args]
(let [[render doc mixins cname] (parse-defc args)] (let [[render doc mixins cname] (parse-defc args)]
`(def ~cname ~doc (rum/build-defc ~render ~mixins ~(str cname))))) `(def ~cname ~doc (uxbox.util.mixins/lazy-component rum/build-defc ~render ~mixins ~(str cname)))))
(defmacro defcs (defmacro defcs
[& args] [& args]
(let [[render doc mixins cname] (parse-defc args)] (let [[render doc mixins cname] (parse-defc args)]
`(def ~cname ~doc (rum/build-defcs ~render ~mixins ~(str cname))))) `(def ~cname ~doc (uxbox.util.mixins/lazy-component rum/build-defcs ~render ~mixins ~(str cname)))))

View file

@ -42,6 +42,12 @@
([initial key] ([initial key]
(rum/local initial key))) (rum/local initial key)))
(defn lazy-component
[builder render mixins display-name]
(let [ctor (delay (builder render mixins display-name))]
(fn [& args]
(apply @ctor args))))
(def mount rum/mount) (def mount rum/mount)
(def static rum/static) (def static rum/static)
(def ref-node rum/ref-node) (def ref-node rum/ref-node)