Fork me on GitHub
#re-frame
<
2015-08-11
>
pupeno11:08:42

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.

pupeno11:08:17

The view for tool-panel looks like this:

pupeno11:08:18

(let [current-tool (re-frame/subscribe [:current-tool])]
    (fn []
      [:h1 (@current-tool "name")]))

pupeno11:08:40

The problem I’m having is that @current-tool is nil until get-tools finishes. What’s the appropriate way to deal with that?

pupeno11:08:55

(when @current-tool
        [:h1 (@current-tool "name")])

pupeno11:08:57

feels wrong.

mikethompson13:08:30

I've answered over on stackoverflow

rorydouglas20:08:05

re: that last question on re-frame..

rorydouglas20:08:32

is the tldr that you should break out the “is ready” bit into a separate subscription?

timgilbert21:08:59

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])

timgilbert21:08:54

…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

timgilbert21:08:47

I have a separate re-frame question...

timgilbert21:08:08

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?

mikethompson21:08:00

OR encourage Dan to release a new version including that PR

mikethompson21:08:40

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

timgilbert21:08:22

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?

mikethompson21:08:09

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.

timgilbert21:08:44

Interesting, thanks for the info...