untangled

NEW CHANNEL: #fulcro
pedroteixeira 2017-05-23T00:47:29.240103Z

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

currentoor 2017-05-23T11:56:24.922865Z

@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.

currentoor 2017-05-24T13:32:38.916856Z

@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]]}])

currentoor 2017-05-24T13:33:48.941729Z

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

currentoor 2017-05-24T13:35:47.983973Z

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))

currentoor 2017-05-24T13:36:08.990954Z

seems to work well with untangled

๐Ÿ‘ 1
pedroteixeira 2017-05-27T22:50:02.062726Z

thanks for the examples!

claudiu 2017-05-23T20:09:41.577487Z

Is anybody using untangled-om-css ?

claudiu 2017-05-23T20:10:26.593123Z

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

pedroteixeira 2017-05-23T20:19:30.773026Z

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

currentoor 2017-05-23T20:20:15.788416Z

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

tony.kay 2017-05-23T20:28:42.962760Z

@claudiu I know there are users of it.

tony.kay 2017-05-23T20:29:04.970320Z

Iโ€™m working right now with @timovanderkamp on some improvements.

tony.kay 2017-05-23T20:29:13.973455Z

rather, he is doing them, and Iโ€™m advising

tony.kay 2017-05-23T20:30:03.990811Z

not sure why advanced compile would be a problem.

claudiu 2017-05-23T21:01:20.625556Z

๐Ÿ™‚ just one of those days. Probably a small mistake on my part, but canโ€™t really seem to tack it down.

timovanderkamp 2017-05-23T21:20:16.979688Z

@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.

timovanderkamp 2017-05-23T21:20:58.992441Z

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