Fork me on GitHub

best way to bring your own transit handlers?

Yab Mas07:03:21

Just answering because it might be a few hours before the team wakes up, they might have other ideas, but it's fairly easy to add the electric-ws-handler to your own ring-jetty-server and then you can do whatever you want.

Yab Mas08:03:07

Just make sure to read;cid=C7Q9GSHFV if you go with jetty 10, else you'll run into the same issue i did the other day, I believe the examples for 9 are up-to-date

Geoffrey Gaillard09:03:35

I was planning to give a look at custom transit handlers today. Good timing 🙂 I’ll keep you posted

Geoffrey Gaillard09:03:04

Yab I think you are talking about ring handlers, whereas Kevin wants to customize how values are serialized on the wire. Or am I confused?

👍 2
Yab Mas09:03:47

Nah your right, I misunderstood

Geoffrey Gaillard17:03:05

We have made progress. We are figuring what’s the right API and we will release customizable transit handlers in the near future.

👍 2
Geoffrey Gaillard11:03:25

Pushed custom transit handler support to See Note the comment in the example code. Keep us posted if the current approach is not compatible with your use case.

👍 2

I’m seeing weird errors that the simplest possible code gives unresolved symbols when used in e/server

Encountered error when macroexpanding hyperfiddle.electric/boot.
Unable to resolve symbol: let
things like let and println and I don’t understand why

Geoffrey Gaillard12:03:31

Could you share some code? Seeing the file would help


for example here I have a component for selecting or creating an entry

(e/defn SelectOrCreate [{:keys [table where display-key id-key empty-option create-option template]
                         :or {display-key :ds/name
                              id-key :ds/id}}]
   (let [tbl 0 #_(new latest-table-change> table)]
      (let [options (fetch. table #{id-key display-key} where tbl)
            !creating? (atom false)
            creating? (e/watch !creating?)
            create-val (str (gensym "new"))]
        (<% :div.relative
            (<% {:on-change (e/fn [e]
                                             (let [v (-> e .-target .-value)]
                                               (reset! !creating? (= v create-val))))}
                (when empty-option
                  (<% :option {:disabled true :selected true} (dom/text empty-option)))
                (e/for-by id-key [item options]
                          (<% :option {:value (get item id-key)}
                              (dom/text (get item display-key))))
                (when create-option
                  (<% :option {:value create-val} (dom/text create-option))))

            (when creating?
              (<% :div.absolute.bottom-0.left-0
                  (InputGroup. {:label create-option
                                :name "Luo"
                                :placeholder create-option
                                :on-enter (e/fn [val]
                                            (reset! !creating? false)
                                            (new insert! table (template val)))})))))))))
even with that simple let binding to 0, it fails… if I take out the let and e/server from the top, it works


I copied this, stubbed out functions you didn't provide, and it compiled for me. I'd next restart everything or start removing code to see at which point does it fail


also, aren't fetch and insert! server functions?


They are e/defn that have e/server blocks

Geoffrey Gaillard14:03:48

Is the code you shared in a .cljc file?

Dustin Getz15:03:56

problem may be at entrypoint

Dustin Getz15:03:59

probably next step is to send us your whole repo and see if we can reproduce

Dustin Getz15:03:19

what is latest-table-change>


It is commented out, so shouldnt affect

Dustin Getz15:03:54

Can you minimize it down to an entrypoint + a few LOC?

Dustin Getz15:03:18

I wonder if a userland macro could cause this


I’ll try to get a minimal repro


must be a userlang macro, because even this fails

(e/defn SelectOrCreate [{:keys [table where display-key id-key empty-option create-option template]
                         :or {display-key :ds/name
                              id-key :ds/id}}]
   (let [tbl 0]
      (<% "foo" (dom/text tbl))))))
I’m referring to code that uses my specql library, that does very heavy macro stuff… something in my setup confuses it


the backend side touches lots of code that has macros (like the clojure.spec.alpha)


Does it fail without <℅?


the <% works in other places that use server and client

Dustin Getz21:03:08

push your repo and I will take a look

Dustin Getz14:03:33

@U11SJ6Q0K one way to work around any potential issue in Electric is to wrap all heavy macro calls in an ordinary clojure function, instead of calling them from Electric regions


the macro namespace in question does some very heavy lifting, and expands to a bunch of clojure.spec definition calls at ns load time, so not really an option to do that from a function


I’ll come back to this later, for now I made this app in another way, so not critical

👍 2
Dustin Getz14:03:01

were you calling the heavy macros from Electric? It seems like you just have a namespace somewhere (not related to electric) with macros in it?


I wasn’t calling that, the compiler just seemed to get confused whenever some code referred to the namespace that had the macro calls in it

Dustin Getz14:03:24

i dont really undertstand what that means


so in my .cljc file containing electric components I have a :refer [some.ns] at the ns declaration


and if some.ns has the macro calls, it seems to get confused

Dustin Getz14:03:54

you mean :require ?

yes 2

I understand this is not a very good bug report, but I’ll come back to it later when I have some time

👍 2