I noticed that I can't do this: (map ElectricFn some-values), the fn is not called, no reactivity, silent failure.
Is there any workaround except using e/for?
all electric defs need to be in a .cljc file, but host clojure/script functions do not
i've added a line to the tutorial to clarify this, thanks
Generally speaking, I don't think you should be doing "filtering" operations in Electric, for a couple reasons • filtering is performance sensitive • performance sensitive means no latency - there cannot be client/server transfer in filtering • performance sensitive means fast on large collections - which Electric is not, Electric is like 100x slower than regular Clojure for imperative programs such as looping over a large collection - due to all the overhead of reactivity, the network runtime, the object lifecycle, etc • really the only thing Electric is excellent at is distributing view state from backend to frontend, it is not a general purpose language, the host language fills that role instead
even e/for is designed for small "differential collections" - an assumption of any client/server system is that the client has limited memory, you never want to send huge collections over the wire (the client then has to deserialize, parse, hold them in memory, loop over them). Most web apps paginate, electric uses virtual scroll. you only want enough in memory to draw the current viewport
You can't call Electric functions like host functions, they have different calling conventions. What are you trying to achieve? 😄
I have a set of input filtering functions, and it felt natural to make some of them Electric, as they compare input values. And I map over them, to filter an input value. I know how to do this without Electric fns, just wondering what is possible, and how would it look.
Well, it depends 😅
If you need to materialize your sequence, you can use e/as-vec
Could you show some more (pseudo)code?
(e/defn ComposeInputFilters
"Returns the first error keyword from filter-fns applied to user-input or nil"
[filter-fns user-input]
(->> filter-fns
(map #(% user-input))
(some identity)))
Ideally, I would like to have both Electric and usual fns in filter-fns, but I know it's not possible.Does your filter-fns need to be cross-site (run on both client and server)? Otherwise, I would make this regular Clojure code.
Clojure function are more reusable in the sense that it's easy to lift a Clojure fn to an Electric fn, but not so straight forward the other way
No, there's no need, and I already made it work with regular Clojure. I had an Electric fn which generated a regular filter-fn. Just trying to do it differently, maybe a bit more elegant.
Another question then, when I make all filter-fns Electric, and pass them like this:
[shui/NotANumber? shui/Negative? MaxTc<MinTc?]
The locally defined fn is passed fine, and I can use it in e/for:
(e/for [F (e/diff-by {} FilterFns)]
(F user-input))
But the other two have different types, and e/for breaks when I add them. Is this because they are defined in .cljs file, or because they are not local?
Is there an easy fix?Nvm, I made it work