Fork me on GitHub
#clojurescript
<
2023-05-04
>
hifumi12304:05:25

It looks like Karma was deprecated just 5 days ago… Karma still does everything I need as far as unit tests go, but I’m wondering what alternatives exist that are equally compatible with CLJS.

seancorfield04:05:49

There was a recent announcement of cljest which is a cljs wrapper around Jest.

seancorfield04:05:07

(at work we used to use Karma ... but switched to Jest/Jasmine but we're all JS on the frontend)

lread14:05:51

Huh, thanks for the heads up @U0479UCF48H, I suppose https://github.com/karma-runner/karma#karma-is-deprecated-and-is-not-accepting-new-features-or-general-bug-fixes. Sounds like we have some time tho... > Critical security issues in Karma will still be triaged and fixed as necessary. This will continue until 12 months after Angular CLI's Web Test Runner support is marked stable.

Harry10:05:56

I am trying to get pdf.js to work within a fulcro server, but I am running into: act-dom.development.js:87 Warning: useEffect must not return anything besides a function, which is used for clean-up. It looks like you wrote useEffect(async () => ...) or returned a Promise. Instead, write the async function inside your effect and call it immediately: useEffect(() => { async function fetchData() { // You can await here const response = await MyAPI.getData(someId); // ... } fetchData(); }, [someId]); // Or [] if effect doesn't need props or state I have the following: (def ^js pdfjs (gobj/get js/window "pdfjs-dist/build/pdf")) (defsc PDFCanvas [this props] {:query [:pdf-canvas/id] ; normal Fulcro component options :ident :pdf-canvas/id :use-hooks? true} ;; ref (set! (.. pdfjs -GlobalWorkerOptions -workerSrc) "") (let [canvas-ref (hook/use-ref nil)] ;; initialize and attach pdfjs when the canvas is mounted (hook/use-effect (fn [] (-> (. pdfjs getDocument "test.pdf") (.-promise) (.then (fn [^js pdf] (js/console.log "pdf loaded") (. pdf getPage 1))) (.then (fn [^js page] (js/console.log "page" page) (let [viewport (.getViewport page #js {:scale 1.5}) canvas (.-current canvas-ref) context (.getContext canvas "2d") render-context #js {:canvasContext context :viewport viewport}] (set! canvas -height (.-height viewport)) (set! canvas -width (.-width viewport)) (-> (.render page render-context) (.-promise) (.then (fn [] (js/console.log "Page rendered.")))) )))) )) ;; ensure this only re-runs when url changes ) ;; [:canvas {:ref canvas-ref}] ) What is the correct way I should be handling the promise?

thheller10:05:04

its only complaining about the return value, otherwise seems fine. you can see an example I made for pdfjs here

thheller10:05:18

not fulcro but that part doesn't really matter

p-himik10:05:39

Or at the very least, not a promise, so js/undefined should work, and maybe nil.

thheller10:05:16

yeah that works too

Harry10:05:01

That is what I was working of 😄 Ok that got rid of the errors but still not displaying the pdf. Must be something to do with fulcro. Cheers I'll keep playing around

Harry10:05:43

Is the #js [url]) [:canvas {:ref canvas-ref}] Part essential?

p-himik10:05:44

The URL part is important but not essential. The canvas part is essential because that's where your PDF will be rendered.

🙌 1
Harry10:05:08

Cool that was what I thought! Now just to get fulcro to work with it! Thanks

isak15:05:12

A little off topic maybe, but a little warning about that library: you will get rendering artifacts in Chrome

jhacks20:05:05

@U08JKUHA9 Are you referring to this issue or something else? https://github.com/mozilla/pdf.js/issues/14641

isak20:05:23

@U2NNQ4GP9 Yes I think that is the one. We tried the library about a month ago, but had to abandon it because of that issue.

👍 2
James Amberger21:05:39

@U08JKUHA9 I came here with the same question as @U0558HTJE6Q (@U05224H0W showed up quickly to help me, too—thanks again). What did you end up doing instead to render pdf in the browser or React Natiive?

isak22:05:32

@U032EFN0T33 We had to render a png of the current page on the server and send it to the client. Not great, but I don't see a good alternative now.

Harry05:05:28

I might go that way too then, I am wanting to overlay text onto the pdf and only need to show one page at a time so might be an easier solution all round

Harry06:05:58

@U08JKUHA9 How did you go about the conversion? I have tried pdf-to-png-converter and pdf-img-convert.js with no luck on getting either to work ;( (TBF I am quite new to cljs)

isak14:05:47

@U0558HTJE6Q In our case the source wasn't PDF, that was just one of many possible output options. Also our backend was in C#, so I probably wouldn't be able to help if your backend is node.

👍 2
sirwobin16:05:48

I'm running stat in nodeJS and I get different results on my laptop and the AWS arm64 nodeJS implementation. I query stats with node:fs/promises using the code below. Specifically, the member property accessor for "atimeMs" is returning null for a member I know is present.

(-> (.stat fs "some/file/path")
    (.then (fn [stats]
             (let [access-time   (long ^number (.-atimeMs stats))
                   epoch-now     (.now js/Date)
                   lock-file-age (- epoch-now access-time)]
               (println "Got stats of" (js/JSON.stringify stats))
               (println "access-time" access-time "now" epoch-now "lock-file-age" lock-file-age))))
    (.catch #(println "stat failed with" (js/JSON.stringify %))))
The stats object in the logs looks like this:
{
    "dev": 38,
    "mode": 33204,
    "nlink": 1,
    "uid": 1000,
    "gid": 1000,
    "rdev": 0,
    "blksize": 1048576,
    "ino": 10649081274884770000,
    "size": 14,
    "blocks": 8,
    "atimeMs": 1683202827641,
    "mtimeMs": 1683202827641,
    "ctimeMs": 1683202827641,
    "birthtimeMs": 0,
    "atime": "2023-05-04T12:20:27.641Z",
    "mtime": "2023-05-04T12:20:27.641Z",
    "ctime": "2023-05-04T12:20:27.641Z",
    "birthtime": "1970-01-01T00:00:00.000Z"
}
and yet the following log statement says access-time is null. On my laptop (intel linux) it works fine and I get values but on AWS with arm64 node I get nulls. Has anyone experienced something similar? Any pointers appreciated.

thheller16:05:27

do you get an inference warning? the access might be getting renamed

thheller16:05:41

try (.then (fn [^js stats]

sirwobin16:05:21

Will give that a try. One moment..

sirwobin16:05:30

That fixed it! Thank you 😃 Will add more hints

sirwobin16:05:46

There was no inference warning before.

sirwobin16:05:49

Perplexing that birthtime is 0 as well. Makes me suspicious of their node implementation or at least the fs promises stat implementatino

chromalchemy22:05:07

What is a way to spit repl results from a jvm repl to an arbitrary userland web form? Then update form, for hacky in-context inter-app eval? Read Evaluate Print-to-web-field Update-web-field Loop Maybe indirectly through some file sync or websocket tooling? Or would i necessarily need to drive a browser? And/or use tampermonkey extension? etc..

chromalchemy22:05:20

Was thinking Squint or Scittle, but wondering if there were general approaches.. https://clojurians.slack.com/archives/C03U8L2NXNC/p1683238255910239

thheller06:05:05

you could just POST a regular HTML <form>. extremely insecure but very easy