Remove all usage of mx/component and replace that with rumext.

This commit is contained in:
Andrey Antukh 2017-04-08 18:30:03 +02:00
parent 491d91b1ee
commit 671c2d912c
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
78 changed files with 328 additions and 503 deletions

View file

@ -10,7 +10,7 @@
[lentes.core :as l]
[beicon.core :as rx]
[potok.core :as ptk]
[uxbox.util.mixins :as mx :include-macros true]
[rumext.core :as mx :include-macros true]
[uxbox.util.i18n :refer [tr]]))
;; --- Form Validation Api

View file

@ -12,7 +12,7 @@
[potok.core :as ptk]
[uxbox.builtins.icons :as i]
[uxbox.util.timers :as ts]
[uxbox.util.mixins :as mx :include-macros true]
[rumext.core :as mx :include-macros true]
[uxbox.util.data :refer [classnames]]
[uxbox.util.dom :as dom]))

View file

@ -1,53 +0,0 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; 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/.
;;
;; Copyright (c) 2016-2017 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.util.mixins
(:require [rum.core :as rum]
[sablono.compiler :as s]))
(defn- parse-defc
[args]
(loop [r {}
s 0
v (first args)
n (rest args)]
(case s
0 (if (symbol? v)
(recur (assoc r :name v) (inc s) (first n) (rest n))
(throw (ex-info "Invalid" {})))
1 (if (string? v)
(recur (assoc r :doc v) (inc s) (first n) (rest n))
(recur r (inc s) v n))
2 (if (map? v)
(if-let [mixins (:mixins v)]
(let [spec (dissoc v :mixins)
mixins (if (empty? spec)
mixins
(conj mixins spec))]
(recur (assoc r :mixins mixins) (inc s) (first n) (rest n)))
(recur (assoc r :mixins [v]) (inc s) (first n) (rest n)))
(recur r (inc s) v n))
3 (if (vector? v)
(recur (assoc r :args v) (inc s) (first n) (rest n))
(throw (ex-info "Invalid" {})))
4 (let [sym (:name r)
args (:args r)
func (if (map? v)
`(fn ~args ~v ~(s/compile-html `(do ~@n)))
`(fn ~args ~(s/compile-html `(do ~@(cons v n)))))]
[func (:doc r) (:mixins r) sym]))))
(defmacro defc
[& args]
(let [[render doc mixins cname] (parse-defc args)]
`(def ~cname ~doc (uxbox.util.mixins/lazy-component rum/build-defc ~render ~mixins ~(str cname)))))
(defmacro defcs
[& args]
(let [[render doc mixins cname] (parse-defc args)]
`(def ~cname ~doc (uxbox.util.mixins/lazy-component rum/build-defcs ~render ~mixins ~(str cname)))))

View file

@ -1,59 +0,0 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; 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/.
;;
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.util.mixins
(:refer-clojure :exclude [concat])
(:require [sablono.core :refer-macros [html]]
[sablono.server :as server]
[rum.core :as rum]
[lentes.core :as l]
[goog.dom.forms :as gforms]))
(extend-type cljs.core.UUID
INamed
(-name [this] (str this))
(-namespace [_] ""))
(defn component
[{:keys [render] :as spec}]
{:pre [(ifn? render)]}
(let [name (or (:name spec) (str (gensym "rum-")))
mixins (or (:mixins spec) [])
spec (dissoc spec :name :mixins :render)
render' (fn [state]
[(apply render state (:rum/args state)) state])
mixins (conj mixins spec)]
(rum/build-ctor render' mixins name)))
(defn concat
[& elements]
(html
(for [[i element] (map-indexed vector elements)]
(rum/with-key element (str i)))))
(defn local
([]
(rum/local {} :rum/local))
([initial]
(rum/local initial :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 static rum/static)
(def ref-node rum/ref-node)
(def dom-node rum/dom-node)
(def react rum/react)
(def reactive rum/reactive)
(def with-key rum/with-key)
(def render-html server/render)
(def render-static-html server/render-static)