This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-04
Channels
- # announcements (1)
- # architecture (7)
- # beginners (44)
- # biff (11)
- # calva (15)
- # cider (5)
- # clerk (9)
- # clj-kondo (20)
- # clj-on-windows (19)
- # clj-yaml (2)
- # cljs-dev (39)
- # clojure (52)
- # clojure-czech (2)
- # clojure-dev (11)
- # clojure-europe (28)
- # clojure-hamburg (10)
- # clojure-hungary (3)
- # clojure-nl (1)
- # clojure-norway (59)
- # clojure-uk (5)
- # clojured (2)
- # clojurescript (33)
- # conjure (2)
- # datahike (1)
- # datomic (5)
- # defnpodcast (5)
- # emacs (18)
- # figwheel (2)
- # funcool (6)
- # graphql (1)
- # hyperfiddle (11)
- # jobs (3)
- # joyride (13)
- # malli (6)
- # music (4)
- # off-topic (45)
- # polylith (11)
- # practicalli (3)
- # rdf (3)
- # releases (1)
- # scittle (8)
- # shadow-cljs (13)
- # specter (2)
- # squint (8)
- # testing (6)
- # tools-deps (21)
- # xtdb (2)
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.
There was a recent announcement of cljest
which is a cljs wrapper around Jest.
(at work we used to use Karma ... but switched to Jest/Jasmine but we're all JS on the frontend)
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.
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?
its only complaining about the return value, otherwise seems fine. you can see an example I made for pdfjs here
https://github.com/thheller/reagent-pdfjs/blob/master/src/main/demo/app.cljs#L22-L52
it wants you to return a cleanup function like here https://github.com/thheller/reagent-pdfjs/blob/master/src/main/demo/app.cljs#L49C7-L52
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
The URL part is important but not essential. The canvas part is essential because that's where your PDF will be rendered.
A little off topic maybe, but a little warning about that library: you will get rendering artifacts in Chrome
@U08JKUHA9 Are you referring to this issue or something else? https://github.com/mozilla/pdf.js/issues/14641
@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.
@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?
@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.
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
@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)
@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.
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.Perplexing that birthtime is 0 as well. Makes me suspicious of their node implementation or at least the fs promises stat implementatino
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..
Was thinking Squint or Scittle, but wondering if there were general approaches.. https://clojurians.slack.com/archives/C03U8L2NXNC/p1683238255910239