Fork me on GitHub
#reagent
<
2019-08-03
>
cljfun07:08:19

doya installed react-window kamponen

hulunote07:08:58

@barikoi the react-window is npm package

hulunote07:08:30

figwheel: cljsbuild/dev/compiler { :npm-deps {:react “16.8.6” :react-dom “16.8.6" :react-window “1.8.5”} :install-deps true}

cljfun07:08:43

dats great

cljfun07:08:01

(def react-comp (r/reactify-component exported))

cljfun07:08:24

is this line needed to be reactifyed?

hulunote07:08:02

I think it can be used, but this is not the point. I think the root of the error is figwheel npm package support problem.

hulunote07:08:25

@barikoi because i test this component in the shadow-cljs,is work.

cljfun07:08:37

i dont' usually use figwheels buildin npm setup, i think it's still sorda expermandal use figwheel along with webpack works great for me

hulunote07:08:55

@barikoi this project is shadow-cljs & react mixed project .

hulunote07:08:38

I export the MyComponent to jsx ReactDOM.render to render , is work.

hulunote07:08:51

but just for test.

cljfun07:08:24

u-needta webpack.config.js as -

cljfun07:08:42

module.exports = {
  entry: './src/js/index.js',
  output: {
    filename: 'index.bundle.js'
  }
}

cljfun07:08:08

an on src/js/index.js

cljfun07:08:19

import React from 'react';
import ReactDOM from 'react-dom';
window.React = React;
window.ReactDOM = ReactDOM;

cljfun07:08:50

use npm deps as false

cljfun07:08:54

{:main hello-world.core
 :npm-deps false}

cljfun07:08:32

on dev.cljs.edn

cljfun07:08:43

{:main hell-world.core
 :npm-deps false
 :infer-externs true
 :foreign-libs [{:file "dist/index.bundle.js"
                 :provides ["react" "react-dom"]
                 :global-exports {react React
                                  react-dom ReactDOM}}]}

cljfun07:08:18

it's a boiler plate for figwheel-main

cljfun07:08:53

in shadow-cljs tis just audamadic

hulunote07:08:40

this code is word in the shadow-cljs .

hulunote07:08:56

this code is work in the shadow-cljs .

hulunote08:08:39

I got this error

vikeri12:08:05

I need some interop help. How can I emulate the following in Reagent

vikeri12:08:42

Specifically the {({height, width}) => ()} part

David Pham12:08:59

Where is Row defined?

jahson12:08:54

@vikeri You could create an effect for resize event

jahson12:08:13

That will dispatch an event

David Pham12:08:47

Or a listener on the resize event

David Pham12:08:00

Dispatching the height and width

jahson12:08:08

Like

{:on-resize {:dispatch ::evt}}

jahson12:08:30

The ::evt handler will get the width and height from the fx

vikeri12:08:20

Not really following, are you saying I should implement this in another way?

jahson12:08:56

So, in order to get something similar to what you mentioned above, you need to create an effect, setup it and then it will start sending you the events. The event handler should put data somewhere in your db. Then you shold subscribe to this data in some component, you could call it auto-sizer, and then this component could pass the width and height into its children. I'd prefer to use data in place, instead of adding another component, there will be not so much difference.

jahson12:08:23

[auto-sizer
  [x] [y] [z]]

jahson13:08:54

or

(let [w @(rf/subscribe [:window/width])
      h @(rf/subscribe [:window/height])]
  [:<>
    [x w h] [y w h] [z w h]])

jahson13:08:03

I forgot it's about reagent, my bad

jahson13:08:58

@vikeri I'm sorry about misleading you, need to switch my brain to reagent mode

jahson13:08:55

In case of reagent you will need to create an component that will handle all of this

(ns some-ns
  (:require [reagent.core :as r]
            [goog.events :as events])

(defn auto-size [& children]
  (r/with-let [size (r/atom nil)
               handler #(reset! size {:width js/window.innerWidth :height js/window.innerWidth})
               _ (.addEventListener js/window events/EventType.RESIZE handler)]
    (into
      [:<>]
      (map put-a-size-in-child children))
    (finally (.removeEventListener js/window events/EventType.RESIZE handler))))

jahson13:08:22

NB: code above is just a stub

jahson13:08:30

You should at least debounce

jahson13:08:42

Another concern is that each time we use the auto-size component, we're creating another listener. Looks like it might be better to create r/atom in namespace instead of component, and setup our listener globally too.

jahson15:08:13

Hope I fixed my initial confusion.