This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-08-11
Channels
- # admin-announcements (36)
- # beginners (1)
- # boot (267)
- # cider (19)
- # cljs-dev (12)
- # clojure (149)
- # clojure-austin (4)
- # clojure-canada (1)
- # clojure-czech (3)
- # clojure-dev (31)
- # clojure-japan (2)
- # clojure-uk (22)
- # clojurebridge (3)
- # clojurescript (314)
- # clojutre (18)
- # core-async (8)
- # cursive (4)
- # datascript (1)
- # datomic (27)
- # editors (2)
- # events (80)
- # hoplon (13)
- # javascript (2)
- # jobs (5)
- # ldnclj (12)
- # ldnproclodo (1)
- # off-topic (4)
- # re-frame (21)
- # reagent (87)
- # testing (13)
I feel like I’m doing something wrong here architecture wise. When you click a link for a tool, it goes to /tool/:id and the route /tool/:id dispatches [:display-tool-panel id]. The handler for :display-tool-panel then dispatches get-tools if the db doesn’t contain the tools, which queries the server and sets, in the db, :active-panel to :tool-panel, and :current-tool-id to the id in /tool/:id.
The view for tool-panel looks like this:
(let [current-tool (re-frame/subscribe [:current-tool])]
(fn []
[:h1 (@current-tool "name")]))
The problem I’m having is that @current-tool is nil until get-tools finishes. What’s the appropriate way to deal with that?
(when @current-tool
[:h1 (@current-tool "name")])
feels wrong.
I posted this question slightly re-worded but with more code here: http://stackoverflow.com/questions/31940875/dealing-with-missing-data-while-its-being-loaded-in-re-frame
I've answered over on stackoverflow
re: that last question on re-frame..
is the tldr that you should break out the “is ready” bit into a separate subscription?
I have a pattern I’ve been using where I set a db field :http-loading? true
when I fire off an http response, and then when I receive the response I set :http-loading? false
and store the response body in the db. Then I have subscriptions to that field and I have stuff similar to:
(if @loading
[:p “Please wait, loading…”] ; note: this is really a spinner
[my-data-component @loaded-http-data])
…but you could probably also use something like (if @loaded-http-data [data-component] [:p “Still loading, please wait…”])
if you just wind up saving your http response into the db when it comes back
I have a separate re-frame question...
What it the secret to using [:input]
tags, saving them to the app-db on user input (eg :on-change
), and not having the cursor jump to the end of the input field every time the user enters a character?
@timgilbert: run a fork which includes this PR: https://github.com/reagent-project/reagent/pull/126
OR encourage Dan to release a new version including that PR
Regarding re-frame and inputs
... if you find you are losing chars on input (from fast typing) then switch to using dispatch-sync
. See: https://github.com/Day8/re-frame/issues/39
Thanks @mikethompson! I’ve noticed the re-com [input-text]
component doesn’t seem to suffer from the jumping-cursor problem, have you implemented the changes in that first PR in the code for the component?
re-com's [input-text]
does suffer from the problem when you choose to use the :validation-regex
AND you type in something that doesn't fit that regex. For example, if the regex requires entering 99.9
and you type in an a
, you'll see the cursor jump to the end.
Interesting, thanks for the info...