Fork me on GitHub
#clojurescript
<
2022-04-24
>
pinkfrog10:04:46

I’d like to provide the react/View with some default props. What’s the proper way to achieve it?

(def view (r/adapt-react-class react/View))
The function r/adapt-react-class does not allow to provide props

p-himik10:04:23

Create a wrapper component.

pinkfrog11:04:25

(defn view
  [& [x & xs]]
  ;; inspecting on the type of `x`.
  ;; if `x` is a map, then it is a prop map
  ;; otherwise it is a child
  ;; xxx
  (let [default-props
        {:auto-capitalize "none"
         :spell-check false
         :auto-correct false}]
    (into [:> react/View (merge default-props x)] xs)))
Reflecting on the type of the first argument seems too much boilerplate

p-himik11:04:48

Well, that's just payment for having the ability to have optional props. Quite a few people are unhappy about it because it makes it much harder to work with Hiccup. As an alternative, you can always require the users of your view wrapper to provide it with a props map as the first argument.

p-himik11:04:39

There's a similar problem with defn - it supports a lot of optional things different positions. The parsing code is quite a few lines.

p-himik11:04:18

Note that there are also r/props and r/children that could be useful here. But using them might also result in unnecessary JS<->CLJS data roundtrips.

pinkfrog11:04:24

Off the topic,

(let [[x & foobar] xs] ,,,)
what’s the typical naming of foobar, h ? t?

p-himik11:04:58

Nothing consistent, as far as I'm aware.

p-himik11:04:43

If you don't need that xs, I'd name it xs.

👍 1
pinkfrog11:04:58

For the r/children, inside a reagent component, say, form-1, I haven’t returned the hiccups (aka chidlren), what’s the meaning of accessing r/children ?

p-himik11:04:40

Not sure what you mean. I haven't checked it, but I think that instead of checking whether there are any arguments and whether the first is a map, you can just use r/props and r/children instead of the props that you pass into the component. So effectively, the passed props will be ignored by your code.

pinkfrog11:04:30

My question was:

(defn sign-in-screen
  []
  ;; the children, here rn/Text has not been returned.
  ;; what's the meaning of r/children?
  (r/children)

  [:> rn/Text
   "Sign in"])

p-himik11:04:36

r/children is a pure function, with an exception that it accepts one argument and will throw an exception if that argument is not a component.

p-himik11:04:59

So the case above is an erroneous usage of the function. And if you replace it with (this-as this (r/children this)), it will just be a no-op.

zelda-kobe12:04:32

is #ethereum still active?

p-himik12:04:04

If you mean specifically the channel, then its history seems to be an evidence enough. If you mean something CLJS-related, then could you please be more specific?

phill20:04:16

Does code splitting support some modules being for web pages and other modules being webworkers? (The use case given on https://clojurescript.org/guides/code-splitting is "to load only the code actually required to run a particular logical screen" which taken literally would seem to say all splits must participate in the same SPA, which would exclude web workers and multi-page web applications.) I tried putting :target :webworker into some modules in the compiler options, and did not notice an error message but I have not found webworker bootstrap js in the output.

ribelo23:04:11

there is probably a bug in destructuring in cljs, or at least it works differently than in clj

1
😮 2
ribelo23:04:06

;cljs
(let [{:keys [button_text button-text]} {:button_text "text1" :button-text "text2"}]
  [button_text button-text])
;; => ["text2" "text2"]

;clj
(let [{:keys [button_text button-text]} {:button_text "text1" :button-text "text2"}]
  [button_text button-text])
;; => ["text1" "text2"]

dpsutton00:04:51

It's a known issue. The target language cannot have hyphens and there can be collisions

🙀 2
phill09:04:30

I don't see it mentioned on "Differences from Clojure" (https://clojurescript.org/about/differences), nor in Jira either although I might have missed it. Therefore, I hope @U0BBFDED7 will pose a question at http://ask.clojure.org. By the way, is destructuring necessary to encounter the collision?