Fork me on GitHub
#re-frame
<
2018-02-09
>
mikethompson01:02:25

re-framers fellow re-framians :-)

Vincent Cantin01:02:40

@joelsanchez your words have been re-framed. 😉

gklijs06:02:33

@joelsanchez looks clear enough. Didn’t know you could chrome like that from clojure, might want to use it for running tests

shen07:02:16

Hey, struggling to find the terms for this, but what's the practice for "derived subscriptions?"

shen07:02:55

e.g. if (subscribe [:numbers]) gives a list of integers

shen07:02:31

can I have (subscribe [:filter even? [:numbers]])?

gklijs07:02:24

think it’s best to create a seperate subscription for it, because you only want to re-render when even numbers change

shen07:02:36

guess it's more of a "how many subs I feel like writing" kind of thing?

shen07:02:56

i.e., when [:numbers] change, i'm happy for all the subs to run

shen07:02:06

but feels easier to write (subscribe [:filter even? [:filter bigger-than-10? [:numbers]]]) than to write

shen07:02:32

(subscribe [:even-and-bigger-than-5]) etc.?

shen07:02:42

(assuming i've got a bunch of compossible things to filter by)

danielcompton08:02:47

Hello re-framians, re-frame-trace 0.1.19 is out: https://github.com/Day8/re-frame-trace/releases/tag/0.1.19. There’s a big change to how subscriptions are processed which should be more accurate. Give it a spin and let us know if there are any issues. We’re finishing up work on re-frame-trace very shortly, so nows the time to get your feedback in.

manuel08:02:10

@danielcompton thanks! Loaded in my project, everything seems to be working fine.

shen09:02:20

@danielcompton: you got any thoughts on derived subscriptions ?

danielcompton09:02:19

@shen a first principle for re-frame is to store everything as pure data as much as possible instead of functions. So I probably wouldn’t want to be passing functions to a subscription

danielcompton09:02:34

If you have a bounded set of possible filters, I could imagine passing data parameters to a subscription which configures which filter transducers are run.

danielcompton09:02:57

Can you give a bit more context to the problem you’re trying to solve?

shen09:02:35

hmm... maybe not passing fn's then

shen09:02:56

ok, numbers is probably a bad example

shen09:02:18

so, let's say we have a col of gizmos

shen09:02:36

and each has three properties, colour, shape and pattern

shen09:02:56

so, we can get the whole thing with a (subscribe [:gizmos])

shen09:02:25

and probably have a (subscribe [:gizmo-by-colour :red])

shen09:02:46

(subscribe [:gizmo-by-shape :square])

shen09:02:27

now, if i wan red squares, I'm thinking I can either have [:gizmo-by-shape-and-colour :square :red]

shen09:02:57

but this also suggests [:gizmo-by-colour-and-pattern :red :stripes] etc.

shen09:02:31

or, I can have a [:filter-by-colour :red [:filter-by-shape :square [:gizmos]]]

shen09:02:19

so I only need to write 4 subs, and at run time, these data only subs are constructed, with some code like

danielcompton09:02:05

We have a similar kind of pattern in our code base, I’ll need to check and see what we did there. I think I’m at least one case we built up a materialised View in event handlers responding to filters changing (though that was very complicated from memory)

mikethompson09:02:40

@shen the current colour (`:red`) will be stored in app-db somewhere, yes?

mikethompson09:02:36

I can't see these filter terms coming our of thin air

mikethompson10:02:15

They'll be arising because of user actions ... so they'll be in app-db ?

mikethompson10:02:10

Anyway, ignoring that line of questioning ... back to your line of reasoning (that the view supplies the filter terms) wouldn't you just do it as something like this ... (subscribe [:gizmos {:shape :square :color :red}])

shen10:02:52

@mikethompson think I see what you are getting at. that if there's a shape dropdown, and color dropdown, then can hook it up that way?

shen10:02:40

will think through this. just wondering to what degree do I actually need composibility

mikethompson10:02:54

By "composability" are you indicating that you might want "many"

mikethompson10:02:22

i.e. many components each asking for their own list of gizmos, using their own (local) set of filters?

shen10:02:02

so, let's say we have three properties

shen10:02:04

as above

shen10:02:40

so 2^3 possibly types of components: i.e.

shen10:02:58

everything, filter by color, filter by color and shape etc.

shen10:02:07

(3 being larger in real life)

shen10:02:42

so, it's a "how many (types) of subscriptions do I need question"

shen10:02:31

but I do see that your solution says you can do it with one

mikethompson10:02:32

So "many" of these components can be on-screen at once ... is that the challenge?

shen10:02:55

less on screen at once. more just amount of boiler-platy code

shen10:02:39

oh right. you mean more types on-screen means more subs in memory, right?

mikethompson10:02:15

I'm just trying to understand the challenge

mikethompson10:02:42

When you say 2^3 possibly types of components then you mean there can be one component on the screen which can be in any one of 8 configurations?

mikethompson10:02:25

And by "configurations" we mean "configurations of filters"

shen10:02:31

no. meant something a bit different

shen10:02:04

so, first question: the challenge is less in terms of performance/number of subs etc.

shen10:02:34

really started with me trying to not write [:gizmo-by-color :red]

shen10:02:52

which your suggestion of [:gizmo {:colour :red}] does solve

mikethompson10:02:02

I'm finding it hard to see any variation of this that involves more than one subscription (although if you want what I call the "many" arrangement, you might need multiple "instances" of this one subscription)

shen10:02:19

think you are right.

shen10:02:22

but thanks. think I was trying to do something a bit weird

shen10:02:25

appreciate the help

shen10:02:53

appreciate all the work and help, btw 🙂

danielneal10:02:18

@shen, this might not be helpful to you, but we put together https://github.com/riverford/compound for the case when you have things (e.g. gizmos) that you might want to filter or index by multiple things (e.g. by colour or shape). The materialized indexes are built as you put data into the db.

shen10:02:48

oh cool. will have a look

sggdfgf11:02:16

what this may mean [:> ] ?

danielneal11:02:39

it's for interop I think

danielneal11:02:49

totally impossible to search for :s

danielneal11:02:03

but something akin to reagent's adapt-react-class

gklijs18:02:47

When I have several events which change parameters of a query, and every time something changes I want to trigger several events. What would be the most idiomatic way to do this with re-frame. I could subscribe to a map containing all the parameters, and then trigger an event handler?

danielcompton18:02:23

@gklijs generally you don’t want to tie the output of a sub into running an event handler

danielcompton18:02:44

it breaks the cycle of data

danielcompton18:02:08

You could make an effect which handles the rerunning of the events?

gklijs18:02:19

Yes, only thing with that is that each parameter change would be a effectfull event handler

gklijs18:02:01

But that's probably the cleanest way.