electric
electric copied to clipboard
e/def bindings are duplicated (created on both client and server under identical names)
Hendrik in slack:
Is it possible to use a (e/def db) in a callback? I added this to the starter app:
(ui/button (e/fn [] (println (todo-count db))) (dom/text "click"))After clicking the button I get Unbound varapp.todo-list/db. Is it possible to make (e/def db) available at callback time?
It is possible and works, with a complication (that we're planning to fix):
Today, (e/def x 1) creates a binding on both client and server, there are two bindings with the same name. Since it is ambiguous, you must be explicit from which site you resolve it from. This is in contrast with let bindings which are defined unambiguously at a single site and therefore the compiler can infer which site has the binding.
(e/def x 1) ; ambiguous, binding x exists at both places
(e/server
(let [y 2] ; unambiguous, binding y located at server
(e/client
(println y) ; y inferred to be on server
(println x) ; x is ambiguous so compiler assumes local access, here client
(println (e/server x)) ; explicitly access x on server
)))
We will fix this as we consider this inconsistency a semantics bug. It's WIP.