untangled

NEW CHANNEL: #fulcro
adambros 2016-11-03T00:00:34.003609Z

well so in other news, i have added untangled-system with tony’s guidance to 0.6.3-SNAPSHOT which just lets you handle the ring middleware stack

currentoor 2016-11-03T00:00:39.003610Z

we have a router that supports route change mutations and post-route change call backs

:templates/new   (fn [{:keys [template-type]}]
                      (let [dash (:dash (generate/template template-type (state/current-user)))]
                        {:mutations `[(dashboard/new ~(assoc dash :template? true))
                                      (dashboard/open ~dash)]
                         :post-cb   #(navigate {:page     :dashboards/show
                                                :params   {:id (:id dash)}
                                                :replace? true})}))
using bidi

currentoor 2016-11-03T00:01:00.003611Z

sorry to interrupt lol

adambros 2016-11-03T00:01:06.003612Z

np

adambros 2016-11-03T00:02:08.003613Z

anyway, point being that you can make your router a component that provides a middleware function and have consumers just plug it in wherever they want it

adambros 2016-11-03T00:02:44.003614Z

we’re testing this stuff out with one of our apps & untangled-components’ image library if you want to take a sneak peak

currentoor 2016-11-03T00:02:52.003615Z

oh this router is frontend only, at least that’s how we’re using it

adambros 2016-11-03T00:03:06.003616Z

ah ok

currentoor 2016-11-03T00:03:21.003617Z

yeah much the om next router library

adambros 2016-11-03T00:03:43.003618Z

sounds useful, and it uses bidi?

currentoor 2016-11-03T00:03:49.003619Z

yeah

adambros 2016-11-03T00:07:38.003620Z

idk if its related, but i cant seem to find om.tempid/TempId when in a clj file

adambros 2016-11-03T00:21:09.003621Z

so after reading a bit of bidi, i cant find anything that lets you put an arbitrary function in a pattern segment

adambros 2016-11-03T00:21:40.003622Z

and based on what i could decypher from bidi.bidi.cljc they extend some other protocols to let what you want work with keywords/uuids

adambros 2016-11-03T00:24:49.003623Z

at first glance i think transform-param might what you want: https://github.com/juxt/bidi/blob/master/src/bidi/bidi.cljc#L71

currentoor 2016-11-03T00:30:31.003627Z

i wonder why it’s a deftype in cljs and a defrecord in clj?

adambros 2016-11-03T00:30:47.003629Z

yeah the repl cant find it, but i can jump to source and see it

currentoor 2016-11-03T00:33:26.003631Z

well this works

currentoor 2016-11-03T00:33:30.003632Z

(om.tempid/->TempId (java.util.UUID/randomUUID))
  =&gt; <#C06DT2YSY|om>/id["ca7c8476-cdf1-4ef3-b7f8-f385ad23ba29"] 

currentoor 2016-11-03T00:33:48.003633Z

i guess that makes sense since it is a record?

adambros 2016-11-03T00:33:53.003634Z

yeah i can see the constructors but not the type

currentoor 2016-11-03T00:34:30.003635Z

yeah that is strange

currentoor 2016-11-03T00:36:13.003636Z

(class (om.tempid/tempid))
  =&gt; om.tempid.TempId

currentoor 2016-11-03T00:36:18.003637Z

might be a jvm/clojure namespace thing

adambros 2016-11-03T00:36:59.003639Z

so i think what’s happening is that this https://github.com/juxt/bidi/blob/master/src/bidi/bidi.cljc#L151 is catching your function tempid and failing to match matches?

currentoor 2016-11-03T00:37:01.003641Z

you can refer to the type as om.tempid.TempId

currentoor 2016-11-03T00:37:10.003642Z

yes

adambros 2016-11-03T00:37:49.003643Z

whats weird is that i cannot get it to use this (extend-protocol bidi.bidi/PatternSegment MyId …) instead of the Fn one

currentoor 2016-11-03T00:38:38.003644Z

hmm, i’m pretty hung over and sleep deprived at the moment. I’ll play with this tomorrow

currentoor 2016-11-03T00:38:58.003645Z

thanks for helping

adambros 2016-11-03T00:39:15.003646Z

haha no problem

adambros 2016-11-03T00:39:26.003647Z

i would say without docs on this, its probably not supported well if at all

currentoor 2016-11-03T00:39:49.003648Z

yeah true, but it seems like something a routing lib should totally do

currentoor 2016-11-03T00:40:22.003649Z

an extensible clojurescript-y one anyway

adambros 2016-11-03T00:40:36.003650Z

oh hmm

adambros 2016-11-03T00:40:57.003651Z

i just…

(def routes
  ["" {"dashboards/" {[[(myid 666) :id] "/edit"] :edit}}])
and it registers it

adambros 2016-11-03T00:41:18.003652Z

i guess you need an instance of it instead of the fn

currentoor 2016-11-03T00:41:43.003653Z

i think i tried that

adambros 2016-11-03T00:41:58.003654Z

kinda works

currentoor 2016-11-03T00:42:02.003655Z

but bidi.bidi/match-route still doesn’t work

adambros 2016-11-03T00:42:16.003656Z

(specification "bidi tempids"
  (assertions
    (bidi.bidi/path-for routes :edit :id (myid 123))
    =&gt; "dashboards/123/edit"
    (bidi.bidi/match-route routes "dashboards/42/edit")
    =&gt; {:route-params {:id (myid "42")} :handler :edit}
    ))

adambros 2016-11-03T00:43:19.003657Z

and its the right type!

adambros 2016-11-03T00:44:18.003658Z

using this:

(defrecord MyId [id])

(extend-protocol bidi.bidi/ParameterEncoding
  MyId
  (encode-parameter [myid]
    (str (.-id myid))))

(defn myid [id]
  (-&gt;MyId id))

(extend-protocol bidi.bidi/PatternSegment
  MyId
  (segment-regex-group [_] #"\d+")
  (param-key [_] nil)
  (transform-param [_] myid)
  (unmatch-segment [this s] (str (.-id this)))
  (matches? [this s] (= (type s) MyId)))

adambros 2016-11-03T00:44:55.003660Z

you should be able to do something similar and maybe tweak the matches?

currentoor 2016-11-03T00:45:10.003662Z

hmm maybe

currentoor 2016-11-03T00:45:12.003663Z

i’ll try

currentoor 2016-11-03T00:46:29.003664Z

(def routes
  ["/"
   {
    "dashboards/" {""                  :dashboards/index
                   "new"               :dashboards/new
                   [[long :id] "/edit"] :dashboards/edit
                   [[bidi.bidi/uuid :id] "/edit2"] :dashboards/edit2
                   [[(om/tempid) :id] "/edit3"] :dashboards/edit3
                   [[(myid 666) :id] "/edit3"] :dashboards/edit4
                   }
    ""            [[true :dashboards/index]]}])

(bidi.bidi/path-for routes :edit :id (myid 123))
=&gt; nil

currentoor 2016-11-03T00:46:44.003665Z

it looks like it’s returning nil

currentoor 2016-11-03T00:47:03.003667Z

oh wait

currentoor 2016-11-03T00:47:21.003668Z

my bad

adambros 2016-11-03T00:48:49.003669Z

i think to get it so you dont have to do make a tempid you’d have to add one that checks based on class

adambros 2016-11-03T00:49:13.003670Z

a PatternSegment for java.lang.Class

adambros 2016-11-03T00:49:23.003671Z

anyway this should get you closer

currentoor 2016-11-03T00:49:35.003672Z

yeah definitely, thanks a lot

currentoor 2016-11-03T21:06:34.003681Z

@adambros i did it a different way which doesn’t require a stub value in the routes https://clojurians.slack.com/files/currentoor/F2X828WTS/bidi_om_next_cljs.clj