Fork me on GitHub
#untangled
<
2016-11-03
>
adambrosio00:11:34

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

currentoor00:11:39

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

currentoor00:11:00

sorry to interrupt lol

adambrosio00:11:08

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

adambrosio00:11:44

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

currentoor00:11:52

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

currentoor00:11:21

yeah much the om next router library

adambrosio00:11:43

sounds useful, and it uses bidi?

adambrosio00:11:38

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

adambrosio00:11:09

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

adambrosio00:11:40

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

adambrosio00:11:49

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

currentoor00:11:31

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

adambrosio00:11:47

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

currentoor00:11:26

well this works

currentoor00:11:30

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

currentoor00:11:48

i guess that makes sense since it is a record?

adambrosio00:11:53

yeah i can see the constructors but not the type

currentoor00:11:30

yeah that is strange

currentoor00:11:13

(class (om.tempid/tempid))
  => om.tempid.TempId

currentoor00:11:18

might be a jvm/clojure namespace thing

adambrosio00:11:59

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?

currentoor00:11:01

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

adambrosio00:11:49

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

currentoor00:11:38

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

currentoor00:11:58

thanks for helping

adambrosio00:11:15

haha no problem

adambrosio00:11:26

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

currentoor00:11:49

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

currentoor00:11:22

an extensible clojurescript-y one anyway

adambrosio00:11:57

i just…

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

adambrosio00:11:18

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

currentoor00:11:43

i think i tried that

currentoor00:11:02

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

adambrosio00:11:16

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

adambrosio00:11:19

and its the right type!

adambrosio00:11:18

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

adambrosio00:11:55

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

currentoor00:11:29

(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

currentoor00:11:44

it looks like it’s returning nil

adambrosio00:11:49

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

adambrosio00:11:13

a PatternSegment for java.lang.Class

adambrosio00:11:23

anyway this should get you closer

currentoor00:11:35

yeah definitely, thanks a lot

currentoor21:11:34

@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