Fork me on GitHub
#re-frame
<
2016-08-09
>
escherize00:08:24

On the re-frame SNAPSHOT, I'm getting strange behavior from the debug interceptor. Here's it's output: http://take.ms/EijOc

escherize00:08:58

only before: is showing what is being navigated into by the path middleware, but only after: is showing me the whole app-db.

escherize00:08:35

Here's the register:

(rf/reg-event-db
 :cat/update-response-test
 [rf/debug (rf/path :categorisation :test-response)]
 (fn [tr [_ field new-value]]
   (assoc tr field new-value)))

johanatan03:08:00

Hi, is it possible to create an ratom from a subset of a map stored in another ratom? say, for example, one section of app-db ?

johanatan04:08:01

I suppose it could be done with a reaction which has the path to the subset of interest embedded within it

johanatan04:08:11

But what happens when you do swap! on a ratom that is the result of a reaction ?

johanatan04:08:05

i.e., it would need to be R/W; not just R

danielcompton04:08:48

@johanatan: I think a cursor might be what you’re after?

johanatan04:08:23

Mm, yes that sounds right. Is that a re-frame or reagent thing?

johanatan04:08:13

Ahh cool. Thx!

mikethompson06:08:34

@escherize: I can't see any problem with debug here. Seems to be working as intended. I've pushed another SNAPSHOT, because I can't remember the last time I did.

mikethompson06:08:40

Does it improve things?

escherize06:08:15

I'll take a look. Do you recognize the issue I see in the image of my dev console above?

escherize06:08:19

the stiring at (-> app-db :categorisation :test-response :body) changed from "a xxx " to "a xxx b". I expected debug to say "Here's the old db, heres the new db" Or: Here's the first constrained view of the db, here's the new constrained view of the db.

escherize06:08:58

what happened was: "Here's the old constrained view of the db, and the new view of the entire db" Maybe that is expected behavior though?

mikethompson06:08:36

debug uses https://clojuredocs.org/clojure.data/diff to calculate what it displays.

mikethompson06:08:31

So that screenshot is saying ... 1. The stuff in "only before" was removed 2. The stuff in "only after" was added

mikethompson06:08:03

(Not saying if that is right or wrong)

mikethompson06:08:00

I'm just fiddling around with debug and path in todomvc to make sure when appear to be interacting correctly

mikethompson06:08:45

If there is a problem it is more likely to be path that's the problem

mikethompson06:08:04

Any change with the latest SNAPSHOT?

escherize06:08:37

I need to restart figwheel just a sec

escherize06:08:07

but also, the stuff in "only before" wasn't really removed, right? the thing that changed was one value in that map.

escherize06:08:40

and if you were going to say that the map should change when a value changes in it... then "only before" has to contain the entire app-db (or maybe context?)

mikethompson06:08:55

Hmm. Looking into it further.

escherize06:08:09

does that make sense?

escherize07:08:23

yeah I think you may be right that the path interceptor was suspicious.

mikethompson07:08:57

Give me 10 mins. There's something wrong with path

mikethompson08:08:33

Ahh. Now I get it. There's a certain interplay between debug and path - but only if debug is before path in the interceptor chain.

mikethompson09:08:40

Fixed and new SNAPSHOT up on clojars. In my code, I put debug interceptors to "the right" of path in an interceptor chain. Which is why I hadn't tripped over this interaction.

mnewhook11:08:58

has anyone done an accordion stuff with re-frame? Like on http://getbootstrap.com/javascript/#popovers?

shaun-mahood15:08:39

I'm thinking of putting together a proposal for a re-frame presentation at Clojure/Conj, I'm just at the ideas stage at this point. Is anyone here interested in giving input or reviewing as the talk develops, or do you have anything particular you would like to see in such a talk?

fenton18:08:34

Reframe seems to be reactive primarily from a UI perspective. That is subscriptions only react when they are tied to a a react-ui component. However, there are plenty of use-cases that aren't UI centric but could benefit from a reactive framework. For example calling a back-end service to fetch additional data. My other comment is that I'm not sure how I can react to multiple data-paths. For example: do a backend service only after the user is logged in AND their GPS coordinates are established. The dispatch mechanism sets one value at a time. The subscribe only works for UI, and is triggered in a singular sense, not by any combinatorial conditions of data. Just curious if others have these issues and if reframe has mechanisms to deal with them.

fenton18:08:20

Or are these concerns that should be dealt with elsewhere?

shaun-mahood19:08:37

@fenton: I think you have a bit of a misconception for how re-frame subscriptions work. Subscriptions in re-frame are tied to a piece of data in your app-db, not the state of the UI itself or anything related to the react components of your UI, so you can subscribe to a piece of data that has no effect on your UI.

fenton19:08:05

@shaun-mahood: oh really. i guess i tried it in the past and i thought it didn't run, but only ran when tied to a piece of UI. I'm very glad to be mistaken!

fenton19:08:30

I'll have to test that again!

shaun-mahood19:08:14

It definitely takes some getting used to - the most effective thing I did when learning was to put in a very simple "Print app-db" button in the top menu of my app during development that just logged out to the console - I think there are some way better ways to do it now, but it helped me to understand the effects of my changes as I was figuring things out.

fenton19:08:37

I may have messed things up by my defining of :set and :get, but they work for UI stuff, but the following didn't create any console log output?

fenton19:08:46

I have to pick up nephews in 10 minutes....but I'm very interested in this discussion... I'll be back after baby-sitting for sure if i dont resolve before that cutoff! 😞

shaun-mahood19:08:37

As far as combinatorial conditions and fetching additional data, I broke all of those down conceptually into individual event handlers and set up some additional checks and data points to make them easier to reason about. I added some additional keys to track my state for some of the more complex areas or that were specific to particular workflows - in the new release it looks like there will be a :dispatch-n option for sequential events (https://github.com/Day8/re-frame/blob/311367dc3d2189c148464886f5ef2c9de473480d/src/re_frame/fx.cljc#L65), though that is more on the event processing side.

shaun-mahood19:08:11

@fenton: Happy to pick up the conversation later

fenton19:08:25

@shaun-mahood: thanks...I'll take u up on it. The non-UI reactions stuff will be very helpful if I can get it to work! 🙂

shader20:08:09

any reason dispatch couldn't just be variadic? It's already assuming that each set of event args is already a single seq, so it wouldn't be hard

shader20:08:55

@fenton that's something I'm interested in too; mostly I'm thinking we need a way to lift the 'behavior' style r/atoms into actual sequences of events. The 'auto-refresh' model of event propagation in re-frame is very nice and easy to use, but only works in a custom execution environment like that provided by reagent in the ui

mikethompson20:08:17

@fenton @shader Rich Hicky has said that Clojure is 80% functional (compared to something like Haskell which is much closer to 100%). Along the same lines, I'd say that re-frame is 60% reactive (compared to something like Cycle.js which tries to make everything reactive). re-frame apps are fundamentally event driven systems. Things like user clicks and data services callbacks all end up as events. And at that point they should be handled by event handlers and their interceptors/middleware. At that point we are not in a "reactive space", we are in a "mutative space".

mikethompson20:08:32

Mutations are a bit of a nightmare, so we benefit from applying some order and structure to the process.

mikethompson21:08:02

I believe you are craving for a means to create internal events. Above, I talked about events being "user clicks a button" or "websockets delivers some data". These are events triggered from the outside - external events. In contrast, think what you are asking for is some way to generate internal events. Like having a rule which says: because path x and y within app-db changed then generate a new event (which will do its own mutation). re-frame currently has no direct support for this, however it has the building blocks to allow you to create it yourself. The on-change middleware/interceptor should act as a template. Steps: - wrap the event handlers which can mutate path x and path y in an interceptor - that interceptor looks to see if they have changed - if they have changed then dispatch an (internal) event. In this way you get a nice "audit trail" of mutations. Everything happens because of events.

mikethompson21:08:17

So ... while I absolutely love reactive flows, I think they have their place. At this point, I'm not in the cycle.js camp of making everything reactive.

mikethompson21:08:36

(Although I reserve the right to change my mind on everything, at any time :-))

escherize23:08:22

@fenton: your subscription called data won't work like that. For it to update in that manner it needs to be a part of the UI - that must be what you meant with your assumption that subscriptions require being loaded into the ui to work. Do notice that @(subscribe [:get [:abc]]) in the repl (or in a top level form) would give you the data at that time.

escherize23:08:10

Only defining a function isn't enough to dereference that subscription when it changes.