Created
August 28, 2016 18:47
-
-
Save micha/dd9bf0f6a24d0c64de8e0c0faad6c56a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns ui.form) | |
(defmacro with-form | |
[[binding form-machine] & body] | |
`(let [form-machine# ~form-machine | |
~binding form-machine# | |
{data# :data | |
error# :error | |
state# :state | |
exception# :exception | |
loading# :loading} form-machine#] | |
(binding [*form-machine* form-machine# | |
*form-exception* exception# | |
*form-inputs* data# | |
*form-errors* error# | |
*form-state* state# | |
*form-loading* loading#] | |
~@body))) | |
(defmacro with-field | |
[attr & body] | |
`(let [[error# data#] (map ~attr [*form-errors* *form-inputs*])] | |
(binding [*input-error* error# | |
*input-data* data# | |
*input-name* (gensym)] | |
~@body))) | |
(defmacro definput | |
[name [attr kids] & body] | |
`(hoplon.core/defelem ~name | |
[{state# :state | |
id# :id | |
:as attr#} kids#] | |
(let [state# (or state# *input-data*) | |
id# (or id# *input-name*) | |
~attr (merge attr# {:state state# :id id#}) | |
~kids kids#] | |
~@body))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment