Fork me on GitHub
#re-frame
<
2016-06-16
>
conaw05:06:52

@mikethompson: how would one go about doing that?

conaw05:06:14

From your undo/redo post, seems like you’d have to do some prep work to store past versions of database because we’re using swap!’s

mikethompson05:06:47

Do you use debug middleware ?

mikethompson05:06:58

It side effects.

mikethompson05:06:07

It writes to console

mikethompson05:06:22

So via middleware you can capture anything.

mikethompson05:06:51

undoable is middleware too

mikethompson05:06:26

All the work is in the chrome extension. Getting the necessary information out of re-frame is pretty easy

nilrecurring11:06:23

I don't know if this is a re-frame-only issue, but I'll ask here, maybe someone can help me figure it out: is there any way using re-frame to route something on load?

nilrecurring11:06:43

What I mean is that if there is a url already set at the loading of the page (that would normally be routed after a url change) the main page gets loaded in any case (that is, the routing is not working until the url changes)

nilrecurring11:06:59

This is my core.cljs:

(secretary/set-config! :prefix "#")
(defroute "/"   []    (dispatch [:view-id ""]))
(defroute #".*" [id]  (dispatch [:view-id id]))

(def history
  (doto (History.)
    (events/listen EventType.NAVIGATE
                   (fn [event] (secretary/dispatch! (.-token event))))
    (.setEnabled true)))

(dispatch-sync [:initialize-db])
(println "Starting render!")
(r/render [my-ns.views/app]
          (.getElementById js/document "well"))

nilrecurring11:06:11

(yes, I'm using secretary)

nilrecurring11:06:03

The main use case for this is to be able to use URLs to link to content into the app

mikethompson11:06:33

@nilrecurring: The re-frame todomvc example correectly interprets the URL (on app load)

mikethompson11:06:45

It uses secretary

mikethompson11:06:54

The URL encodes the selected filter control at the bottom of the page (one of all, completed, active).

martinklepsch12:06:18

Just implemented this for a firebase app https://github.com/Day8/re-frame/wiki/Subscribing-To-A-Database — now this seems to redundantly establish listeners when reloading, how do you make sure on-dispose is called when reloading?

nilrecurring12:06:46

@mikethompson: yes exactly, I started from there and edited

nilrecurring12:06:10

So I guess the issue is in the second defroute

nilrecurring12:06:55

The thing that is driving me crazy is that it works on url change (so it's working), but not on app load

nilrecurring12:06:43

(and the id is an arbitrary string that may or may not be present in an hash-map)

nilrecurring13:06:16

@mikethompson: investigating more: I got rid of the regexp on the defroute, using destructuring now. Now it works correctly after a figwheel reload (so I load the page and the routing doesn't work, I save the file and on figwheel reload the routing works correctly)

nilrecurring13:06:17

Logging stuff into the rendering function in the views.cljs it seems that the routing kicks in before the app is ready, so I log something like this:

id: 575430df6ff9f07b8b012333
Starting render! 
Loading the app...

nilrecurring13:06:38

With this routing function

(defroute "/:id" [id]
          (do (js/console.log (str "id: " id))
              (dispatch [:view-id id])))

rnandan27313:06:39

i wanted to use datascript in a re-frame app, and the only way i could get the subscriptions to work was to populate sink the data in app-db from datascript queries in the handlers. Is the right way? Can datascript be used to hot load browser localstorage?

conaw15:06:28

Anyone got an example of a subscription with multiple ratoms, I’ve heard it can be done

mccraigmccraig15:06:08

what dyu mean by "multiple ratoms" @conaw ?

conaw15:06:02

This ticket is about subscription definition, but let's remind ourselves about use:

   (subscribe [:query-id 1 2 3] [r1 r2])
The 1st parameter is the query vector, which starts with the query-id (generally a namespaced keyword). The 2nd parameter is a vector of input signals (ratoms/reactions). When they change, the subscription should be rerun.

Most subscriptions only involve one parameter. Many re-framers don';t even know about the 2nd.

conaw15:06:48

Before reading this, I was one of those re-framers who didn’t know about the second, I wish to no longer be

conaw15:06:05

especially since I’m working with two ratoms, a datascript db and an app-db

mccraigmccraig16:06:16

@conaw: the second parameter is for dynamic subscriptions - for passing parameters to a subscription when those parameters are already wrapped in a reaction - here's an example subscription using the second param https://www.refheap.com/07cd87724b6bd330fc66b06e7 - you should be able to pass any reaction or ratom like things in there

conaw16:06:49

no need to deref the second ratom?

conaw16:06:27

(register-sub
  :todo-dynamic
  (fn todo-dynamic [_ _ [active-list]]
    (let [q (q/get-query active-list)]
      q)))

conaw16:06:31

is that a type

conaw16:06:51

it doesn’t need the db, or the other vector

conaw16:06:25

so obv no need to do (fn [ [] [active-list]] ….)

conaw16:06:50

cool, much appreciated

ckirkendall21:06:33

What is a clean what to have a “subscription” or data change dispatch to handler if it detects a change. This is outside of a component.

ckirkendall21:06:03

Here is a description of what I am trying to do. The base part of the app has a search bar that can affect many different areas of the application. The code is isolated in base/handlers.cljs and handles setting the db to the correct search term. Now for the panel that is active I might need to also trigger some logic when the search term changes like reseting the current page to 0 and starting a search again. The panel logic is in panel1/handlers.cljs what is the best way to trigger my hander code in panel1 when the search term in the db is updated by the base/handlers.cljs.

ckirkendall21:06:40

I am trying to avoid coupling the base code and the panel code.

nilrecurring21:06:42

@ckirkendall: in the handler function that updates the search term in base/handlers.cljs I would further dispatch to a function in panel1/handlers.cljs that keeps the search term in sync in the local db

ckirkendall21:06:39

That couples the base code to the panel and in this case all panels since the search scopes sub panels. That is what I am trying to avoid.

nilrecurring21:06:27

I can't see an alternative honestly 😕

ckirkendall21:06:22

yeah I am struggling coming up with something clean

snoe21:06:17

@ckirkendall: we're doing something similar, we take a couple strategies. We either dispatch to the base handler from the panel handler or pass a "callback" dispatch key to base. (rf/dispatch [:base/search [:panel/search]])

ckirkendall21:06:02

There is something in the core that allows me to add-post-event-callback

ckirkendall21:06:13

It sounds like what I am looking for.