Fork me on GitHub
#re-frame
<
2017-09-14
>
gklijs06:09:46

I think it could be valid, if you either want less dependencies, or not one global state

mikethompson06:09:56

@sandbags @gklijs I always have the same response :-) You can absolutely use Reagent by itself if your application is simple enough. BUT if you just use Reagent by itself then you only have the V bit of an application. As your application starts to get more complicated, you *will* start to create an architecture which adds control logic and state management - the M and C parts (even if you don't think you are, you are). So then the question becomes: is your architecture better than re-frame's or not? And some people prefer their own architectures and would answer "yes" :-) Fair enough. I think the only danger arises if this process is not conscious - if someone creates a dogs breakfast of an architecture and doesn;t even know they've done it. I've had MANY people privately admit that's what happened to them ... and then they swapped to re-frame to get some structure back. So, my advice is .... if your application is a little more complicated, be sure to make a conscious choice around architecture, because one way or another you'll be using one.

gklijs06:09:37

@mikethompson good point, for a very basic website, I now even use neither, since even reagent feels like doing to much.

lxsameer11:09:43

@mikethompson i was talking to @danielcompton about the gitbook docs, is there any reason why you're not using such a tool ? 🙂

mikethompson11:09:15

@lxsameer No real reason other than ignorance :-)

mikethompson11:09:40

I'd very much like to improve the presentation of the docs

mikethompson11:09:12

For example, I'm painfully aware that "a line" of text shouldn't be wider than 70 chars for a good reading experience, etc

lxsameer11:09:21

@mikethompson i converted the re-frame docs to gitbook, to use the epub 😛 , if you're cool with it I can take care of it

mikethompson11:09:28

I'm certainly interested. But also cautious. What does it look like?

lxsameer11:09:47

@mikethompson let me show you a screenshot

lxsameer11:09:38

@mikethompson we can change the theme really easy

lxsameer11:09:46

but it's the default one

mikethompson11:09:04

I think that looks better than what we have

mikethompson11:09:38

Is it hard to build ?

mikethompson11:09:00

Tool chain wise

mikethompson11:09:06

I'm on Windows

mikethompson11:09:39

Hmm. gitbook looks commercial. But I assume they do something free for open source?

mikethompson11:09:03

Gotta go. But I'm cautiously interested.

lxsameer11:09:49

it would be easy to create a new theme ( there are plenty of them we can use )

lxsameer11:09:30

and there is no need to use the commercial service, I done that locally and also we can use the free plan since re-frame is opensource

lxsameer11:09:54

but in general it's quite satisfying, I'll make a PR later

saskia14:09:48

converting the re-frame docs to gitbook would be great! @daiyi I think this thread might be interesting to you!

vinai15:09:15

How do you provide the session login state to re-frame view components via a subscription? I could imagine querying an api and storing the result in the db, or maybe adding a non-http only cookie, but my feeling is those aren't the most elegant ways to accomplish that. (Currently the authorization is done via buddy with a ring session backend)

borkdude15:09:55

I have the following situation: component subscribes to sub1 click-handler dispatches event ev1 ev1 does optimistic update to db, sub1 should be refreshed and component should be updated ev1 also dispatches ev2, which does a URL navigation which triggers secretary to dispatch another event to do a request, eventually also updates sub1 the optimistic update doesn’t work, but when I comment out the dispatching to ev2 in ev1, it does work. What could be wrong?

reefersleep16:09:24

@borkdude could you provide the code for your ev1? I'm suspecting that you've got the ev2 dispatch in the tail position of your ev1, meaning that you're not returning your updated (with the optimistic update) app-db from ev1.

borkdude16:09:44

@U0AQ3HP9U Thanks. However, that’s not the issue. Code looks like this:

(reg-event-fx
 ::optimistic-update
 [(path db/page-id)]
 (fn [{:keys [:db]} [_ current-guid new-guid route]]
   (debug current-guid new-guid)
   (debug "OPTIMISTIC event" new-guid)
   {:db (let [article (get db ::db/article)
              article (assoc article :optimistic-guid new-guid)]
          (assoc db ::db/article article))
    :navigate route}))
where :navigate is an effect which navigates to the route

reefersleep17:09:00

Lots of stuff going on there, with some re-frame API usage that I'm not used to reading

reefersleep17:09:15

let me just see if I can understand it

reefersleep17:09:45

looks fine to me, but I don't have any experience with -fx event handlers

reefersleep17:09:01

so I don't know any particular traps in that area

reefersleep17:09:59

is everything in the "call chain" of events and subs following the :navigation fx called correctly?

borkdude17:09:44

It seems to work with dispatch-sync

reefersleep17:09:27

well, good! I have no idea why that would be.

reefersleep17:09:53

I don't know how dispatch-sync affects your event chain, or even if it does, apart from the first event

lxsameer15:09:34

I didn't change anything in the docs yet, we might need to change some minor stuff , like adding a cover or some image urls but in general it would be like this

lxsameer15:09:07

also adding a new theme is as easy as adding it to docs/build/book.json file

lxsameer15:09:18

let me know you thoughts on this

borkdude17:09:23

Maybe this is what I need dispatch-sync for, it seems to work that way

reefersleep17:09:48

@mikethompson do you have any idea of why that would be? dispatch-sync working for @borkdude in this situation, I mean

reefersleep17:09:20

I can't grok it from reading the docs on dispatch-sync

dobladez18:09:35

@vinai storing the session login state in app-db makes all the sense. Why do you feel it is not "elegant" ?

vinai18:09:16

Because I think I'll have to make an extra api call probably. Something like Login post -> Route captured by server -> redirect to route captured by frontend app -> query API to update login state. Hm, maybe not. I guess I can make the login post via ajax.

vinai18:09:55

Sorry, I guess it was a stupid question. I'm not very bright today #tired

dobladez18:09:12

certainly... pretty much everything on a reagent/re-frame app will be via "ajax", and you simply update the db on response

dobladez18:09:27

you still need something like local-storage if you want to remember the user's auth info across browser windows (or tabs)

vinai18:09:58

I'm persisting big parts of the db in local storage already, so adding the login state will not be an issue.

mikethompson22:09:50

@borkdude not sure I fully understand but ... thoughts ... > ev1 does optimistic update to db, sub1 should be refreshed and component should be updated Remember that (Reagent) component refreshes happen in the next animation frame. Potentially up to 16ms from "now". In the meantime, that further dispatch may have been processed Use of dispatch-sync might nudge the timings so things happen in a different order. Ie. there might be an animation frame already scheduled for 1ms from now, and by using dispatch-sync, the component refresh (together with subscription refresh) might happen "this cycle" (in 1ms) rather than "next cycle" (17ms) of animation frames. Or something

jfntn22:09:00

Is there a way to prevent a sub from getting disposed of when the watching component gets unmounted?