Fork me on GitHub
#re-frame
<
2018-08-23
>
jonathanj04:08:03

@bhauman and thanks for all your hard work.

jonathanj05:08:24

Okay so my next question: I’m very familiar with Redux and my preferred approach is to export “dumb” components alongside my store-connected components, primarily because I can very easily write stories for these. It seems like re-frame often advocates for using subs/ratoms in the component definition, doesn’t that make the devcards approach more difficult?

jonathanj08:08:58

Seems like this is a fairly long-standing issue.

urbanslug11:08:01

can one use devcards with shadow-cljs?

thheller11:08:14

sure. why wouldn't you? (no clue about the re-frame stuff but devcards themselves work fine with shadow-cljs)

urbanslug11:08:57

hmm let me try that out

urbanslug11:08:15

I didn't see anything devcards related in the manual/docs is all

thheller11:08:34

its just a CLJS lib. the fulcro template generates a demo devcards config if you need one

urbanslug12:08:05

I assumed it was tied to leiningen like figwheel is

bhauman12:08:32

@urbanslug figwheel has not been tied to leiningen for years

bhauman12:08:50

it has a lien plugin but people have used it from a script and the repl for a very long time

bhauman12:08:19

I keep hearing this sentiment and I’m curious why folks think this

bhauman12:08:56

@jonathanj devcards renders any react elements that you provide it with

bhauman12:08:37

it will be hard to participate in the built in data display for the card

bhauman12:08:53

but you can create a separate card to display global data

jonathanj12:08:02

@bhauman Yeah, it seems like this issue leans much more to re-frame than devcards, specifically decisions around global state etc.

jonathanj12:08:32

Some of the workarounds are things like iframes to segregate instances, a bit yuck.

bhauman12:08:05

not really worth it better off to create components that accept some kind of state and hand it to them

jonathanj12:08:29

I think my approach would be to mimic my Redux workflow: Have a very dumb foo-view component that has no subscriptions and have foo be the re-frame-connected version.

bhauman12:08:30

but I really haven’t used re-frame so

bhauman12:08:43

exactly that’s what I would do

bhauman12:08:05

keep it super simple, and don’t fight things

jonathanj12:08:27

@bhauman Appreciate the input.

bhauman12:08:27

no worries, I’m hoping that we can sometime figure out a way to make working with re-frame more straightforward

👍 4
bhauman12:08:39

the same for devcards

bhauman12:08:15

it should be easier to start using these things

jonathanj12:08:48

I got a whiff of trouble when there was no devcards profile for the re-frame lein template, so yeah it would be nice to have devcards and re-frame working together out of the box like that. One day.

mikethompson12:08:27

@jonathanj I wish I had more time to make it happen. Stuck like this at the moment https://github.com/Day8/re-frame/blob/master/docs/EPs/002-ReframeInstances.md

👍 4
bhauman12:08:17

@mikethompson glad to know this is on your radar 🙂

jonathanj12:08:29

I’m very re-frame green, but my experience wrestling with this with React and Redux was that I didn’t actually want storybook to know anything about Redux. I don’t want to have to create a store, put some state in it, wrap my stories in providers, etc. just to have a component showcase.

jonathanj12:08:16

All the callbacks are replaced with a storybook action() that just logs something to the storybook, so nothing actually does anything it just confirms the contract the component (apparently?) adheres to.

jonathanj12:08:40

I don’t know if some kind of optional (binding)-type thing might be sufficient to wrap a re-frame component in some suitable local universe? Unfortunately I don’t know what Frames are, so meaningful commentary is probably at least one deep dive away.

jonathanj12:08:54

I think the way I would want my re-frame devcards to work would be to have some kind of events log bundled into the card that corresponds to all the stuff the wrapped re-frame component dispatches. Maybe even listing what it’s subscribing to too.

bhauman12:08:57

@mikethompson Solution sketch #3 looks promising and we could create a devcards card that provides this frame id and displays the frame state

bhauman12:08:53

@jonathanj I would take some time and explore some of the things that devcards does, and recognize the differences from storybook. IE you can display the same component in different states on the same page and work on them in parallel. and many many more features that fundamentally depart from storybook

bhauman12:08:29

And it shouldn’t be difficult to create a component that does anything you want to do because in the end devcards simply renders react

jonathanj12:08:39

I’d like to explore that, my time is a bit limited at the moment for it unfortunately.

bhauman12:08:41

I guess I’m just saying don’t come to it with too many preconceived strategies before giving it a try 😉

bhauman12:08:58

as its quite a bit different

bhauman13:08:02

but thank you for pointing out storybook as I’m going to really give it a try to see what its bringing to the table

jonathanj13:08:13

devcards is definitely much more flexible, which is great. Part of what is appealing about storybook is it’s narrowed focus and stronger commitment to that narrow focus (with things like the action logger, etc.) I think it ought to be pretty easy* to build something nicer than storybook with devcards, for pretty much all the reasons you’ve mentioned.

bhauman13:08:29

loving the * on “pretty easy”

bhauman13:08:46

that dang phrase 🙂

jonathanj13:08:21

If it was possible to do something like (binding [*re-frame/global-app-db* (…)] (some-reframe-component …)]) (which I think is the ignorant-person’s version of Frames etc) you could trivially trap re-frame events and build a little self-contained IDE-esque devcard.

jonathanj13:08:44

The thought has me itching to get started! 😂

bhauman13:08:24

yeah bindings don’t work because effect handlers will probably escape the bindings at some point

Julien Fleury13:08:41

Do someone know a library to use websocket from both sides (messages from server and from clients) ? ftravers/reframe-websocket only allow client -> server -> client

urbanslug13:08:12

maybe because it was called lein figwheel? 😄 > I keep hearing this sentiment and I’m curious why folks think this

iperdomo16:08:02

Hi all, what's the best way to deal with async API call and coeffects? I'm trying to write something similar to https://github.com/gothinkster/clojurescript-reframe-realworld-example-app/blob/master/src/conduit/db.cljs#L44-L50 ... in this code, getting a logged user from localStorage involves a synchronous api call, we can just assoc ... In my case, I'm trying to get a user session via AWS Cognito JS SDK, that is async ... https://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito-user-identity-pools-javascript-examples.html#using-amazon-cognito-identity-user-pools-javascript-example-retrieving-current-user

iperdomo16:08:05

what i'm trying to do is to have some interceptor to check if the user is logged in and the session is valid .... if not, redirect to the login view ... is this the right approach to solve this? :thinking_face:

Drew Verlee16:08:54

is it possible to call a reframe event handler directly? if so, how? i can dispatch, but that doesnt take the db as an argument. just for debugging*

Drew Verlee17:08:41

thanks ill take a look

lwhorton17:08:06

before I go digging into the reframe internals to write my own reg-fx function, i’m looking for a way for a registered fx to be handed two arguments, (fn [the-cofx-map the-app-db]) where currently they are only handed the cofx map. does something liket his already exist?

urbanslug17:08:38

I have such an event: and I need it to run every x time at the core of my app. Basiclally client server sync. I'm making the request

(rf/reg-event-db
 ::get-some-data
 (fn [{:keys [db]} _]
   {:http-xhrio {:method           :get
                 :uri              url
                 :timeout          8000
                 :with-credentials false
                 :on-success       [::add-data]
                 :on-failure       [::api-request-error :get-data]}
    :db (assoc db :loading? true)}))

urbanslug18:08:12

issue is it seems to freeze, doesn't make the request

urbanslug18:08:35

the http-xhrio event isn't being triggered for some reason

urbanslug18:08:40

but loading is set to true

urbanslug18:08:22

Oh my should be reg-event-fx

urbanslug18:08:33

Oh it says :response-format (ajax/json-response-format {:keywords? true}) ;; IMPORTANT!: You must provide this.

jmclavijo19:08:14

Edited: Are there any re-frame/reagent engineers that are looking for work? Someone who has a good grasp on react, front-end dev, and creating Server Side Rendering. There’s already a react template that we want to use and modify so as to not to start from scratch

urbanslug20:08:39

@jclavijo I didn't understand that second part of your question

🤪 4
⚙️ 4
zalky21:08:27

I find re-frame-async-flow-fx super useful. I was thinking it would be nice to be able to dispatch re-frame events with no expectation that they be handled. These events would just serve as a signal for asynchronous processes. I often find myself defining :action/success handlers that don't do anything for this purpose. It would be convenient to be able to just add a ^:no-op metadata to a dispatched event, and have it technically dispatched, but not throw a handling error. Does this make sense as a feature? Is there another pattern with re-frame-async-flow-fx that I'm unaware of?