Fork me on GitHub
#re-frame
<
2018-06-08
>
kennytilton10:06:21

I am porting my AskHN Who’s Hiring browser https://kennytilton.github.io/whoishiring/ from JS/Matrix to CLJS/re-frame. Going quite well, actually. But I have been using strings like “&trade;” and (worse) unicode stuff like “&#x2b51". Those are not getting translated so I see those exact strings in the browser. Anyone know who’s escaping those so the client does not handle them?

kennytilton10:06:10

Perfect. Thx.

kasuko15:06:34

Hey, I am running into a weird re-frame subscription conceptual problem. I really like keeping all the logic out of the views but I have been struggling with how to use the result of a subscription as an input to another subscription without tainting the views with this logic.

kasuko15:06:44

Here is a code snippet to describe what I mean

kasuko15:06:50

So in the above I have a subscription that will return the currently selected type in my imaginary "list" view

kasuko16:06:10

and then I have a subscription that will return me properties of some provided type

kasuko16:06:24

I want to know how to effectively thread the result of the :selected-type subscription as input to the :properties subscription. Preferably as a subscription itself (see :list-properties subscription handler) but I feel like needed to use reg-sub-raw is really clunky.

kasuko16:06:27

Any thoughts?

curlyfry16:06:37

@kasuko Providing a subscription as input to another is a built in feature of re-frame, and the subscription will only run when the value of the input subscription changes

kasuko16:06:22

@curlyfry Thanks, but I am aware of that feature, but it doesn't deliver on my needed solution. The above allows passing subscriptions as inputs to another handler but it does not allow multiple levels of resolution for the input subscriptions

kasuko16:06:36

For example when trying to use it I can't get past this:

kasuko16:06:48

Essentially I am trying to use subscriptions as I would functions and now I want to compose them like I would with functional composition ... but can't

kasuko16:06:26

If we pretended subscriptions were functions then it's very easy to do (output-sub (input1-sub) (input2-sub)) which is what the above subscriptions are doing ... but I want to do is (output-sub (input-sub1 (input-sub2)))

mikerod19:06:01

@kasuko this is possible via reg-sub-raw though

mikerod19:06:27

(re-frame/reg-sub-raw
 :broken-list-properties
 (fn [_ _]
   (reagent/reaction
    (let [[selected-type @(re-frame/subscribe [:selected-type])
           props @(re-frame/subscribe [:properties selected-type])]]
      props))))

mikerod19:06:34

So there isn’t a “nice syntax” way to support it built-in, but it certainly is doable.

mikerod19:06:50

I ended up just making my own macro to capture the pattern, since I’ve used it quite often in some apps.

mikerod19:06:42

ended up just doing something ilke

(re-frame.utils/regsub
 :broken-list-properties
 {:q [] ;; <-- used if there were query args to use as well
  :let [selected-type [:selected-type]
        props [:properties selected-type]]}
 props)
just so I wouldn’t have to do all that boilerplate code as often and also to be sure I didn’t forget to add a reagent/reaction

👍 4
kasuko19:06:34

Ah so I was on the right track. Ya I will also have to look into ways to clean it up a bit. Thanks!

mikerod20:06:28

No problem

eraserhd16:06:31

(wrong window)

kennytilton18:06:34

[Warning: preference question ahead,] Am I the only one tempted to group stuff by application semantics instead of re-frame role? eg, instead of having all events in one place have them in the source after the primary (perhaps only) component that would dispatch it?

👍 4
Hendrik Poernama04:06:16

With my events.cljs growing, I am now leaning more towards semantic grouping (let's call it modules?) I try to make each modules independent or have explicit dependcies. Sometimes this requires having a dedicated module init event.

Hendrik Poernama04:06:12

Since app db can become a big glob of globals, I namespaced all keys and control access with cofx. That is, one module can only access another's data if it is 'exported' using cofx.

manutter5119:06:19

You are definitely not the only one, I’ve decided I like it much better with semantically-related stuff all in one file.

isak20:06:27

since clojurescript lacks the ability to add requires programatically, it tends to get extremely verbose if you don't

kennytilton20:06:28

Reagent is over-warning about un-keyed vectors. Sometimes I know what I am doing. Is there some way to turn that off? It makes a yuge mess in my console. Now I have to fake a key. And are these questions better on Stack Overflow?

kkruit21:06:52

So I recently started using re-frame-10x and last week the tool stopped showing up in chrome (v67.0.3396.79). It still shows up in firefox any ideas?

kkruit21:06:51

Nevermind, I cleared the Local Storage and everything is back to normal. Thanks for the sound board :)

kennytilton23:06:34

“(into [:ul]…)” Diabolical! I love it. Thx!