Fork me on GitHub
#re-frame
<
2017-01-16
>
mikethompson03:01:37

@brthrjon Ahh, you asked for slider and I read scroller. So my comment is useless, sorry.

paulspencerwilliams09:01:58

Cheers @mikethompson, I'll look at that .

mikethompson09:01:06

re-frame is currently on the first page of hacker news thanks to "jdnier"

minikomi09:01:55

upvoted 🙂

akiroz09:01:25

hey guys, anyone know if I could control the return value of dispatch-sync in an event? I need to use the window.onbeforeunload event handler to check if a form has unsaved data in the app-db before the user leaves my page.

akiroz09:01:38

The problem is that the onbeforeunload handler needs to be sync or the window will just close before I can check the app-db in a re-frame event.

andre09:01:30

did you try it?

andre09:01:57

dispatch-syn should work because it sync

andre09:01:17

what do you mean "if I could control the return value" ?

nilrecurring09:01:27

@akiroz dispatches do not have a return value AFAIK. I would just dereference a subscription after the dispatch-sync, that is totally synchronous

nilrecurring09:01:32

But while you’re at it, if you use the @(subscribe [:form-vals]) you don’t even need the dispatch-sync

akiroz09:01:36

@andre no, I haven't tried it yet. according to MDN, the onbeforeunload handler function is suppose to return a string....

akiroz09:01:06

@nilrecurring Oh cool, that should work just fine 🙂

nilrecurring09:01:01

@akiroz BIG DISCLAIMER though: dereferencing subscriptions if you’re not in a view, even if it’s the easiest way in some cases, cuts the “reactive cycle” (as you’re bypassing the view), so it’s not advised and it feels a bit hackish

nilrecurring09:01:20

I usually do that because it works just fine

nilrecurring09:01:38

But there’s an ongoing discussion on this here: https://github.com/Day8/re-frame/issues/255

akiroz09:01:04

yeah, I know it's a bit of a hack... but I really don't have much of a choice because of the imperative nature of this API. 😞 my other solution would be to access re-frame.db.app-db directly which seem much worse...

mikethompson09:01:39

Naturally, I must sternly caution against this using all the gravitas I can muster. But ... I'd also note that some have used track from reagent with subscriptions

mikethompson09:01:14

Generally they dispatch from within the track to make something happen

mikethompson09:01:36

Or so I'm told

nilrecurring09:01:10

How is it better/worse/different from @(subscribe)?

mikethompson09:01:41

The subscribe inside of a track and then when it fires, they dispatch something

nilrecurring09:01:37

But akiroz’s usecase requires a synchronous lookup in app-db

nilrecurring09:01:51

So no dispatch needed. I believe the dispatch-sync was happening only to peek into the db from there.

ska13:01:31

Hi. I am still not grokking the subscription model in re-frame. When I am in a form-1 view and have a let binding at the top like this: (let [data (deref (rf/subscribe [::update-event]))] ;; return some view here, including calling sub-view with data does it make a difference whether I deref in the let binding or when calling the sub-views?

mccraigmccraig14:01:35

@ska other than that the type of the bound variable in the let binding will be different, no

ska15:01:35

@mccraigmccraig so the subscription will work in either situation?

mccraigmccraig15:01:39

@ska yes - either should be fine

ska15:01:24

So, when my view function is called (since this is form-1 it's the render fn, I take it) it will return a new vector on every call and thus break the fast equality benefit that we get from our persistent data structures. Doesn't it? Since the subscribe is just inside a defn it can not know anything about the stuff around it.

mccraigmccraig15:01:07

@ska yes, the fn is the render fn, and it will return a new vector on every call - but it will only get called when the data it depends on changes (i.e. when the value of the subscription changes)

ska15:01:50

@mccraigmccraig That looks like a miracle to me. The render fn only gets called when some data it uses in its function body changed. Ah, well, I guess I need to read the sources of re-frame eventually. And maybe it is just too late for today.

joshjones15:01:10

@ska If it helps to know, the subscribe is cached -- I had the same question (if I'm understanding your confusion) a week or so ago

brthrjon16:01:41

is there a standard place (e.g. config.cljs) to put effect handlers (i.e (reg-fx...))?