Skip to content

Instantly share code, notes, and snippets.

@kennyjwilli
Last active June 9, 2017 18:10
Show Gist options
  • Save kennyjwilli/f83013c6a61ec31610b93eb6aa45b821 to your computer and use it in GitHub Desktop.
Save kennyjwilli/f83013c6a61ec31610b93eb6aa45b821 to your computer and use it in GitHub Desktop.
(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