Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(rules/rule logging-in
[[_ :logging-in? true]]
[[_ :email ?email]]
[[_ :password ?password]]
(do-login ?email ?password
(fn [[ok? response]]
(println "login response" (pr-str response))
(precept/then (into
[[:global :logged-in? true]
[:transient :login-response (random-uuid)]]
(precept.util/tuplize-into-vec response))))))
(rules/rule login-response
[[_ :login-response ?r]]
(println "retract")
(precept.util/retract! [:global :logging-in? true]))
(rules/defsub :email
[[_ :email ?email]]
{:email ?email})
(rules/defsub :password
[[_ :password ?email]]
{:password ?email})
(defn Login
(let [{:keys [email]} @(precept/subscribe [:email])
{:keys [password]} @(precept/subscribe [:password])]
[:input {:type "text"
:value email
:on-change #(precept/then [:global :email (.. % -target -value)])}]
[:input {:type "text"
:value password
:on-change #(precept/then [:global :password (.. % -target -value)])}]
[:button {:on-click #(precept/then [:global :logging-in? true])} "Login"]]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.