This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-04-01
Channels
- # aatree (3)
- # admin-announcements (2)
- # beginners (42)
- # boot (142)
- # cider (12)
- # cljsrn (11)
- # clojure (126)
- # clojure-greece (2)
- # clojure-poland (7)
- # clojure-russia (81)
- # clojure-uk (10)
- # clojurescript (81)
- # component (27)
- # core-typed (2)
- # cursive (18)
- # euroclojure (1)
- # gorilla (1)
- # hoplon (85)
- # immutant (2)
- # jobs (3)
- # leiningen (2)
- # off-topic (49)
- # om (151)
- # onyx (19)
- # parinfer (3)
- # re-frame (36)
- # reagent (2)
- # spacemacs (5)
- # untangled (32)
- # yada (9)
@mikethompson: Ah, that’s a good point, event handlers are supposed to be snappy.
There will be some event which triggers the change in route. And there will be an event handler which handles that event.
@mikethompson: aha, yeah
That event handler would normally issue the necessary HTTP GET
Hmm. Not sure it is. Changes to app-db
happen in event handlers.
https://github.com/Day8/re-frame/wiki/Talking-To-Servers
So sourcing data generally happens in event handlers
Back up to the point where there is an "event" ... the user clicks on something. What handles that event?
What (event handler) knows to change route?
okay so in your "main" ...
... you'll have a initialise-db
event fired which takes the route
... and which will initiate the HTTP GET
... and the on-success
and on-failure
of that GET will themselves dispatch
https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/core.cljs#L30-L34
Except your dispatch will look something like ...
(dispatch [:initialise XXXXXX])
where XXXXX is the necessary path info
@bpicolo: Similar, except that re-frame dispatches based on event type, whereas Flux apps typically dispatch based on sub-state-tree handlers, each of which picks apart the event type. Or as far as I understand the Flux docs, anyway.
I say “typically” because it is possible to write a Flux app that uses re-frame style event dispatch. It just isn’t the usual pattern.
@mikethompson: just last week I was solving this and found the same solution 😉. Great
here's an input:
[:input {:type "password"
:name "password"
:placeholder "Password"
:value @password
:on-key-press (fn [e]
(let [enter 13]
(if (= enter (.-charCode e))
(when (validate @signup-form-data)
(dispatch [:signup-request]))))
true)
:on-change (fn [e]
(dispatch [:update-signup-form :password
(-> e .-target .-value)])
true)}]
No surprise here: it's the password field on my signup form. Is there a better way to get the :on-key-press
functionality? I.e., run
(when (validate @signup-form-data)
(dispatch [:signup-request]))
whenever enter is hit within the form.
When I wrapped it in a form (as follows), enter was causing me to post query params, instead of running my cljs - even though i have :on-submit (fn [e] (.preventDefault e))
on the form!The way I've done it before is:
1. In the app routes, either subscribe to :logged-in?
or check for the existance of a key to indicate that fact.
2. For the login/signup/non-secret pages, if :logged-in?
, edit the url to put the user at the main screen in the SPA.
3. For the secret pages, if not :logged-in?
edit the url to kick the user to signup page.
Those are fine; just remember that you also want server-side authorization on all this stuff, just in case someone hacks their way around. Never trust the client code.