Fork me on GitHub
#reagent
<
2017-02-09
>
borkdude15:02:03

Is there a way to return React dom nodes from a function that normally returns hiccup for Reagent? I need it for React interop with the InfiniteLoader from React-Virtualized.

pesterhazy16:02:35

react-virtualized is awesome by the way

pesterhazy16:02:44

I have some sample code if you need it

pesterhazy16:02:50

for reagent I mean

borkdude16:02:02

@pesterhazy That would come in handy I think!

borkdude16:02:56

There might also be something in Reagent that takes care of this?

(defn is-row-loaded [props]
  (let [{:strs [index]} (js->clj props)]
    …)

borkdude16:02:06

the destructuring part I mean

pesterhazy16:02:49

didn't have time to clean it up too much, hope it's helpful anyway

pesterhazy16:02:31

ah. no unfortunately not

pesterhazy16:02:02

probably better to do (let [index (goog.object/get props "index")])?

pesterhazy16:02:41

js->clj is not perfectly reliable and may do too much work

pesterhazy16:02:55

I agree it's cumbersome

borkdude16:02:56

I’ll just use plain interop then

pesterhazy16:02:17

if you plan to use adv compilation, goog.object/get is your best option

borkdude16:02:31

why is this? I’ve heard it before vaguely

pesterhazy16:02:12

google closure minifies property names

pesterhazy16:02:31

so it will break direct access like (.-index ...)

borkdude16:02:43

ah, of course

borkdude16:02:01

I almost never run into this, but that’s of course because of proper cljsjs externs

borkdude16:02:13

But in this case that must work too I guess

pesterhazy16:02:19

yeah externs don't apply in all cases, e.g. callbacks

borkdude16:02:12

goog.object it is then

borkdude16:02:54

@pesterhazy What does this notation mean? :> js/ReactVirtualized.AutoSizer

pesterhazy16:02:11

short cut for adapt-react-class

borkdude16:02:18

Ah, r/reactify-component

pesterhazy17:02:43

nope, adapt-react-class

borkdude17:02:25

yeah, I meant the other way around, the utility I was searching for

borkdude17:02:59

but :> is now also clear, thanks for the link

borkdude17:02:01

Hmm, > Uncaught Error: InfiniteLoader.render(): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.

pesterhazy17:02:00

you need to return e.g. (r/as-element [:div ...])

borkdude17:02:06

The problem is in the List

borkdude17:02:05

Maybe I should write: (r/create-element js/ReactVirtualized.List #js {…}), but that doesn’t work either

borkdude17:02:48

Turns out List isn’t even defined, doh

borkdude17:02:30

I’m working with “7.11.8-1” because that was the latest on cljsjs

pesterhazy17:02:00

yeah it's a bit outdated

gamecubate17:02:08

Hi all. core.logic for facts & queries, +reagent for web front-end decision tree for our users. Does it make any sense to even consider using those two birds together?

gamecubate17:02:32

A lot of systems and constraints make for non-intuitive decisions in the course of our work, hence the desire on my part, to let core.logic do the dirty work of ifs-and-thens.

gamecubate17:02:50

But not sure how to tie query results

(run* [q] …)
to reagent component defs:
(defn advice-component [] (if (run* [q] …
? Could it be that simple?

gamecubate17:02:26

Realize I need to test if no one has done this before (doubtful) but googling for this = nil.

borkdude19:02:21

Ok, now I upgraded the cljsjs package myself. I get: Warning: Something is calling a React component directly. Use a factory or JSX instead, for:

(r/create-element js/ReactVirtualized.List
                         #js {...})
I’m trying to imitate this example in JSX:
<List .... />

borkdude19:02:54

Wrapping it in a createFactory gives me the same message, like so:

(def List* (.createFactory js/React js/ReactVirtualized.List))
and then:
(List* #js {…})

nrako20:02:57

@borkdude you might try (aget js/ReactVirtualized "List")

borkdude20:02:34

It’s already solved now. I used js/React.createElement js/ReactVirtualized.List

borkdude20:02:54

but there was also a problem with r/reactify-component, I had to wrap that result in a factory as well

nrako20:02:50

with the aget mentioned above, I think you could use something like this- (def List (aget js/ReactVirtualized "List") and then to call it in code [:> List ... ]

nrako20:02:26

or I should say, I have used that before, but not sure if it would for that lib 🙂

borkdude20:02:18

Yeah, in this case it doesn’t fit the pattern, because I need to give React a function that returns a component