Fork me on GitHub
#re-frame
<
2018-04-06
>
aleksandr07:04:20

Hello! Could anyone help me please? I wrote a cljs project. It is a reagent component on the re-frame. I require this project from :dependencies in a project.clj. But I have a problem. If a project where I require my component is written on the re-frame too, then an app-db this two projects mix with each other. I think It is not quite right. What should I do in this case?

tomaas08:04:18

Hi in a reg-event-dbhandler i need to use data which might not be fetched yet? What pattern should I use?

tomaas08:04:49

For example: there are a list of items, clicking on one of those dispatches an event :some-event which uses items data in its handler and as well as sets the url to /item/3. The problem would appear when the page is reloaded in that url /item/3.

gklijs08:04:44

you’re probably creating a spa, and need to use something like secretary https://github.com/gf3/secretary to do changes to the url. Then when the url changes you can send a request to get item 3, and change the db on the response, which might trigger a re-render

tomaas08:04:25

core.cljs calls (routes/app-routes) before any server data has been fetched. I have (defroute "/item/:id" (re-frame/dispatch [::some-event id]))

javi09:04:37

@al.vyguzov i am doing that currently (live editor built in re-frame, examples written in re-frame....) and the solution that is working for me so far is namespacing the db / subs and events.... I am today looking at making some middleware to "automate" this

aleksandr09:04:00

@fj.abanses Thank you! I decided keep my add-db under the :swipe-component key

aleksandr09:04:19

So in another project It will be seen under :swipe-component key

javi10:04:37

@al.vyguzov πŸ™‚ same here... let me know if you come up with an "automated" solution... i am looking into it myself

aleksandr10:04:05

@fj.abanses Ok! I know that it isn`t best solution, but I wrote interceptor

(def add-swipe-component-key
  (re-frame.core/->interceptor
    :id      :add-swipe-component-key
    :before (fn [context]
              (assoc-in context [:coeffects :db] (:swipe-component (:db (:coeffects context)))))
    :after  (fn [context]
              (let [db (:db (:effects context))]
                (-> (update context :effects dissoc :db)
                    (assoc-in [:effects :db :swipe-component] db))))))

aleksandr10:04:55

Right now that solution solve my demands. Later the better idea will come may be

aleksandr10:04:24

Oh, I miss a mistake here. Sorry

aleksandr10:04:35

You need dissoc all your project keys in app-db here. Not good solution πŸ˜•

MegaMatt20:04:03

would it be possible to make a javascript jsx port of reframe? I like re-frame a lot but my day job is probably going to be js for the foreseeable future.

😒 8
gklijs20:04:10

@matthewdaniel I think I read somewhere it already exists, there it is http://karolmajta.github.io/reframe-js/

4
gklijs20:04:05

It's old though, but at least it's possible

theeternalpulse20:04:53

this is a fairly new project that seeks to bring all the great data-centric ideas from clojure to JS

MegaMatt20:04:11

i'll take a look

theeternalpulse20:04:09

granted it's not jsx based, all data similar to re-frame

theeternalpulse20:04:19

there's a hiccup templating system in there

MegaMatt20:04:29

wow, that looks like a good article

theeternalpulse21:04:20

Yeah, it's one of the few articles I feel is aimed at the JS web dev crowd about how clojure devs do things, in addition to web development

theeternalpulse21:04:45

Not cloaked in functional mysticism that we're known for πŸ™‚

danielcompton22:04:14

Also I've heard that redux has a similar architecture pattern to re-frame

theeternalpulse22:04:09

react + redux => re-frame with some improvements from what I've seen. The state is first class, while redux can get messy when your app is bigger than a demo

theeternalpulse22:04:08

and I mean reframe has the improvements πŸ™‚

danielcompton23:04:30

I'd agree with that πŸ˜‰