Fork me on GitHub
#clojurescript
<
2021-11-11
>
genekim00:11:11

Hello, all! I am trying to write a clojure.spec to ensure that a function argument is actually an atom, as opposed to one that’s already dereferenced. I ran into this post, which was great (thanks, 2016 version of @alexmiller! 🙂 https://stackoverflow.com/questions/58700950/persistentvector-cannot-be-cast-to-class-iatom So this works in Clojure REPL:

(instance? clojure.lang.IAtom (atom {}))
=> true
What is the way to do this in ClojureScript? In a CLJS REPL, I get clojure.lang.IAtom isn’t found. After reading https://www.reddit.com/r/Clojure/comments/hua7p2/nonexistent_clojurelang_in_clojurescript/fym5kyb/, I think maybe this should work, but it returns false?
(instance? IWatchable (atom {}))
=> false
Any advice? Thanks in advance!

kardan13:11:26

Think you got a response but for reference since you asked for a Clojure and a Cljs solution I did https://github.com/kardan/taxa/blob/main/src/main/com/kardans/taxa.cljc#L107

genekim17:11:14

This is awesome, @U051F5T93 — thank you!

dpsutton00:11:08

(type (atom {})) is cljs.core/Atom. So i tried (instance? cljs.core/Atom (atom {})). But i don’t know if that’s a robust solution but seems straightfoward

genekim17:11:48

Thank you, @U11BV7MTK! I just learned about satisfies? too.

p-himik06:11:14

In cljs/core.cljs, there's this thing that built-in atoms use:

(defprotocol IAtom
  "Marker protocol indicating an atom.")

1
genekim17:11:28

This is terrific, thank you! I never thought about satisfies? — very cool.

p-himik06:11:09

Reagent uses it:

{:pre [(satisfies? IAtom a)
         (ifn? f)]}
Prismatic schema uses it:
(defn- atom? [x]        
  (satisfies? IAtom x))

Ben Hammond08:11:56

Trying to run material-ui 5.1.0 / emotion-js / React with shadow-cljs I get a file-name too long error from @emotion/react hoist file https://github.com/emotion-js/emotion/tree/main/packages/react/isolated-hoist-non-react-statics-do-not-use-this-in-your-code I am running Ubuntu 20.04.3

FileNotFoundException: .shadow-cljs/builds/elephantchess/dev/shadow-js/module$node_modules$$emotion$react$isolated_hoist_non_react_statics_do_not_use_this_in_your_code$dist$emotion_react_isolated_hoist_non_react_statics_do_not_use_this_in_your_code_browser_cjs.js (File name too long)
        java.io.FileOutputStream.open0 (FileOutputStream.java:-2)
...
        shadow.build.cache/write-file (cache.clj:24)
        shadow.build.cache/write-file (cache.clj:24)
        shadow.build.closure/convert-sources-simple/fn--12746/fn--12748 (closure.clj:2113)
Has anyone found a workaround for this ? (I'm just trying to upgrade to mui v5; I've only had this working on material-ui v4) I'm not aware that I care about hoisting non-react statics, think I would be happy if I could nudge shadow-cljs into ignoring this fille... Can I do that? Would I regret it?

thheller08:11:27

hmm this has come up before. I guess I'll need to add something to shorten the filenames somehow

thheller08:11:52

or can you increase the file name max length on ubuntu somehow?

Ben Hammond09:11:42

I've got a feeling it is built in to the ext4 filesystem maybe I can partition with a new fs

thheller09:11:37

well I can just shorten the name after a certain length. didn't expect anyone to use such long filenames ... but I guess everything exists on npm 😛

Ben Hammond09:11:29

that would be lovely if you would do that

❤️ 1
🙏 1
thheller09:11:28

should be fixed in 2.16.3

👏 1
Ben Hammond09:11:44

maybe reiserfs, if I can overcome scruples

Ben Hammond09:11:30

I'm still wrestling to understand the purpose of that file; it is intriguingly named

thheller09:11:49

according to the internet the max file name length is 255 bytes

Ben Hammond09:11:03

I think materialui is a common library, so I'm guessing alot of people will trip over this

thheller09:11:12

but the filename is only 193 bytes?

thheller09:11:29

only appears to be a linux issue. windows and mac seem to be fine

Ben Hammond09:11:37

yeah I didi not understand the length

Nathan K10:11:05

Hi all. Any thoughts on this re-frame code? It’s a basic input field, I’m trying to keep track of its value, and I’m rendering its value to a separate div. As written, it has some kind of performance problem, I’m not 100% sure why. (code in thread 🧵)

Nathan K10:11:14

(ns reframe-example.views
  (:require
   [re-frame.core :as re-frame]
   [reframe-example.events :as events]
   [reframe-example.subs :as subs]))

(defn main-view []
  (let [input-value (re-frame/subscribe [::subs/input-value])
        input-changed #(re-frame/dispatch [::events/update-input-value
                                           (-> % .-target .-value)])]
    [:div
     [:input.typing {:value @input-value
                     :type "text"
                     :on-change input-changed}]
     [:div @input-value]]))

Nathan K10:11:22

The event:

(re-frame/reg-event-db
 ::update-input-value
 (fn [db [_ val]]
   (assoc db :input-value val)))
The subscription:
(re-frame/reg-sub
 ::input-value
 (fn [db]
   (:input-value db)))

p-himik11:11:33

Your code is perfectly fine. There's an FAQ entry about that problem: https://day8.github.io/re-frame/FAQs/laggy-input/

Nathan K11:11:57

Interesting, I wonder why elm doesn’t have this issue with seemingly equivalent code. Maybe some difference in the event loop. Thank you for your help 🙏

👍 1
flowthing11:11:18

Looks like ClojureScript 1.10.879 and 1.10.891 behave differently when passing a map to a function that accepts keyword arguments:

λ clj -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.879"}}}' -M -m cljs.main --repl-env node -e '(defn destr [& {:keys [a b] :as opts}] [a b opts]) (destr {:a 1})'
#'cljs.user/destr
[nil nil {{:a 1} nil}]
vs.
λ clj -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.891"}}}' -M -m cljs.main --repl-env node -e '(defn destr [& {:keys [a b] :as opts}] [a b opts]) (destr {:a 1})'
#'cljs.user/destr
(node:62287) [DEP0097] DeprecationWarning: Using a domain property in MakeCallback is deprecated. Use the async_context variant of MakeCallback or the AsyncResource class instead. (Triggered by calling emit on process.)
(Use `node --trace-deprecation ...` to show where the warning was created)
Execution error (ExceptionInfo) at cljs.repl/evaluate-form (repl.cljc:577).
Execution error (Error) at (<cljs repl>:1).
No value supplied for key: {:a 1}
I understand why this throws an exception, but it took me by surprise since there's no mention of this in the change log. Could maybe add a note?

flowthing11:11:35

(The node deprecation warning is unrelated, dunno what that's about.)

flowthing11:11:07

(Also, it seems that there's 1.10.893 in Maven Central, but there are no release notes for it.)

thheller11:11:15

looks like a bug to me. best report it to jira or http://ask.clojure.org. slack tends to get lost

flowthing11:11:04

All right, will make an Ask post about it.

thheller11:11:30

hmm maybe its not actually a bug. CLJ behaves the same

flowthing11:11:06

Right, CLJ (prior to 1.11.*) behaves the same as 891. Our codebase had a couple of bad calls like that where things worked regardless with 879, but with 891 they throw.

dnolen12:11:16

@flowthing it's because a map bug was fixed, which is in the change log

flowthing13:11:03

Hmm, not sure which change log entry you're referring to, but all right.

dnolen13:11:52

@flowthing sorry, you were right, this one was missing added

dnolen13:11:51

was not intentionally left out - why I thought it was there - thanks for pointing it out

1
mortemeur23:11:18

If I wanted to create a website and wanted to make sure google saw it properly, should I use fulcro (which I know does awesome ssr) or can I use re-frame like I want to with some library?

athomasoriginal00:11:58

What kind of site are you creating? E.g. blog, app et al

mortemeur00:11:12

it's going to be a spa that's really interactive

athomasoriginal14:11:37

Right. I think what I was going to suggest is that Apps don’t have the same SEO requirements as a blog or marketing site. Thus, depending on what you are building, I would say you may not want to go the SPA route. You can still use CLJS if you like.

athomasoriginal14:11:13

Either way, this problem is unrelated to CLJS. So, the same tricks you would use in JS and React land would apply here and there will be more content written about the subject in general.

myguidingstar16:11:37

if you know fulcro well then yes, it has awesome ssr and I would highly recommend fulcro. But if you're not familiar with it, then there's a huge risk because it takes time to master fulcro