Fork me on GitHub
#re-frame
<
2016-03-02
>
surreal.analysis02:03:28

I know I’ve asked this in the past, but can’t seem to recall. If you want a simple string to populate an input and also be a part of the URL, does it make more sense to have :on-change call secretary/dispatch, or to call a handler along the lines of :set-input-string, and for that handler to set the secretary route?

surreal.analysis03:03:48

I ended up manually setting the URL, which triggers the secretary route, which dispatches reframe events, but that feels wrong to me. Any insight on how to properly set up changing URLs, re-frame events, and secretary would be appreciated.

surreal.analysis03:03:57

It seems to me that, from within the input box, I would want to have a function that dispatches the fact that the string changed, but the only way I can think of is simply writing 2 of each handler (e.g. set-variable-url, set-variable-actual)

mikethompson03:03:19

I like all mutations to go in event handlers

surreal.analysis03:03:27

I agree, but is my assumption that I need essentially 2 of each handler that changes the URL to deal with that? i.e. one to set the URL, which triggers secretary, that then sets the actual data?

surreal.analysis03:03:02

Or would you recommend disabling secretary hooking into the pushstate like that, and just update the URL and data in a single handler

surreal.analysis15:03:11

I ended up going with this:

(defn generate-url [db]
  (let [{:keys [query-string]} db]
    (str "#/" query-string)
    ))

(defn set-url [db]
  (aset js/window "location" (generate-url db)))

(re-frame/register-handler
 :set-query-string
 standard-middlewares
 set-query-string)

(re-frame/register-handler
 :update-query-string
 standard-middlewares
 (fn [db [query-string]]
   (set-url (set-query-string db [query-string]))
   db))
Where the view code dispatches update-query-string, which triggers a URL change, which causes secretary to dispatch set-query-string