Fork me on GitHub
#re-frame
<
2018-04-28
>
soulflyer04:04:23

Looking for advice or (simple)examples to follow. I just wrote a tree thingy for use with reframe for use like a file system explorer. I would like to extract it from my project so its easier to use in other projects. Currently it's spread across 4 files, tree.clj where the basic mechanics live, project-tree-clj where I build my specific instance, a couple of events in my events.clj file that handle fetching the data for the tree and toggling visibility of nodes and then the display part in views.clj. I probably only want to extract tree.clj and the toggle node visibility event. How do people handle things like this? It's not complicated, I'm not writing a whole library, just a component I'm pretty sure I'm going to re-use in other things.

eoliphant12:04:32

Hi, @soulflyer I’m actually going through this process myself with a form library I built out in one of my projects. The great thing is that at the end of the day, it’s all just clojure(script). Without seeing your specific code, I think generally you can just create a library project that just has the tree.clj and event.clj (personal note: i’ve started creating events_subs.cljs namespaces myself, as I find it easier to keep related one together as opposed to jumping back and forth), have tree.clj require events.clj and that should pretty much be it. You might want to consider using say namespaced ::myevent keywords for events/subs to ensure their names don’t collide with keys in the apps you pull the lib into

soulflyer02:04:44

@U380J7PAQ Thanks, that's the kind of thing I was looking for. Since I asked I have come across a number of things that would vastly improve my code. Most notably specter zipper navigators. Currently considering a restart, which I guess would be a golden opportunity to build it as a separate library.

eoliphant03:04:28

@soulflyer yeah specter is frigging amazing

👍 4
eoliphant17:04:15

That’s great stuff @robert-stuttaford

😊 4
eoliphant21:04:17

Hi, I’m trying to figure out how to handle a scenario that seems like it needs ordering , but probably doesn’t. I’m using a 3rd party authentication service. After you get redirected back to your page, there’s a callback that gets fired with your jwt token, etc. So i have an event-fx that maps to a db update, and another effect that I created to add the idtoken to the ajax-cljs list of interceptors, i also need to query the server about the user. So I need to, from this event-fx, return an http-fx in the map, but, that” interceptor setter” effect needs to have been called first

Geoffrey Gaillard07:04:25

Hum… I suggested async flow fx, but just noticed you mentionned it previously in this thread. Why isn't async flow fx adapted for this use case ?

eoliphant13:04:33

Well one thing is that async flow fx uses event to walk through the state machine. I didn’t know if it was ‘ok’ for an effect, to in turn dispatch new events

👍 4
nenadalm14:04:21

I am using dispatch-n effect when I need to do stuff which needs to be in order (e.g. set jwt token to local storage + db and then request page data for which there needs to be the token present).

eoliphant19:04:01

Yeah, the problem though, is that dispatch-n doesn’t make any guarantees AFAIK in terms of ordering, if say :event-1 gets held up, :event-2 will go on its merry way without whatever setup event-1 was doing. I tried something like that and it works ‘most of the time’ lol.

eoliphant00:05:04

Ah yes the dispatch is in order but they are async