Fork me on GitHub
#re-frame
<
2016-11-25
>
mikethompson00:11:45

@tomerweller something like ... 1. the server query (via HTTP?) will be initiated in an event handler, assumidly in response to some event like [:user-clicked-navbar-item 3], via something re-frame-http. 2. This event handler will also set a bit of app state, (assoc db :loading true) 3. When you get the HTTP call response, you save the data into db into the path, say, :the-data 4. Your subscription will query for both :loading and :the-data. It will return nil or [] while ever :loading is true, otherwise when :loading transitions to false it will return whatever is needed from :the-data.

mikethompson00:11:49

@knaman I can't seem to follow your question/problem ... but I can see a problem in your code ... use this instead

(defn edit
  [id]
  (let [alerts (subscribe [:alerts])
     a  (filter #(= id (:a %)) @alerts)]
     ((template) a "Edit")))

mikethompson00:11:09

Mind you the problem with this approach is that a rerender will be triggered everytime alerts changes

mikethompson00:11:20

Without really understanding the context, perhaps better like this ...

(defn edit
  [id]
  (let [a (subscribe [:alert id])]       ;; <-- subscription give a single alert
     ((template) @a "Edit")))

knaman00:11:55

@mikethompson the problem was rerendering only, not so much to do with any ui issue as it doent affect anything, but kind of bothered me that adding the elements has nothing to do with editing function

mikethompson00:11:42

Like i said, I'm totally confused about the problem you describe, but I'm afraid I've not got more time to devote right now. So just jumped in with a code related observation

mikethompson00:11:39

Because some of the code you supplied was broken

knaman00:11:58

@mikethompson no worries, ill give your suggestion a try thanx

samueldev00:11:34

@mikethompson are you headed to clojure conj next week?

samueldev00:11:18

Us re-framers attending will pour one out for you. Did you see that there’s a re-frame talk?

mikethompson00:11:54

Would love to, but there's the tyranny of distance Yes, shaun is giving one (talk)

mikethompson00:11:17

Is that the first ever talk on re-frame at a conference?

mikethompson00:11:47

We're a low profile, gorilla movement

mikethompson00:11:00

Knuckles on the ground and everything :-)

richiardiandrea00:11:21

grassroots movement, very cool 🙂 I am very happy that there is going to be a talk on it, finally!

samueldev00:11:10

lol gorilla movement

tomerweller01:11:07

next: Is it possible to register a subscription with a dynamic list of input signals?

mikethompson01:11:10

That's the best docs currently available on reg-sub

mikethompson01:11:14

@danielgrosse nothing obviously wrong

mikethompson01:11:22

But ... it looks as if the problem is in the subscription handler for :title, right?

mikethompson01:11:40

You are saying it is not delivering a changing value?

mikethompson01:11:58

Can't figure out why session-component takes a session argument. Doesn't use it.

danielgrosse01:11:37

@mikethompson The example is really stripped down. In the full version, the session object is used. I did find the error. The wrapping function caused the behaviour.

danielgrosse02:11:06

(defn session-component
	[session]
	(let [title-id (subcribe [:title-id])
           session-title (get session @title-id)] ; this represent more the real code
		(rf/console :log "session-component " @session-title) ;shows allways the same
			[:div @session-title]))

shaun-mahood04:11:39

@samueldev @richiardiandrea I’m really looking forward to meeting other re-framers - anyone else coming to the conj?

samueldev05:11:07

I'll be there

samueldev05:11:29

Let's have a few pints and try and convert some om'ers

curlyfry15:11:25

@andre Exciting stuff! Do you think you could explain a bit more what is happening in the second gif? I don't quite follow what is shown under expand all/Collapse all to the right. Is the event list on the left the history?

edannenberg17:11:54

@knaman in the first example alerts will subscribe on every render, probably not what you want in this case. in the second example the subscription is only executed once, and then just the inner fn is executed for each re-render. for more details see https://github.com/Day8/re-frame/wiki/Creating-Reagent-Components

mikethompson17:11:45

@knaman prior to version 0.8.0, you had to use the 2nd variation (above). But, from v0.8.0 onwards, you can use the 1st version, which is easier. @edannenberg You can read all the details here: https://github.com/Day8/re-frame/issues/218#issuecomment-254718776

knaman17:11:38

@mikethompson ok, i was more thinking about idiomatic ways if any for using either of two ways, right now i use the first variation when i need to sanitize some data coming as argument as i can store it inside a let, and the second one more for ui rendering work

mikethompson17:11:44

It was the move to a de-duplicated signal graph (in v0.8.0) is what makes this change possible: https://github.com/Day8/re-frame/blob/master/CHANGES.md#080--20160819

mikethompson17:11:05

@knaman I'd be using the 1st variation all the time now.

mikethompson17:11:53

There can be subtle issues with the 2nd: https://github.com/Day8/re-frame/issues/218#issuecomment-252470445 (link corrected)

mikethompson17:11:08

I corrected the link immediately above

knaman17:11:25

@mikethompson i m pretty new to clojurescript, all the docs have example of second tupe

knaman17:11:48

@mikethompson what about subscriptions as @edannenberg pointed out they would be made every time i render

mikethompson17:11:36

@knaman as the ticket indicates, the decision to officially allow the 1st form was recent. But now it is made, you should absolutely go that way. Much simpler.

mikethompson17:11:36

The 2nd form will still work, of course. The docs will be migrated to reflect the new decision. .

edannenberg18:11:36

@mikethompson good to know, was not aware of that. btw, whats your stance on reagent/with-let ?

mikethompson18:11:54

I never use it

mikethompson18:11:31

But maybe I should ... i can't even remember what it does

andre18:11:39

@curlyfry hi, yes ,on the left "history" of all events, and you can click on event and watch event data at the bottom on the right. on the top right the app's state , app-db

andre18:11:15

so you can see all picture what happens in your app

andre18:11:28

app state and events data

andre18:11:28

for example if app stuck, you can watch current app state and last events data before stuck

edannenberg18:11:56

@mikethompson basically a shortcut for react lifecycle methods, (ab)used it quite a bit as a shortcut for form-2 so far

edannenberg18:11:00

one downside is missing IDE support though

tomerweller20:11:27

@mikethompson regarding dynamic subscriptions, I went over the todos documentations but am still not sure about this specific case. What I have in hand is a subscription that depends on a variable number of subscriptions. i.e, there are two levels of signals. A first signal determines which other signals (o to n) to subscribe to. Do you have any recommendations on how to achieve that?