Fork me on GitHub
#hyperfiddle
<
2023-07-09
>
braai engineer02:07:09

How to listen for dragstart and dragend DOM events? (dom/on "dragstart" ...) or "ondragstart" do not seem to fire.

Dustin Getz13:07:38

if you suspect an issue in electric-dom with these events you can drop down to m/observe and manage the event directly

braai engineer09:07:39

I am not yet skilled enough in Missionary to know how to drop-in to it from Electric. Is there an example somewhere for a different event plz?

braai engineer10:07:22

Ah, my mistake: I was not calling (.preventDefault e) on "drop" and "dragover" events.

Vincent18:07:15

I have a need for a component I think everyone could employ eventually in one project or another: a way to pass a timestamp to the clientside and have it say in relative terms "1 second ago" or "15 minutes ago" or "1 hour ago" it makes me think that there are probably a few we could optimistically invest our collective time into as a community and make it easy to have durable, reusable components

Dustin Getz19:07:13

Javascript ecosystems have it covered - https://day.js.org/docs/en/display/from-now

👁️ 2
Piotr Roterski19:07:17

if you want to stay in cljc land you could probably use https://github.com/clj-commons/humanize#datetime

👁️ 2
Vincent18:07:06

Free multiplayer and client/server data transparency is a revolution in web programming. It's hard to state how liberating this is for applications that rely on real-time comms or significant client/server message passing.

🙂 2
Reut Sharabani19:07:08

What is HYPERFIDDLE_ELECTRIC_SERVER_VERSION ? Why do I need to set it? How do I set it? Can I not set it/ignore it somehow and still have everything work?

Reut Sharabani19:07:13

I'm trying to deploy to production and I have issues. One of these issues is that this property isn't set. I set it manually and now I suspect the other issues may be related to not setting it properly (?) I just set it to my commit hash because I have no idea what it should be.

Reut Sharabani19:07:08

I'm deploying to an internal env and version is not set and the docker cmd is:

"Cmd": [
  "/bin/sh",
  "-c",
  "java -DHYPERFIDDLE_ELECTRIC_SERVER_VERSION=$VERSION -jar app.jar"
]
Can I safely change it to java -jar app.jar?

Reut Sharabani20:07:31

for now it's set to my commit hash and I get these errors 😞 :

in ( .render js/mermaid dummy  )
 in ( .then (.render js/mermaid "dummy" mmd) #object[ja] )
 in reactive (fn [] ...)
 in reactive (fn [] ...)
 in reactive (defn Mermaid [] ...) in app/observer.cljc line 233
 in reactive (fn [] ...)
 in reactive (fn [] ...)
 in reactive (defn Observer [] ...) in app/observer.cljc line 264
 in (try ...) 

 TypeError:  is not a function
Locally it works fine so it's either something to do with the remote env or with my build. I have no idea what is not a function can tell me. js/mermaid is available on the webpage (checked in console) and it has a render method.

Dustin Getz20:07:26

the starter app has a working configuration out of the box, are you having trouble with that?

Dustin Getz20:07:55

the version used to cachebust stale clients when you deploy and the server changed

Dustin Getz20:07:11

it should be set by the build, i think in the dockerfile

Dustin Getz20:07:23

see build.clj and the readme

Reut Sharabani20:07:13

I'm not deploying to that fly platform thing. But I don't think it's the version. I think it's because I set a callback on a promise using (fn [arg] ..) and it doesn't recognize it as a function. But I'm still investigating

Reut Sharabani20:07:28

this is my clue:

in ( .then (.render js/mermaid "dummy" mmd) #object[ja] )
 in reactive (fn [] ...)
 in reactive (fn [] ...)
 in reactive (defn Mermaid [] ...) in app/observer.cljc line 233
 in reactive (fn [] ...)
 in reactive (fn [] ...)
 in reactive (defn Observer [] ...) in app/observer.cljc line 264
 in (try ...) 

 TypeError:  is not a function
    at Function.<anonymous> (main.BC569D98165855497A21AC1C8BE1718D.js:1623:185)
The object thing is a ja and the http://ja.mg is not a function (which is probably function/call or something)

Dustin Getz20:07:58

what commands did you type? where is the error coming from?

Reut Sharabani20:07:03

It's my app running and trying to update some svg. The library that generates the svg is using async/away (so a promise) and my line that probably fails is:

(.then
                        (.render js/mermaid "dummy" mmd)
                        set-mm-svg)
set-mm-svg used to be a lambda (fn [svg] ... set svg) and I think that failed

Dustin Getz20:07:20

release build? dev build?

Reut Sharabani20:07:59

I also tried e/fn and it failed so I am now trying #?(:cljs (defn ...))

Dustin Getz20:07:17

ok, i think it’s an advanced mode problem, i think you don’t want to access mermaid from the js global. how is mermaid loaded?

Reut Sharabani20:07:43

index html script tag

Reut Sharabani20:07:49

I have very little front end experience 😄

Reut Sharabani20:07:04

It's available on the webpage (I checked in console)

Dustin Getz20:07:13

that is the problem

Reut Sharabani20:07:43

well after 3 hours that is nice to hear 🙂

Dustin Getz20:07:55

get mermaid from NPM and then :require it so that shadow-cljs can see it

Reut Sharabani20:07:11

yeah I wanted to do it but idk how require works in clojurescript. I guess I'll have to do that

Reut Sharabani20:07:21

it's just adding to the shadow under :dependencies, right?

Dustin Getz20:07:35

idk off hand and am on mobile

Reut Sharabani20:07:45

no problem, let me try. Thanks Dustin!

Dustin Getz20:07:03

you’re definitely going to need to have working knowledge of clojurescript toolchain

Reut Sharabani20:07:33

well I'm stubborn so I'll definitely learn /something/

😂 2
Reut Sharabani20:07:46

btw why does the deployment care, does it modify index.html? If there is a link where I should have found out I'd like to read. Thanks.

Dustin Getz20:07:25

clojurescript prod builds perform dead code elimination and code minification which mangles the names

Dustin Getz20:07:12

you can also turn it off

Reut Sharabani20:07:19

I wanted to. I only found optimizations and turned them off

Reut Sharabani20:07:32

(It didn't work so they're on now).

Reut Sharabani09:07:27

I couldn't get it to work because shadow seems to not support "lazy loading" which is probably when you require something conditionally and I end up with some missing modules after compilation. I think it's best if I can add the html "script" tag and not mangle anything because performance is not an issue for me. Is turning off "optimizations" enough to do that or do I need to take care of other things? If it's too much work, how can I include a library with lazy loading (in this case mermaid) and use it in production? It works locally so there must be a difference in that aspect between production and local build but I've yet to find it. I figured it's around the src-build and client build (there is a comment about it in the code) but I didn't find how to make it work. Performance is not an issue because it's a demo I want to show my peers.

Dustin Getz10:07:38

i don’t understand fully yet, please add me to your github repo

Reut Sharabani10:07:35

I'll try and create one with a minimal example later. I can't add to my repo since it includes some private stuff.

Reut Sharabani10:07:19

(I don't think it's related to hyperfiddle at this point, I'm posting here to leverage slack search which indexes these messages and can maybe help someone from the future with similar problems)

Reut Sharabani11:07:12

ok so it turns out optimizations :none is not an option. You have to use optimizations :simple . The code even suggests that (setting optimizations in build-client to false, I hard coded the compiler option to :none) This enables to requires through script tag without breaking anything. @U09K620SG now it works and my diagrams are generated. Optimizations are not a concern for my demo. Thank you so much for your help and patience!

Reut Sharabani11:07:58

for reference this is the error optimizations :none generates:

optimizations set to :none, can't optimize
{}
ExceptionInfo: optimizations set to :none, can't optimize
	shadow.build.closure/optimize (closure.clj:1308)
	shadow.build.closure/optimize (closure.clj:1301)
	shadow.build.api/optimize (api.clj:273)
	shadow.build.api/optimize (api.clj:267)
	shadow.build/optimize (build.clj:525)
	shadow.build/optimize (build.clj:517)
	shadow.cljs.devtools.api/release* (api.clj:339)
	shadow.cljs.devtools.api/release* (api.clj:324)
	shadow.cljs.devtools.api/release/body-fn--19691--auto----19795 (api.clj:358)
	shadow.cljs.devtools.api/release (api.clj:356)
	shadow.cljs.devtools.api/release (api.clj:351)
	build/build-client (build.clj:32)
	build/build-client (build.clj:22)
	build/uberjar (build.clj:49)
	build/uberjar (build.clj:38)
	clojure.lang.Var.invoke (Var.java:384)
	clojure.run.exec/exec (exec.clj:89)
	clojure.run.exec/exec (exec.clj:78)
	clojure.run.exec/-main/fn--237 (exec.clj:228)
	clojure.run.exec/-main (exec.clj:224)
	clojure.run.exec/-main (exec.clj:192)
	clojure.lang.Var.applyTo (Var.java:705)
	clojure.core/apply (core.clj:667)
	clojure.main/main-opt (main.clj:514)
	clojure.main/main-opt (main.clj:510)
	clojure.main/main (main.clj:664)
	clojure.main/main (main.clj:616)
	clojure.lang.Var.applyTo (Var.java:705)
	clojure.main.main (main.java:40)
And the resulting jar doesn't load the a web page (missing manifest).

Dustin Getz12:07:07

My best guess is that shadow-api/release is intended to build a single .js file artifact and therefore an optimization strategy is required

Dustin Getz12:07:11

i think you'd write shadow-api/compile for a dev build iirc

Reut Sharabani12:07:01

yes, I basically hard-coded an override of optimizations to :none when you directed me that the script tag inclusion doesn't work because of :advanced. This broke shadow's output. So using :simple instead of :advanced (like the code you point to suggests) worked.

Reut Sharabani12:07:06

So when you want to include something that has lazy-loaded libraries internally, or that you can't npm-install for some other reason, you probably want to use :simple optimizations. Otherwise shadow messes with js in some way that breaks script tags (probably doesn't compile them alongside the npm_modules and whatever else).

Dustin Getz15:07:37

If you must, you can access the global by string, i.e. js.window["mermaid"] to bypass the name mangling

Dustin Getz15:07:02

(def mermaid (aget js/window "mermaid")) ; something like this

Reut Sharabani15:07:13

I'm focused on other things but I'll keep that in mind

Reut Sharabani15:07:29

it's a shadow issue anyway so I'm sure other devs just know how it works

👍 2
Reut Sharabani12:07:01

yes, I basically hard-coded an override of optimizations to :none when you directed me that the script tag inclusion doesn't work because of :advanced. This broke shadow's output. So using :simple instead of :advanced (like the code you point to suggests) worked.