Fork me on GitHub
#reagent
<
2017-08-23
>
hugh.jf.chen03:08:12

Hello,any one knows why my program can't receive re-frame subscription?

hugh.jf.chen03:08:31

the event has fired and dispatched

hugh.jf.chen03:08:42

the event handler had been called

hugh.jf.chen03:08:51

but I can't receive the subscribtion

mikethompson03:08:14

Very hard to say without a minimal gist demonstrating the code you have written. But in the absence of good information, I'd wildly speculate along the following lines ... 1. did you put debug in the subscription's computation function? Is it running? My guess is no. 2. Did you deref the subscription in the view. Put a @ in front?

mikethompson03:08:08

Other than that you'll have to be a lot clearer with your question. A minimal gist is best

hugh.jf.chen03:08:58

Thanks for your reply. for 1, I did put debug code in subscription code and it is not running

hugh.jf.chen04:08:29

for number 2, I had @ in front of the subscription

hugh.jf.chen04:08:44

I'm trying to put the code in a gist

hugh.jf.chen04:08:25

I use a re-frame-datatable component

hugh.jf.chen04:08:41

I suspect that may be cause of the problem?

hugh.jf.chen05:08:27

really can't figure out why can't receive the :edit-checklist subscription

mikethompson05:08:30

Dunno if this is the issue, but don't use with-let just use let??

hugh.jf.chen05:08:42

I've tried just using let, can't receive the subscription either

quangh12:08:38

I got an warning when trying create hiccup from npm-deps: Warning: Using native React classes directly in Hiccup forms is not supported. Use create-element or adapt-react-class instead: JsonTree

sam1612:08:08

Can someone tell me how to use this library in reframe? https://github.com/TeamWertarbyte/material-auto-rotating-carousel

reefersleep19:08:28

@hugh.jf.chen in your gist, you're not registering the :edit-checklist subscription anywhere

reefersleep19:08:06

your

;; sub reg function
(defn query [db [event-id]]
doesn't actually register a subscription. And it's not called anywhere else in the gist.

reefersleep19:08:36

Add this:

(re-frame.core/reg-sub
 :edit-checklist
 (fn [db _] (:edit-checklist db)))

reefersleep19:08:27

Or maybe, you'd actually want the following:

(re-frame.core/reg-sub
 :open?
 (fn [db _] (if (:edit-checklist db)
                true                
                false)))

reefersleep19:08:22

And like @mikethompson said, just use a let. I don't know what the with-let does, but your code doesn't seem to suggest you need anything other than a let.

reefersleep19:08:30

(actually, re-frame doesn't demand you to use the let for technical reasons either, but of course, you might want it because you feel it makes your code easier to read : )

noisesmith19:08:35

I was curious, for reference this is what with-let is https://github.com/reagent-project/reagent/blob/master/src/reagent/ratom.clj#L17 *(fixed with better link for def)

pesterhazy19:08:27

Does anyone have experience writing Higher Order Components in Reagent? Any pointers to good examples?

pesterhazy19:08:22

I'm looking for a way to build reusable pieces of functionality that can be added to existing components in a composable manner.

reefersleep20:08:17

@noisesmith I looked it up myself as well, not the definition, though, just a reference to it in a reagent update - looks to me like a boilerplate-removing way of doing:

reefersleep20:08:48

(defn my-component [a b c]
  (let [s (subscribe [:some-path])]
    (fn render-my-component [a b c]
      ... ;; component implementation goes here, somewhere dereffing s

noisesmith20:08:01

it allows a finalize too

hugh.jf.chen22:08:26

@reefersleep Thanks for your reply. Actually, I have following snippet in the same namespace of the query function: (reg-sub :edit-checklist query). So I think I'd register the subscription for :edit-checklist.

hugh.jf.chen22:08:08

OK. I think I figured it out. Because no one calls the checklist-edit-form function. Once I add a call to the checklist-edit-form function somewhere in my code. I can receive the subscription. Maybe re-frame think there's no deed to deliver the subscription if there's no subscribe call. Sounds reasonable.

mikethompson23:08:45

@hugh.jf.chen nodes in the signal graph are ONLY instantiated when they are needed

mikethompson23:08:19

And they are only needed when a view exists and does a subscribe.