hyperfiddle

Dustin Getz (Hyperfiddle) 2025-02-22T14:23:45.555939Z

I want, badly, Slack messages in an Electric UI/backend. Does anyone have experience with anything like this? I know there is a bot API but i also know there are limitations and/or "rules"

braai engineer 2025-02-22T18:58:47.571369Z

consider putting little $50-$500 bounties on stuff like this and people will do it mostly for street cred. pay in crypto, make a big hoorah about it. ouks will poast about it and amplify Electric. make it feel like a leetcode challenge. β€œwho can build this the fastest in Electric? time yourself. record a livecoding sesh if you want.”

braai engineer 2025-02-22T18:59:24.933939Z

(tax-deductible marketing expense)

Toyam Cox 2025-02-23T02:27:21.697019Z

Got some experience with Slack messages. It's not a particularly pleasant place. Partly because you have to constantly be translating between users and their user ID. Clojure does make it easier.

Toyam Cox 2025-02-23T02:28:01.230699Z

And I have not even mentioned the trouble around permissions for the bot. You have to approve every single thing that the bot is allowed to do. The owner of the namespace has to allow the bot and the permissions on that bot, as well as presumably added to some channels.

Toyam Cox 2025-02-23T02:28:56.168029Z

Changing how it is viewed by humans, such as impersonating a human, requires some serious permissions. I wonder whether it's even possible to do so in the Clojurians' Slack because you're not an admin of the Clojurians' Slack.

xificurC 2025-02-23T07:17:57.600369Z

Prior art https://github.com/emacs-slack/emacs-slack

πŸ‘€ 1
Dustin Getz (Hyperfiddle) 2025-02-22T14:54:44.111209Z

Impressive Electric one-liner - use dom/Mouse-over? to control eager vs lazy loading of tooltips in one LOC (just an and actually)

(when (and Tooltip (dom/Mouse-over?)) 
  (dom/props {:data-tooltip (Tooltip ?e a v pull-expr)})) ; tooltip loads from server only on mouse over!

πŸ‘ 6
πŸ‘πŸ» 1
tobias 2025-02-22T01:52:08.029619Z

There's a behaviour I'm not understanding to do with how Electric handles for vs map with non-"reactive" collections. This works like I'd expect:

(e/defn Sequences []
  (e/client
    (let [n (parse-long (Input* 10 :type "number" :min "0" :max "100"))
          ns (range 1 (inc n))
          squares (map #(* % %) ns)]
      (dom/div (dom/text "n: " n))
      (dom/div (dom/text "ns: " (pr-str ns)))
      (dom/div (dom/text "squares: " (pr-str squares))))))

xificurC 2025-02-22T08:28:32.000739Z

Most likely electric lost a type hint during compilation. A way to work around this is to force clj compilation, i.e. extract to a cc/defn or use an anonymous fn

tobias 2025-02-22T08:56:53.783409Z

Good to know, thanks! Just wanted to make sure I wasn't missing something deep about the way that Electric treats non-reactive collections.

Dustin Getz (Hyperfiddle) 2025-02-22T13:50:22.195849Z

generally speaking, in this expr, ns (range 1 (inc n)) since n is variable, you probably want ns to be incrementally maintained, which means you should diff-by asap, certainly before mapping squares (map #(* % %) ns) because that will recompute everything when ns changes incrementally. In other words, in Electric code bodies there is very little use for for & map (and clojure sequences broadly), you almost certainly want to be using e/for

tobias 2025-02-22T14:08:00.987799Z

Thanks, that makes sense. I actually came across the behaviour when I was working through the fizz buzz tutorial and experimenting with what happens when you replace the reactive/diffing collection with a regular collection just to understand the difference. I really like the diff-by syntax that turns a regular collection into a diffing one. Only thing I find is that sometimes I have a hard time keeping a track of what’s a normal collection and what’s diffing, but your advice to diff-by asap makes sense.

Dustin Getz (Hyperfiddle) 2025-02-22T14:09:17.015249Z

yeah, the answer is "every most collections should be immediately diffed as soon as electric touches it" which means "plural" names like xs are diffed. I sometimes write xs! to mean non-diffed in advanced cases

Dustin Getz (Hyperfiddle) 2025-02-22T14:10:52.203379Z

an immediate exception to "diff everything immediately" is tables, where you want to retain the original clojure collection (may be large) in memory and the virtual scroll will encapsulate the rendering/network strategy

Dustin Getz (Hyperfiddle) 2025-02-22T14:12:44.348089Z

because here, what you really want is to stream just the collection's viewport window to the browser, so you're diffing just the window, not the entire collection

πŸ‘ 1
tobias 2025-02-22T01:54:55.844629Z

But if I try the same sort of thing using for then I get a compile error

(e/defn Sequences2 []
  (e/client
    (let [n (parse-long (Input* 10 :type "number" :min "0" :max "100"))
          ns (range 1 (inc n))
          squares-using-for (for [x ns] (* x x))]
      (dom/div (dom/text "n: " n))
      (dom/div (dom/text "ns: " (pr-str ns)))
      (dom/div (dom/text "squares-using-for: " (pr-str squares-using-for))))))

tobias 2025-02-22T01:55:11.002999Z

tobias 2025-02-22T01:58:11.284719Z

Actually, here's an even more minimal example:

(e/defn Sequences3
  []
  (e/client
    (dom/div (dom/text (pr-str (for [i (range 10)] (* i i)))))))

tobias 2025-02-22T01:58:24.276969Z

tobias 2025-02-22T06:21:29.845429Z

Thanks for the link, but I'm not sure I follow. Are you saying that the expansion of the clojure core for macro somehow interferes with the way that electric works?

2025-02-22T06:33:47.229949Z

I dunno, just the for macro expansion is very complicated, way more than calling map

2025-02-22T06:35:14.153339Z

The line I linked to is almost identical in the clojurescript for definition, and I bet that is actually the issue, maybe related to the ^not-native annotation in the cljs

tobias 2025-02-22T01:53:02.880219Z

tobias 2025-02-22T06:19:21.054549Z

In the webview2 tutorial there are a few :required namespaces that I need to follow along with the tutorial on my own machine. dustingetz.teeshirt-orders-datascript I assume is from here https://gitlab.com/hyperfiddle/electric-fiddle/-/blob/main/src/dustingetz/teeshirt_orders_datascript.cljc But where can I find the code for electric-tutorial.typeahead? Thanks in advance!

βž• 1
tobias 2025-02-22T08:50:38.072229Z

Thanks! Not sure how I missed that

Dustin Getz (Hyperfiddle) 2025-02-22T13:46:14.984269Z

how did that go? I forgot we use that so early in the tutorial

Dustin Getz (Hyperfiddle) 2025-02-22T13:46:35.268829Z

we definitely don't intend for you to understand the typeahead impl that early