Fork me on GitHub
#re-frame
<
2018-05-03
>
eoliphant00:05:10

it looks like the only thing there is the query id. is there any way to get the db? I have a set of keys in there that have corresponding subscriptions. I was going to use them to create the subs

mikethompson01:05:12

@eoliphant be sure to read through https://github.com/Day8/re-frame/blob/master/docs/SubscriptionInfographic.md And take particular notice of the link at the bottom to the todomvc example app, it is heavily commented and will likely provide the answers you seek

mikethompson01:05:46

But to answer your questions: 1. Layer 2 have direct access to app-db. And consequently they will rerun every time app-db changes in any way. So we make them trivial. 2. Layer 3 has access to one or more Layer 2 subscriptions (but not app-db directly) and creates "materialised views" of the raw data extracted by Layer 2

mikethompson01:05:07

We never want Layer 3 accessing app-db directly because, if that were the case, the Layer 3 sub would have to re-run every time app-db changes for any reason.

mikethompson01:05:52

So, Layer 2 acts as a way of pruning the propagation of values through the signal graph (short-circuiting unnecessary computations) , when app-db has changed in some way, but not the part "of interest".

eoliphant01:05:11

Yeah, I’ve got the flow down. But yeah I see the issue if you make app-db available

mikethompson01:05:35

You really don't want app-db ... you want some part of app-db

👍 4
mikethompson01:05:44

And that's what a layer 2 subscription provides

eoliphant01:05:05

and I’d done that. but my issue, and granted maybe I didn’t do this the best way lol, is that I’ve got a form, and I have dynamic subs that I can use to get a given field’s values, validations, etc. So [:field-val x] [:field-valid x] etc. That all works fine

eoliphant01:05:19

but I wanted to check all the fields prior to submission. Basically have my signal function return a vector of subscribes to the [:field-valid] for each field, then just run an every? or whatever in the calc function

mikethompson01:05:45

Won't this submit be handled in an event handler?

eoliphant01:05:04

so I can say return a sub for the form-data, etc. But then it’s the raw data, and I don’t reuse the validation check in the field level validation

mikethompson01:05:53

This forms stuff is not really my era. There are re-frame forms libs. Have a look in ExternalResources docs

mikethompson01:05:12

They may have some ideas

eoliphant01:05:42

yeah i’ve been poking around with those, the more flexible one free-form, says validation is pluggable, but has no examples lol

eoliphant01:05:47

but i’ll do some more digging

eoliphant02:05:46

ok i got it to work. I’m just not sure how I feel about it lol

eoliphant02:05:07

I used my sub that points to the map of fields in my component, i then passed that result to my are-all-fields-valid? level 3 sub. From that I just mapv over the list to get subs. Works, just feels a little clunky lol

sveri05:05:40

Anyone having an idea how I can hide the re-frame-10x window during tests with etaoin? Or is it possible to start with the re-frame-10x window hidden?

sveri05:05:30

I mean mean with code, sorry I wasnt clear.

gklijs06:05:13

@sveri in my project with re-frame-10x it's hidden on start-up, but I thought that was the default. Not sure what's different. But with etaoin you must likely want to test against a production build right?

sveri06:05:36

@gklijs I write my tests while developing and run them parallel, easier than clicking through the UI all the time. I wonder why it is opened per default, OTOH it is also opened whenever I open my browser.

gklijs06:05:07

Might be a browser specific thing, I use chrome, and it never opened when opening the page, neither when opening with etaoin.

mikethompson06:05:50

(mranderson047.re-frame.v0v10v2.re-frame.core/dispatch [:settings/user-toggle-panel])

hkjels09:05:00

I’ve used reagent and re-frame quite a bit now, but I’m still at times struggling to resolve the warnings about Every element in a seq should have a unique :key:

hkjels09:05:37

is it the children of ui.element.containers.views.container

sandbags12:05:46

@hkjels if you are creating children using, e.g., a for then you need to add a ^{:key "unique-something"} before the child form

👍 4
javi12:05:46

@hkjels > but I’m still at times struggling to resolve the warnings look at your (for [item coll] [:div .... forma and make sure a unique {:key "some-unique-key"} is provided.

javi12:05:06

ha ha synched!

hkjels12:05:35

That’s what I usually do, but the problem did not lie within a loop I changed the form of one of my components from [cotainer params content] to (into [container params] content) and it was satisfied

sandbags12:05:38

that's because your into returned a vector

sandbags12:05:25

perhaps i misunderstand your context…

lilactown15:05:56

this is an issue with any component that takes & children

lilactown15:05:51

you have to use into to get rid of the need for keys, otherwise reagent sees & children as a list and expects it to have keys

hkjels19:05:29

Yeah, that’s exactly what happens, but it’s difficult to see from the warning, where the problem resides and I’ve had heeps of these.

lwhorton17:05:02

I’d love to get some opinions on the use of graphql with reframe. The two strategies seem kind of opposed to one another? Graphql is a fetch-only-what-you-need every view, and keep refetching because the payload is optimized thanks to the query. A well structured rf db is capable of avoiding a ton of fetches because its easy to update in a single place, and derived values prevent stale views

lwhorton17:05:04

Normally in rf I would normalize the database and all my views pole subscriptions from the database. If I’m going to fetch all new data every view though with graphql, I don’t see any downside to name spacing a slice of the database and tying it straight to my view. Normally this would be a bad idea, But does it really matter if you’re just re-fetching exactly what you need on every view?

isak17:05:11

@lwhorton you can get away with that in a lot of cases, and it is a lot simpler. For complex views where you edit multiple records, but need a consistent view, it may not be good enough

👍 4
isak17:05:36

For example if you have comments { ... person { name } }, and look at one comment, edit person.name, then go the next comment. (Not realistic maybe, but you get the point)

lgessler17:05:19

does anyone have any advice on how to decide what to put in a subscription vs. in the view code? the basic mantra, of course, is that views should be as dumb as possible, but it seems like on the opposite end there is the risk of putting too much view-specific content in subs. For instance I have a text SVG element in one of my components. Some of its attrs are functions of db state, and some are hard-coded, something like this:

[:text 
 {:font-size 12
  :y @(rf/subscribe [:some-sub])
  :x @(rf/subscribe [:some-other-sub])}
  @(rf/subscribe [:another sub])]
I could think of at least three different approaches to this: 1. Have a sub for each attr that varies with state 2. Have a single sub that returns a map containing the values of all state-dependent attrs 3. Have a single sub that returns the entire attr map, including hardcoded values of all of them (3) seems quite convenient in that it simplifies view code a lot, but I wonder if there are disadvantages to putting some specific information in subscriptions that aren't apparent to me? edit: adding something on that occurred to me later: i ended up doing (3) in some parts of my codebase, but when I needed to add an on-click attr to it I decided that that was a really bad thing to keep in a sub rather than on the view itself. So from this maybe i'd suggest a more general principle that event handlers probably ought to stay ought of subs, as these should probably be as obvious as possible in the view code

isak18:05:28

@lgessler One way to think about it would be whether you could reuse the subscriptions for different targets, like DOM vs React Native. If it is too specific, then you couldn't, which would be a shame. May also not be a huge problem, though

👍 4
lgessler19:05:51

thanks, that's one useful diagnostic question for sure

robert-stuttaford19:05:05

@lgessler so i guess it’s about frequency of change. if only one of those change a lot, and that one thing has many subscribers, then you probably want to split it out. but if a handful of things are all used together and change together, then they likely belong together

👍 8
lgessler19:05:17

excellent point, thank you. that performance matter is something I hadn't considered. That's probably the most important consideration in this particular circumstance since these subs are getting hit a lot