Last active
June 9, 2017 18:10
-
-
Save kennyjwilli/f83013c6a61ec31610b93eb6aa45b821 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(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])] | |
[:div | |
[: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