re-frame

https://github.com/Day8/re-frame/blob/master/docs/README.md https://github.com/Day8/re-frame/blob/master/docs/External-Resources.md
2020-12-22T03:50:34.003200Z

How can I understand why my subscriptions are getting disposed? It’s driving me nuts and I’m sure that this question will help me understand laziness better

p-himik 2020-12-22T08:35:21.003800Z

Subs (which are just Reagent reactions) are disposed of automatically when the last watch on them is removed. Usually it happens when the last view that was using a sub is unmounted.

p-himik 2020-12-22T08:35:59.004100Z

How does it affect you anyway?

2020-12-22T12:48:48.007Z

I’m using day8.re-frame/undo, and my :undos? subscription is being disposed on the first undoable event that I dispatch

2020-12-22T12:52:22.010600Z

But I don’t understand why, because I have an undo and a redo button on my app and I don’t think they’re getting unmounted... they do get disabled however. Here’s the tutorial that I’m following where it describes what the buttons are like https://github.com/day8/re-frame-undo#the-result

p-himik 2020-12-22T12:58:37.010900Z

OK, but how does it affect you? How do you even know that duspose! (IIRC the function) was called on the reaction?

2020-12-22T13:10:35.016900Z

Ok I figured out how to fix the behavior: could you explain what’s going on though? I had written my button like so: (defn undo-button [] (let [undos? @(subscribe [:undos?])] ;; only enable the button when there's undos (fn [] [:input {:type "button" :value "undo" :disabled (not undos?) :on-click #(dispatch [:undo])}]]))) Note that this deviates from the tutorial slightly, by moving the deref of my subscription into the let binding itself. With my button written this way, the subscription to :undos? gets disposed. When I do it the tutorial’s way instead, ie like so: (defn undo-button [] (let [undos? (subscribe [:undos?])] ;; only enable the button when there's undos (fn [] [:input {:type "button" :value "undo" :disabled (not @undos?) :on-click #(dispatch [:undo])}]]))) I get the correct behavior. Why does moving the @ result in this change of behavior?

p-himik 2020-12-22T13:32:34.017100Z

The first example uses @ outside of the view function but, I think, within the Reagent's ratom context. It's expected. In short, don't use @ on subs/ratoms/reactions outside of view functions.

2020-12-22T13:50:46.017800Z

Ok I’ll remember that - thanks for your help

clyfe 2020-12-22T15:40:42.018500Z

What's the plan on re-frame instances there? Should I make a PR? @mikethompson

clyfe 2020-12-22T15:40:55.018900Z

Or core team wants to do it themselves?

2020-12-22T17:24:47.019Z

So I have this basic println effect which I'm trying to dispatch in my init function start here renders the root view, but for some reason I'm getting an error re: frame: no :event handler registered for: {"ns":"pokedex.events", "name":"println","fqn":"pokedex.events/println", ...} . Am I registering the effect incorrectly? I just followed https://github.com/day8/re-frame/blob/master/docs/Effects.md re-frame docs on effects, but tweaked the effect slightly.

p-himik 2020-12-22T17:26:17.019700Z

::println in your case is an effect. dispatch and dispatch-sync work on events.

p-himik 2020-12-22T17:26:49.020100Z

Switch ::print and ::print-effect in pokedex.events.

dpsutton 2020-12-22T17:34:09.020400Z

also :println and ::println are different values

👍 3
🔥 2
🤘 1
2020-12-22T22:08:20.021400Z

So I have registered this effect and event which fetches some data from an API which I then conj onto a vector in my re-frame db which works fine, but it's quite slow for some reason and I'm not exactly sure why. First I thought it was an issue with the component that renders this data, but I made it basically empty to check and it seems that dispatching to ::fetch-pokemons is the bottleneck.

p-himik 2020-12-22T22:23:01.022100Z

Your (http/get p-url) requests are done sequentially, not in parallel. Also, a small nitpick: you can replace (update db :list #(conj % pokemon)) with (update db :list conj pokemon).

2020-12-22T22:24:37.022300Z

I see, how would I make the requests in parallel?

p-himik 2020-12-22T22:40:08.022500Z

Try using take! for example. There are innumerable approaches.

👍 1