Builds client SSR approach, sunsets old cljs.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
(:require [auto-ap.ssr.utils :refer [path->name2]]
|
||||
[auto-ap.cursor :as cursor]))
|
||||
|
||||
(def ^:dynamic *prefix* [])
|
||||
(def ^:dynamic *prefix* [])
|
||||
(def ^:dynamic *form-data*)
|
||||
(def ^:dynamic *form-errors*)
|
||||
(def ^:dynamic *prev-cursor* nil)
|
||||
@@ -22,18 +22,30 @@
|
||||
`(binding [*prefix* ~prefix]
|
||||
(start-form ~form-data ~errors ~@rest)))
|
||||
|
||||
(defmacro with-prefix [prefix & rest]
|
||||
`(binding [*prefix* (into (or *prefix* []) ~prefix)]
|
||||
~@rest))
|
||||
|
||||
(defmacro with-cursor [cursor & rest]
|
||||
`(binding [*current* ~cursor]
|
||||
~@rest))
|
||||
~@rest))
|
||||
|
||||
(defmacro with-field [field & rest]
|
||||
`(with-cursor (get *current* ~field )
|
||||
`(with-cursor (get *current* ~field)
|
||||
~@rest))
|
||||
|
||||
(defmacro with-field-default [field default & rest]
|
||||
`(with-cursor (get *current* ~field ~default)
|
||||
~@rest))
|
||||
|
||||
`(let [new-cursor# (get *current* ~field ~default)
|
||||
new-cursor2# (if (not (deref new-cursor#))
|
||||
(do
|
||||
(cursor/transact! *current*
|
||||
(fn [c#]
|
||||
(assoc c# ~field ~default)))
|
||||
(get *current* ~field ~default))
|
||||
|
||||
new-cursor#)]
|
||||
(with-cursor new-cursor2#
|
||||
~@rest)))
|
||||
|
||||
(defn field-name
|
||||
([] (field-name *current*))
|
||||
@@ -62,10 +74,10 @@
|
||||
(defn cursor-map
|
||||
([f] (cursor-map *current* f))
|
||||
([cursor f]
|
||||
(when (field-value)
|
||||
(when (seq (field-value))
|
||||
(doall
|
||||
(for [n cursor]
|
||||
(with-cursor n
|
||||
(f n)))))))
|
||||
(for [n cursor]
|
||||
(with-cursor n
|
||||
(f n)))))))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user