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
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 bidisorry to interrupt lol
np
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
we’re testing this stuff out with one of our apps & untangled-components’ image library if you want to take a sneak peak
oh this router is frontend only, at least that’s how we’re using it
ah ok
yeah much the om next router library
sounds useful, and it uses bidi?
yeah
idk if its related, but i cant seem to find om.tempid/TempId when in a clj file
so after reading a bit of bidi, i cant find anything that lets you put an arbitrary function in a pattern segment
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
at first glance i think transform-param
might what you want: https://github.com/juxt/bidi/blob/master/src/bidi/bidi.cljc#L71
@adambros should be here no? https://github.com/omcljs/om/blob/ee4c7ac33934fcd9b3ea663045ced1408dd7df24/src/main/om/tempid.cljc#L36
i wonder why it’s a deftype
in cljs and a defrecord
in clj?
yeah the repl cant find it, but i can jump to source and see it
well this works
(om.tempid/->TempId (java.util.UUID/randomUUID))
=> <#C06DT2YSY|om>/id["ca7c8476-cdf1-4ef3-b7f8-f385ad23ba29"]
i guess that makes sense since it is a record?
yeah i can see the constructors but not the type
yeah that is strange
(class (om.tempid/tempid))
=> om.tempid.TempId
might be a jvm/clojure namespace thing
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?
you can refer to the type as om.tempid.TempId
yes
whats weird is that i cannot get it to use this (extend-protocol bidi.bidi/PatternSegment MyId …)
instead of the Fn
one
hmm, i’m pretty hung over and sleep deprived at the moment. I’ll play with this tomorrow
thanks for helping
haha no problem
i would say without docs on this, its probably not supported well if at all
yeah true, but it seems like something a routing lib should totally do
an extensible clojurescript-y one anyway
oh hmm
i just…
(def routes
["" {"dashboards/" {[[(myid 666) :id] "/edit"] :edit}}])
and it registers iti guess you need an instance of it instead of the fn
i think i tried that
kinda works
but bidi.bidi/match-route
still doesn’t work
(specification "bidi tempids"
(assertions
(bidi.bidi/path-for routes :edit :id (myid 123))
=> "dashboards/123/edit"
(bidi.bidi/match-route routes "dashboards/42/edit")
=> {:route-params {:id (myid "42")} :handler :edit}
))
and its the right type!
using this:
(defrecord MyId [id])
(extend-protocol bidi.bidi/ParameterEncoding
MyId
(encode-parameter [myid]
(str (.-id myid))))
(defn myid [id]
(->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)))
you should be able to do something similar and maybe tweak the matches?
hmm maybe
i’ll try
(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))
=> nil
it looks like it’s returning nil
oh wait
my bad
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
a PatternSegment
for java.lang.Class
anyway this should get you closer
yeah definitely, thanks a lot
@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