Fork me on GitHub
#re-frame
<
2016-07-30
>
mikethompson01:07:48

@danielpquinn: subscriptions used within a view component (reagent) will be correctly unsubscribed when that (reagent) component no longer exists. But if you just call subscribe outside of a view component, then yes the subscription will not be gotten rid of.

danielpquinn01:07:17

@mikethompson In that case, what is the best way to access values in my app-db outside of my view code? Is that an anti-pattern?

mikethompson02:07:44

event handlers are given db as a argument

mikethompson02:07:12

And they return the mutated version of it.

danielpquinn02:07:45

okay cool, I suppose I could put this piece of code in an event handler, but it might not mutate the db depending on whether values are valid.

danielpquinn02:07:48

thanks for your help!

danielpquinn02:07:12

Maybe I should put the validation code in middleware?

danielpquinn02:07:22

I’ll keep digging around 🙂

mikethompson02:07:29

We sometimes use enrich (middleware) for that purpose

danielpquinn02:07:46

I’ll have to google that one, thanks for the tip

mikethompson02:07:24

The idea is that you attach enrich middleware on every event handler which might cause a change to the state which needs to be validated. If the enrich middleware finds an error it assocs error details into db (or disassoc if no validation errors found). The view code responds the existance of "error details" in db and renders the necessary view.

danielpquinn02:07:32

that sounds like a sensible approach. I’m still getting used to keeping everything in a global state structure

danielpquinn02:07:02

wouldn’t have thought to put error details into that state object

mikethompson02:07:04

This does keep everything in app-db.

mikethompson02:07:46

I'm slight confused, your last two comments seem to contradict

danielpquinn02:07:33

Sorry, it was probably my wording. I think we’re on the same page 🙂

mikethompson02:07:36

Just to be clear enrich allows you to post process db ... after an event handler has run.

mikethompson02:07:46

Perfect spot for validation