Fork me on GitHub
#re-frame
<
2017-03-16
>
isak00:03:12

that seems to solve the problem i was talking about

mikethompson01:03:31

@isak No, not keen on debouncing subscriptions. Just not the right place. Events change things. They do re-computations. They should handle debouncing, etc. Subscriptions are a much more passive set of dominoes. You are trying to create stateful subscriptions which .... is ... bad. > What if the check isn't the problem, but the number of places? Why don't you put the check on everything? If X changes them dispatch Y. Identity check on X, so virtually no overhead. (And then handle debouncing via a debounced dispatch)

mikethompson01:03:11

You can easily add a interceptor to every event handler Other than that .... do it this way (see point 2) https://github.com/Day8/re-frame/issues/255#issuecomment-274303581

isak02:03:42

@mikethompson Hm, isn't there more state for the user of the functionality that way, though? Because they need to worry about starting and stopping the :subscription->event with that way. With the function I had, at least the state is just internal.

isak02:03:38

I see that there is a new reagent with-let function that can help, but then you'd still need to write event handlers that actually spit out the right effects to start and stop

isak02:03:05

Instead of relying on the :on-dispose logic that happens naturally with subscriptions

isak02:03:54

So the logic becomes a lot more spread out

isak02:03:00

I could do the check for every handler, but its not just one value, it is a handful. Wouldn't it also become problematic if that became a standard pattern in the codebase? Potentially a bunch of things that got checked for everything. Seems a shame to not be able to use the normal reaction logic

rc114007:03:23

hi all , wanted to find out if there is a way to effecitvely stream/load parts of my re-frame app as needed , so when i hit the site initially only the code that is needed to load the login page is sent to the browser , once i login the rest can be loaded

sandbags10:03:54

@mikethompson is the re-frame lein template kept deliberately behind on some dependencies? I see it was updated a few days ago but lein ancient revealed quite a few older libs and i wondered if there might be compatibility issues that were driving those?

rc114010:03:06

@mccraigmccraig thanks , will check it out

rc114010:03:02

i think i remember seeing that post before , but will check it out again

rc114010:03:22

was hoping for some way to do this cleanly within re-frame

mccraigmccraig10:03:30

assuming the modules stuff works smoothly it looks fairly straightforward to split a re-frame app up, as long as you do it along namespace lines - perhaps with a core.cljs file for each module which makes sure all the subs, handlers and views for that module get required ?

borkdude10:03:04

What is a good way to log just the name of the events that are dispatched by re-frame in the console?

borkdude10:03:17

For debugging that is

sandbags10:03:39

@borkdude that isn't re-frisk?

borkdude10:03:20

I didn’t check that out yet

sandbags10:03:57

i think you will find it exactly what you are looking for, unless you absolutely want them in the browser console rather than a pop-up window

sandbags10:03:07

it also has an inspector for the app-db

sandbags10:03:15

essential in my book

borkdude10:03:37

I’m going to try it

borkdude11:03:51

Should it come up with a separate window?

borkdude11:03:09

I’m not seeing anything 🙂

borkdude11:03:10

Ah I see in the demo that there is something in the bottom right corner

borkdude11:03:21

Didn’t notice it in my own app 🙂

borkdude11:03:25

It works very good, thanks @sandbags

arcanumxiii11:03:41

Hi, just to say that I just finished my first webapp with re-frame — took me a week, with lot of change coming from the end customer and all the while learning the framework : it was fun, fast, and a pleasure to debug. If only everything could be so nice… next web app challenge : using re-com, maybe some React component. Let’s hope my joy will not be crushed !

borkdude12:03:13

Can I make the left panel where the event names show wider in re-frisk?

borkdude12:03:38

I still can’t read many of them 😉

sandbags14:03:02

@borkdude motor4ik is your man for that

sandbags14:03:16

stupid autocomplete

sandbags14:03:07

anyone hit "Figwheel Client Version 0.5.7 is not equal to Figwheel Sidecar Version 0.5.9. Shutting down Websocket Connection!" ?

sandbags14:03:25

i'm looking in the deps and i cannot see where the version 0.5.7 client is getting roped in from

sandbags14:03:19

sigh... despite being a new app this is something cached to do with using localhost:3449

souenzzo14:03:43

lein do clean, figwheel ctrl + F5 I also have a lot of problems with caching 😛

sandbags14:03:40

whomever it was that said cache invalidation was one of the two hardest problems in CS was not likely wrong

sandbags15:03:12

@isak when would you imagine needing to?

isak16:03:24

@sandbags e.g., trigger expensive computation when something changes

sandbags16:03:48

have you read about how re-frame subscriptions work?

sandbags16:03:57

i'm not seeing the need to do this manually

isak16:03:00

yea, but re-frame subscriptions are not good for expensive computations that may get triggered frequently

sandbags16:03:18

well, they're going to get triggered as they are de-referenced, right?

isak16:03:44

here is a workaround i did yesterday: https://gist.github.com/isaksky/2cc3779b52305e992c6150863454a9af . But I was thinking about run!then a debounced dispatch as an alternative

sandbags16:03:58

IIRC in the docs it talks about how to avoid computing unnecessary subscriptions

sandbags16:03:21

i.e. you don't have to re-compute everything every time db changes

isak16:03:05

yea, but lets say a user can trigger 10 things in quick succession that requires recomputing an expensive dataset - how would subscriptions as-is be a good fit? only 1 recalculation is required

sandbags16:03:13

otherwise i guess my instinct would be to use an event, or i don't understand your problem

sandbags16:03:38

well that sounds like you need to debounce the event

sandbags16:03:44

not manually dispatch the expensive calculation

isak16:03:00

if I debounce the event, then the UI does not update, which is not good

sandbags16:03:16

you might need to separate your event processing into a sequence of events

isak16:03:21

it is nice if the UI can update, indicate that it is "thinking", then do the thinking

sandbags16:03:34

but, really, i am straying beyond my competence in building re-frame apps, i'll let others with more experience advise you

isak16:03:16

ok. I have a way, just seeing if there is a less "nasty" way

sandbags16:03:52

i think there is, but i'll let someone who has implemented it try and explain

madstap16:03:25

Couldn't you make a layer of indirection? Like event-1 updates the db with a :expensive-calc/thinking? and dispatches further to event-2 which is debounced and does the calculation? Or am I misunderstanding something?

isak16:03:48

@madstap yea that is a good solution, and normally i would do that. The only problem is there are a number of events that can trigger changes to the basis for an expensive calculation, so then I think it makes sense to "react" to those changes, instead of spreading the logic around many handlers, or applying a global interceptor

sandbags20:03:10

Anyone know of any re-com applications other than the demo app?

PB21:03:56

Hey all. Everywhere I use h-box or well boxes in general I get the following warning: Warning: Every element in a seq should have a unique :key:

PB21:03:05

Could someone help me understand what this is?

PB21:03:27

I’m usually iterating over vectors to build the view

sandbags21:03:54

@petr it's to do with the way react keeps track of elements. When you generate the items in your vector add ^{:key <unique-id>} before each one

sandbags21:03:25

e.g. ^{:key "row-15"} and so on

PB21:03:12

@sandbags thats going to get kinda ugly. Basically I’m iterating over api-responses. Woudl a good time to do it be when adding it to my db atom?

PB21:03:18

Is there a pattern around this?

sandbags21:03:59

worst case scenario use their hash as a unique id

sandbags21:03:10

you don't need to add it to the database, just generate it on the hiccup element

sandbags21:03:30

react uses the keys to detect changed elements more quickly

PB21:03:30

Ohhh I see

PB21:03:38

So I’m using re-com to handle that

PB21:03:50

I didn’t see a :key attr on any of thecomponents

sandbags21:03:22

(h-box :children [^{:key "abc123"}[...] ^{:key "def456"][...] ...])

sandbags21:03:42

presumably you're using for or map to create the children

sandbags21:03:08

as hiccup elements from your api responses

PB21:03:31

Ah so it just goes prior to the element I’m about to create

sandbags21:03:51

^{} is the sugar for attaching metadata to a clojure object

PB21:03:23

I haven’t ever seen the ^{} only as ^:dynamic

PB21:03:25

as an example

PB21:03:05

So I’m guessing using gensym is not a good idea here

sandbags21:03:03

IIRC ^:dynamic is a short-hand for ^{:dynamic true} but i could be wrong about that

sandbags21:03:17

I'm not clear what you mean in terms of gensym

shaun-mahood21:03:41

@petr: there is another way to do that if you aren't expecting a lot of changes to the data - I believe you use into, I'll try and find the doc for it. It avoids the need for the unique ID.

sandbags21:03:16

i wonder how it does that, i'd be interested to know

PB21:03:27

@shaun-mahood that’s be great!

PB21:03:52

@sandbags so it’s everywhere that there is a new element? be it a boarder/title/box/whatever?

sandbags21:03:15

@petr no, everywhere that there is a collection, list items, rows, a series of divs etc...

sandbags21:03:39

without id's react would have to compare all the elements to see which ones had been added/removed

PB21:03:49

Ah so basically anywhere the :children key appears

sandbags21:03:05

in terms of h-box and v-box yes

shaun-mahood22:03:40

@petr: I can't find the docs right now, I'm pretty sure it's in the re-frame docs somewhere - it was one of the docs that crossed over between re-frame and reagent so it may have ended up in a weird place. Either way, the essential thing is that if you call a sequence using for, then you will have to add the unique keys. If you use into [], then you don't have to worry about it. The reasoning behind the keys can be found at https://facebook.github.io/react/docs/lists-and-keys.html#keys - my understanding as it relates to reagent is that if you are moving things around (dragging items in a list, for example) then you should see better performance, but otherwise you can just use into [] and avoid the whole mess.

sandbags22:03:07

i can't see how using into instead of for can change the situation

shaun-mahood22:03:28

@sandbags: Well, if I could find the relevant docs then that would explain it better 🙂

shaun-mahood22:03:01

Oh perfect, didn't even have to light up the batsignal!

sandbags22:03:39

ah so it's about lists vs vectors

sandbags22:03:52

for returns a list, (into [] ...) returns a vector

sandbags22:03:02

okay that makes sense

sandbags22:03:12

so (mapv ...) would also be fine

sandbags22:03:41

useful to know

shaun-mahood22:03:42

Looks like mapv is an issue based on the bottom of that answer, assuming that hasn't changed

sandbags22:03:12

i tried following the link at the bottom which has only a link to another page that does not appear to refer to mapv