This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-01
Channels
- # admin-announcements (3)
- # beginners (25)
- # boot (21)
- # cider (39)
- # cljs-dev (86)
- # cljsrn (20)
- # clojars (4)
- # clojure (70)
- # clojure-canada (1)
- # clojure-greece (101)
- # clojure-poland (16)
- # clojure-russia (35)
- # clojure-spec (202)
- # clojure-uk (24)
- # clojurescript (69)
- # cursive (23)
- # datomic (34)
- # devcards (7)
- # dirac (5)
- # editors (3)
- # emacs (6)
- # events (1)
- # hoplon (52)
- # instaparse (1)
- # jobs (4)
- # jvm (2)
- # lein-figwheel (2)
- # leiningen (10)
- # luminus (2)
- # mount (1)
- # off-topic (12)
- # om (55)
- # om-next (8)
- # onyx (19)
- # pedestal (4)
- # planck (1)
- # re-frame (27)
- # reagent (5)
- # remote-jobs (1)
- # spirituality-ethics (14)
- # tmp-json-parsing (6)
- # untangled (121)
- # yada (32)
hi, I am still new to reframe, wonder if there is some template to start. I am particularly interested how to handle a usual login scenario, which include: 1. show login screen, 2. do the login, if success, show dashboard, 3, if fail keep on login page, 4. if go to dashboard directly by url, then clean auth cookie and redirect to login page.
trying to figure out what is the best way of doing all these using single state atom
I have a component
(defn input-component []
(let [input (re-frame/subscribe [:input])]
(fn []
[:div
"Hello : " @input ". "
[:div [:input {:type "text" :on-change #(re-frame/dispatch [:input-changed])}]]
])))
@ashconnor: you aren't including the input value in your dispatch - try something like #(re-frame/dispatch [:input-changed (-> % .-target .-value)])
What @rui.yang asks for might actually be really useful. I'll be needing to add auth to my re-frame app soon and am probably procrastinating because I have no idea how that'll work with re-frame
i'm sure a template would be useful @fasiha @rui.yang ... meanwhile a very simple scheme is to store your user-credentials (or lack thereof) in app-db, have a sub which yields those creds and a form-2 component which has hiccup something like (if @creds-sub [authenticated-view] [unauthenticated-view])
... after successful login a handler stores the creds in app-db, logout (or whenever you get a 401) removes them
I'm not sure if this will help you guys, but this is how I've decided to differentiate logged in routes vs logged out routes:
https://gist.github.com/escherize/83cbb92a99a39a8ba1c52fd50ea16c5a#file-routing-cljs-L30
Can someone take me through the [:input-changed (-> % .-target .-value)]
? It works but I don’t know exactly what (-> % .-target .-value)
is doing
@ashconnor: it is syntax sugar for (fn [e] (-> e .-target .-value))
which defines a function with a single parameter e
and returns the value
field of the target
field of e
1. %
is part of syntactic sugar for anonymous functions. inside the #(..)
, it’s a reference to the args passed to the function.
2. ->
is the thread-first macro, see this: https://clojuredocs.org/clojure.core/-%3E
3. .-
is an interop with javascript. you’re getting an attribute from an object
the ->
is a threading macro, which rewrites (-> e .-target .-value)
as (.-value (.-target e))
thanks @mccraigmccraig @caio - that makes sense
so I could replace the macro with [:input-changed (fn [e] ((.-value (.-target e))))]
: edit maybe [:input-changed (fn [e] (.-value (.-target e)))]
from what you’ve sent, it looks like the whole line is inside an anonymous function, isn’t it?
idk if it was a typo or what, but the correct “translation” to that first line you sent would be [:input-changed (.-value (.-target %))]
[:input-changed (fn [e] (.-value (.-target e)))]
would be right if the original was [:input-changed #(-> % .-target .-value)]
(notice the #
)
thanks - because right now with the code I posted just above - it returns a javascript function to the input
@escherize thanks for sharing, will digger into it.