Fork me on GitHub
#re-frame
<
2018-07-12
>
ferossgp08:07:40

Hi! How is better to wrap a component with data fetcher in re-frame?

(defn with-fetch-table []
  (let [cached-filters (reagent/atom nil)
        cached-offset  (reagent/atom nil)
        this           (reagent/current-component)
        query-debounce (debounce re-frame/dispatch 1000)]
    (fn [{:keys [offset]
         :as   props}]
      (let [filters
            (select-keys props [:filter-1 :filter-2])
            query-fn #(query-debounce
                       [:graphql/query
                        {:operation-name "backoffice-fetch"
                         :refetch-on #{:table-row-remove} ;; re-frame-forward-events-fx 
                         :query (query/fetch-table
                                 (merge filters
                                        {:offset @offset}))}])]
        (when-not (= @cached-offset @offset)
          (reset! cached-offset @offset)
          (query-fn))
        (when-not (= @cached-filters filters)
          (reset! cached-filters filters)
          (reset! cached-offset 0)
          (reset! offset 0)
          (query-fn))
        (reagent/children this)))))
I use forward-fx for events that trigger re-fetching but I don't know how do to it for filters and pagination as in my example above. They are stored in simple ratom on the page, because I need them in local state only. Any best practices for such cases?

p-himik08:07:44

@ferossgp If I understand you issue correctly, there have been brief discussions about similar concerns in the past. It seems that mixing purely re-frame components (subscriptions for "data in", dispatches for "data out") with reagent/atom doesn't really work if you need the data from the ratoms somewhere else.

Drew Verlee12:07:07

i’m doing the walkthrough https://github.com/Day8/re-frame/blob/master/docs/CodeWalkthrough.md. I want to get cider through emacs to connect to a repl so i can eval the clojure in emacs. Normally i would do ‘cider-jack-in’ to have cider start a repl and connect to it. In this case, i’m i supposed to connect to a repl that figwheel is starting? I ask because any combination of cider-jack-in or cider-jack-in-clojurescript i try doesn’t seem to result in a working repl (I cant eval the cljs in emacs).

eggsyntax19:07:17

What's your cider-version? 0.18.0-SNAPSHOT is undergoing heavy churn at the moment which is potentially related.

p-himik12:07:00

@drewverlee I don't have an answer to your question, but the question should probably be asked in #cider, #emacs, or in #clojurescript.

valtteri14:07:41

@drewverlee lein new re-frame +cider gives you a functional starting point where you can just cider-jack-in-clojurescript and cider will launch a figwheel repl for you (along with clj repl). Check also this https://github.com/Day8/re-frame-template#start-cider-from-emacs-if-using-cider

valtteri14:07:50

It’s also possible to start figwheel repl outside emacs and make cider connect to it but it might be simpler to use cider-jack-in-clojurescript.

Drew Verlee14:07:23

Ah gotcha, so I should connect to the repl that figwheel started

dfcarpenter16:07:44

Can anyone point me to an example of a master/detail view with re-frame + bidi/pushy?