Fork me on GitHub
#re-frame
<
2016-12-20
>
mikethompson00:12:29

@oliy your re-learn look interesting https://github.com/oliyh/re-learn Ready for prime time?

michael.heuberger01:12:39

hello folks - does anyone know how to write a single reg-sub that does one or more subscriptions, depending on the app state? probably an anti-pattern but doable with reg-sub-raw

michael.heuberger01:12:24

something like

(reg-sub 
   :sorted-items 
   (fn [_ _]  (subscribe (get-in db [:some-subscriber]))) ;; here, a dynamic one depending on app state but dont have the db. how to do this?
   (fn [items _]
      (sort items))

oliy08:12:22

@mikethompson thanks! Not quite yet - there are a few small bugs and features to do before it's ready to be unleashed on an unsuspecting world

oliy08:12:32

I'll let you know when I do though!

oliy08:12:16

There is a part of a blog post on integrating Martian with re-frame for http fx

cmal10:12:33

I found new docs been added. A lot of things left for me to read now.

martinklepsch10:12:33

Anyone aware of larger public apps written in re-frame 0.8.0+?

cmal11:12:20

Hi, I remember there is a doc article which explained why use [] to build a component instead of using (). But I cannot find it right now. Can anyone help me? I've been searching for it for two hours...

curlyfry11:12:58

@cmal I'm not sure which one you mean, but there is an explanation in the official Reagent tutorial https://reagent-project.github.io

cmal11:12:19

Ahh, I remember maybe I read about that in the wiki. I've been search the docs not the wikis. maybe in wikis. I'll go to there and have a look.

cmal13:12:47

Is this because of react will not rerender when its props change if the props were not actually used in the component.

limist15:12:28

@oliy re-learn looks really useful, thanks for sharing it. We've definitely got a use-case in mind for it, any eta for its release please?

borkdude15:12:41

In the re-frame README I read:

(defn items-view
  []
  (let [items  (subscribe [:query-items])]  ;; source items from app state
    [:div (map item-render @items]))   ;; assume item-render already written
Shouldn’t this be a form-2 component, since it will now create subscription every time the component is re-rendered?

oliy15:12:48

@limist I am hoping to work on it a bit over xmas

cmal16:12:34

@borkdude: I also confused about this. But it seems that I have read in somewhere this is a form-2 comp and omit the (fn []) because of no args. I am not sure, still hope others to explain.

martinklepsch16:12:33

@borkdude you can now use subscriptions in form-1 components, introduced in 0.9.0 I think

borkdude16:12:52

@martinklepsch is that documented how it works?

martinklepsch16:12:28

@borkdude please refer to the change log for details, afk right now

mikethompson20:12:02

@borkdude See reference to issue #218 in https://github.com/Day8/re-frame/blob/master/CHANGES.md#headline It has actually been a thing since v0.8. But formally recognised (in docs etc) in v0.9

kkruit20:12:02

@mikethompson I'd just like to say re-frame's documentation is intelligible and comprehensive. My thanks to you and others in the community who've contributed, it's fantastic.

borkdude20:12:20

@mikethompson I had exactly the situation you are describing in this comment: https://github.com/Day8/re-frame/issues/218#issuecomment-252470445 (corner case 1) I wondered about this: > When x changes, the view re-renders, creating a new subscription. The old one is disposed of. No need of dynamic subscriptions. Can’t this go wrong somehow, when you deref the subscription once and render the [:div (str @sub)], what happens when x is the same, but the subscription value changes - what will trigger the re-render?

mikethompson20:12:54

@borkdude that's the standard case: view rerenders because the value of the subscription changes

mikethompson20:12:30

@kkruit thanks! Pleased to hear it is going well for you.

borkdude20:12:58

@mikethompson I’m not sure if that is true. E.g. in the case of this Reagent component, it does not work:

(defn foo []
  (let [x (r/atom 1)]
    [:button {:on-click #(swap! x inc)} (str @x)]))

mikethompson20:12:10

Hmm. I must not be understanding your question. I can't see the connection between the code above and the original question I answered. Re-reading

borkdude20:12:48

well, subscriptions behave more or less the same as r/atoms in the sense that they will trigger a re-render when they change. But when you generate one during your render, then render once and it goes out of scope, it seems to me that will never trigger a re-render again (unless the argument to the function changes)

mikethompson21:12:24

@borkdude I promise it works a treat :-)

borkdude21:12:10

Can you explain why it works?

mikethompson21:12:42

1. rerender functions capture their input reactions (so "going out of scope" is not a problem) 2. re-frame is caching reactions (so it can do signal de-duplication)

mikethompson21:12:59

Signal deduplication came in with v0.8, and that's the underlying reason this all works. See explanation at top of #218

borkdude21:12:51

@mikethompson Cool, so it works because of a more complex implementation than Reagent + r/atoms

mikethompson21:12:05

Subscriptions have always been reactions, rather than r/atoms, but yes, v0.8 introduced a lower level caching of reactions

mikethompson21:12:28

Should all be explained in #218, hopefully

shaun-mahood21:12:33

@borkdude: What are the last couple of screenshots checking and confirming?

borkdude21:12:11

@shaun-mahood correct behavior of subscriptions in form-1 components

shaun-mahood21:12:19

Ahh good :) I've used them quite a bit in form-1 since they started working, just got confused following throught the conversation.

borkdude21:12:41

I didn’t know this yet, but it is very good to be aware of it

shaun-mahood21:12:17

@borkdude: yeah, it takes away one of the significant gotchas from earlier versions.

mikethompson21:12:41

Be sure to also look at the new Infographics: https://github.com/Day8/re-frame/blob/master/docs/EventHandlingInfographic.md https://github.com/Day8/re-frame/blob/master/docs/SubscriptionInfographic.md These are not relevant at all to what we were talking about .... I'm just keen to seem them read :-)

shaun-mahood21:12:19

@mikethompson: Are those infographics available in an editable form? Curious how they're made :)

mikethompson21:12:38

I should put the figma files into the repo

borkdude22:12:57

Now I’m actually starting to wonder why this didn’t work in Reagent: https://www.dropbox.com/s/1142j6n0pjll6l4/Screenshot%202016-12-20%2023.14.08.png?dl=0

borkdude22:12:47

When I click the button, a re-render is triggered. Looks like the atom isn’t updated properly or something?

borkdude22:12:04

I know the solution, but I’m just trying to understand what’s going on

borkdude22:12:53

Funny, when I add a println after the on-click:

click #<Atom: 1>
after click #<Atom: 2>
but then followed by
re-render #<Atom: 1>

borkdude22:12:31

ah, the explanation is that every re-render a new atom is created of course.

borkdude22:12:50

But in Re-frame the subscription is cached. I guess that solves it.

shaun-mahood23:12:56

@borkdude: I've had to re-read the page at https://github.com/Day8/re-frame/wiki/Creating%20Reagent%20Components an embarrasing number of times to realize (and remember) how all of that works :)