Fork me on GitHub
#untangled
<
2017-05-23
>
pedroteixeira00:05:29

hi, is there an easy way to define a custom parser function for om.next? would have to impl a new UntangledApplication right?

currentoor11:05:24

@pedroteixeira untangled makes a lot of the client state decisions for you and provides an appropriate parser function so all you have to write is the mutations.

pedroteixeira20:05:30

currentoor: I was trying to think of ways to implement routing, and would need ways to plugin custom read functions for some keywords (not being looked up directly in app state), not sure if this can achieved in untangled

currentoor20:05:15

@pedroteixeira what sort of routing? like url routing or app state routing?

pedroteixeira01:05:57

@U09FEH8GN sorry, I meant url routing. I think I saw somewhere someone solving on the parser (query would return something conditionally on current route for ex) rather than using union queries on top component. still digging into design patterns here, still unsure on best way to go for current proj with cljs+react. I thought about implementing UntangledApplication, to better underestand Om.next first

currentoor13:05:38

@pedroteixeira oh I see, well we bidi with app state to do url routes, our route structure looks like this

(def routes
  ["/"
   {"beta"      :beta/index
    "templates" {"" :templates/index
                 "/"
                 {""                                :templates/index
                  [[keyword :template-type] "/new"] :templates/new}}
    "reports"   :reports/index
    "dashboards/"
    {""                  :dashboards/index
     "new"               :dashboards/new
     [[id+ :id] "/"]
     {""               :dashboards/show
      "copy"           :dashboards/copy
      "edit-schedule/" :dashboards/edit-schedule}
     [[id+ :id] "/edit"] :dashboards/edit}
    ""          [[true :dashboards/index]]}])

currentoor13:05:48

then we just store the keyword route value like :dashboard/new in app state and make rendering decisions based on it

currentoor13:05:47

then we use pushy to do the url magic

(defn navigate [{:keys [page params replace?] :as route}]
  (if history
    (let [route           (url->route js/location.pathname)
          current-handler (:handler route)
          current-params  (:route-params route)
          navigate*       (if replace? pushy/replace-token! pushy/set-token!)]
      (when (or (not= page current-handler)
                (not= params current-params))
        (navigate* history (route->url page params))))
    (log/warn "History API not available, ignoring route request" route)))

(defn navigate-url [{:keys [url replace?]}]
  (if history
    (let [navigate* (if replace? pushy/replace-token! pushy/set-token!)]
      (when (not= js/location.pathname url)
       (navigate* history url)))
    (log/warn "History API not available, ignoring route request" url)))

(defn mount [comp]
  (when-not history
    (let [update-fn (fn [{v :handler p :route-params :as route}]
                      (let [route-handler               (handlers v)
                            {:keys [mutations post-cb]} (if route-handler
                                                          (route-handler p))
                            route-action                `[(route/update {:page ~v :params ~p})
                                                          (modal/close)]]
                        (om/transact! comp (vec (concat route-action mutations
                                                        [:ui/current-route :ui/modal-open])))
                        (if post-cb (post-cb))))
          listener  (pushy/pushy update-fn url->route)]
     (set! history listener))))

(defn start  []
  (pushy/start! history))

(defn stop []
  (pushy/stop! history))

currentoor13:05:08

seems to work well with untangled

pedroteixeira22:05:02

thanks for the examples!

claudiu20:05:41

Is anybody using untangled-om-css ?

claudiu20:05:26

In dev & simple mode works well but for advanced I get everything like <style>.#object[hW "function hW(){React_Component_apply(this,arguments);this_state=null!=this_bc?this_bc():{};return this}"]__h3

tony.kay20:05:42

@claudiu I know there are users of it.

tony.kay20:05:04

I’m working right now with @timovanderkamp on some improvements.

tony.kay20:05:13

rather, he is doing them, and I’m advising

tony.kay20:05:03

not sure why advanced compile would be a problem.

claudiu21:05:20

🙂 just one of those days. Probably a small mistake on my part, but can’t really seem to tack it down.

timovanderkamp21:05:16

@claudiu are you using the helper function upsert-css? Not sure if it would make a difference but you could try to emit a dom/style element yourself.

timovanderkamp21:05:58

Both methods are described in the readme of untangled/om-css