Fork me on GitHub
#re-frame
<
2016-12-14
>
andre05:12:36

@sandbags (1) like expand all but only for one sub-tree? (2) can't imagine how it should work, can you write steps how you want to use it

andre05:12:42

hi all, who have tried latest version of https://github.com/flexsurfer/re-frisk is it helpful? subscriptions ,interceptors?

escherize06:12:53

For us, basically expand-all expands our 200ish event/sub/etc. but we just want to see the app-db.

escherize06:12:59

expand one subtree would help us a lot

escherize06:12:30

maybe add a [+] next to the current down caret?

escherize06:12:40

that just expands all beneath the node the [+] is on?

escherize06:12:13

just my thoughts

andre06:12:39

thank you

mikethompson07:12:24

------------- Reminder for everyone. Please do the Clojure survey: https://www.surveymonkey.com/r/clojure2016 ------------

sandbags09:12:02

@andre (1) i meant to expand a subtree completely rather than one level at a time

sandbags09:12:06

@andre (2) I am very often interested in a nested part of my data structure, but i think this could be difficult as there are GUID keys in the way that make data-add-in troublesome to use but would, now i think about it for a moment, also make a bookmark unusable... hrmmm

pbaille10:12:56

Hello, everyone, i’ve got a question: reg-event-fx has no doc string, is it intended to be used for events that doesn’t modify app-db, so the return value of the function passed to it is ignored?

abstruselyarcane10:12:24

@pbaille reg-event-fx is a more generalised event handler, it can produce all side effects, including modifying the db

abstruselyarcane10:12:40

{:db newdb} to modify db

pbaille10:12:48

ok but it doesn’t need to return the new db value, right?

abstruselyarcane10:12:59

It shouldn't, yes

abstruselyarcane10:12:03

I haven't tried it, tho

pbaille10:12:46

ok so you can return {:db newvalue} and in this case it acts as reg-event-db?

pbaille10:12:55

seems weird

andre10:12:08

@pbaille reg-event-fx handler should return map with the fx istructions

pbaille10:12:10

why just use reg-event-db in this case

abstruselyarcane10:12:28

reg-event-db is sugar so you don't have to return a map with new db everytime

abstruselyarcane10:12:32

It's just another middleware

andre10:12:35

re-frame has several implemented instructions, like :dispatch, :dispatch-n, and also :db

andre10:12:08

and if you want you can return :db instrictions with the new db value

abstruselyarcane10:12:15

reg-event-db wraps the function you give it in middleware that turns it into {:db stuff} for other middleware to consume and do stuff

pbaille10:12:17

@andre, ok I see, Am I suppose to look the source to know that? or is it documented somewhere?

andre10:12:20

but it's optional

abstruselyarcane10:12:23

It's in the docs

pbaille10:12:39

okok sorry i’ve missed it

pbaille10:12:38

great! thank you 🙂

abstruselyarcane10:12:33

And the readme gets even longer...

mikethompson10:12:39

@abstruselyarcane Hey! The new readme is shorter

mikethompson10:12:19

And it has pictures

abstruselyarcane11:12:13

I liked the old ascii art, but I guess dominoes will have to do

shem11:12:05

@andre new version of re-frisk looks very good! couldn't get the pop up working previously, now works great.

andre11:12:16

@shem great, thank you 🙂

bartadv12:12:39

Hi! A question, that's best pictured with todomvc code, so I'm pasting following line: https://github.com/Day8/re-frame/blob/master/examples/todomvc/src/todomvc/views.cljs#L7

bartadv12:12:41

here we see that the todo input just have local atom, and it manages it on its own. Suppose we want to clear the input when some other action occurs, then our only way to do this is to move the input to the app db and just subscribe, right?

bartadv12:12:33

Oh, I see the 'editing' in the upper component is doing exactly what I've been wondering. Sorry for vague questions, I'm just wondering where's the distinction between something that's local and something that just have to be in app state and is subject of subscriptions/events...

lxsameer12:12:32

how can i pass a react element as a prop to other elements in reagent ? I need something similar to <C1 icon={<ICON />}>

abstruselyarcane12:12:03

Since re-frame is built on top of reagent, you should just be passing vectors around in hiccup

lxsameer12:12:48

@abstruselyarcane something like this ?

lxsameer12:12:05

[button {:icon  [user]}]

abstruselyarcane12:12:30

Wait, you want to pass a react component to another react component?

abstruselyarcane12:12:49

How is the icon represented?

abstruselyarcane12:12:33

If the icon is a react class

lxsameer12:12:39

yeah both are react components

abstruselyarcane13:12:02

You should be able to pass in a vector that will be used by another component to construct their view

lxsameer13:12:11

and the button component keep complaining because it expect a react element for icon prop

abstruselyarcane13:12:33

Oh, youre using a third party lib button

abstruselyarcane13:12:46

I thought you were talking about a component you controlled

abstruselyarcane13:12:29

Hmm, maybe dig through reagent docs to see if theres a function that transforms it from hiccup to react?

abstruselyarcane13:12:28

I'm not sure how reagent handles this tho

lxsameer13:12:55

that's a bit hard

abstruselyarcane13:12:48

Look at the create react component section

lxsameer13:12:02

@abstruselyarcane i did it , i did this (.render (new js/Grommet.Icons.Base.User (clj->js {}) js/window))

lxsameer13:12:21

I'm looking for a cleaner solution

abstruselyarcane13:12:14

Umm, refactor that into a macro?

abstruselyarcane13:12:38

I'm not the expert here; until somebody comes up with a cleaner way, might as well make it look prettier

lxsameer13:12:59

the cleaner solution is to use React.createElement and pass the react compnent to it

abstruselyarcane13:12:30

Looks very pretty, I must admit

andre13:12:41

but if someone wants i have diagram for ninjas 🙂

abstruselyarcane13:12:24

@andre try creating diagrams for dynamic subscriptions and events

abstruselyarcane13:12:31

or are they deprecated?

mikethompson13:12:26

With v0.8.0 you really don't need dynamic subscriptions any more

abstruselyarcane13:12:01

Well, if you have local state somewhere that needs to interact with subs, it might be useful

abstruselyarcane13:12:19

I'm still trying to rewrite my entire data layer with specter, tho

abstruselyarcane13:12:31

(get-in path) is just not working anymore

pbaille15:12:12

hi, I'm wondering why this is throwing an error: (rf/reg-sub ::db (fn [db _] db)) (println @(rf/subscribe [::db]))

shaun-mahood16:12:32

@pbaille: What error are you seeing?

pbaille16:12:44

#object[TypeError TypeError: Cannot read property 'call' of undefined]

pbaille16:12:56

it should not throw?

shaun-mahood16:12:53

Are you just trying to figure out how subscribe works, or is that pattern necessary in your project?

pbaille16:12:24

no it is just a test, not intended to be used

pbaille16:12:46

expose the whole state as this is a bad idea I suppose

shaun-mahood16:12:08

Ok, in that case I think you should be following the examples - start with https://github.com/Day8/re-frame/tree/master/examples/simple

pbaille16:12:01

is subscribe only intended to be used in reagent components?

shaun-mahood16:12:03

Subscribe is generally used within a reagent component, so the test you are doing isn't representative of normal use and probably isn't worth troubleshooting

pbaille16:12:10

ok I continue to explore and come back if I'm stuck again 🙂

pbaille16:12:18

thank you!

shaun-mahood16:12:37

No problem, keep asking questions as you run into problems 🙂

danielcompton19:12:20

There's nothing really wrong with calling a subscription in standard code, e.g. test code, as long as you are aware it is a slightly different context

danielcompton19:12:34

but for one shot subscription calls, that is fine

danielcompton19:12:11

@pbaille at a guess, you should be wrapping those in a do? Can you show the whole context?

upgradingdave19:12:29

hey all, I’m writing a widget that shows a progression of steps and I’d like to be able to dispatch a step, then wait for a little bit, then dispatch another step, here’s what I have and it works fine, but wondering if anyone can suggest any tips?

upgradingdave19:12:48

I’m only going to have 3 or 4 steps, but might be fun to try and write a macro. Or, also, just curious if anyone else ran into something similar and how you solved it?

sandbags19:12:31

@upgradingdave have you seen :dispatch-later ?

sandbags19:12:48

check in the effects doc if not

upgradingdave19:12:30

awesome, (I thought there might be something already built in). thanks!

kanwei20:12:11

is anyone using boot, that's also gotten the latest betas to run properly?

sandbags20:12:34

@upgradingdave pleasure ... happy to be able to give some help for once 🙂

danielcompton20:12:52

depending on how much control you need

shaun-mahood21:12:11

@danielcompton: Outside of tests, would there be any issues with calling subscriptions in other places? If I had a regular function call a subscription, and then used that function from multiple places (e.g. a coeffect, event handler, effect) would there be any things that would work differently from subscribing within a reagent component? Does the whole de-duped signal graph magic still work the same. This is all purely theoretical for me, but I've seen a few questions on this channel (particularly with chains of subscriptions) where subscribing directly from within a function may have been the best solution if there are no other major issues, so it would be nice to understand it a bit better so I'm not giving out too much misleading advice 🙂

danielcompton22:12:33

I should probably write this up, as you're right it is a common question. There's two intertwined issues here though. Should you use subscriptions outside of view functions or other subscriptions, and Can you use subscriptions. I'm still pretty firmly in the should not camp for subscribing in event handlers as part of a production app for conceptual/data flow/unidirectional data cycle reasons. Can you use them? I've never really explored too much down this path, but I know we use one shot subscriptions in tests, and there's also no issue I've found with calling them at the REPL. I haven't really looked to see how the reaction on-dispose is called outside of a view function. Also, there's a weird reagent bug at the moment where you can use a disposed Reaction quite happily, and I think it even keeps running. Then you need to consider the subscription cache, which should be mostly fine, except for cases like https://github.com/Day8/re-frame/blob/develop/docs/FAQs/Why-Clear-Sub-Cache.md. In short, thar be dragons. If you want to call it in testing or for debugging purposes, then I don't see any major issues. But it's not something I'd recommend for production critical code

shaun-mahood22:12:45

@danielcompton: That's good info, thanks. I had the impression that things broke outside of components, so it's nice to know that it's mainly a case of "possibly undefined behaviour, probably a bad idea" vs. "won't work".

danielcompton22:12:03

Yep, good summary