Fork me on GitHub
#reagent
<
2018-03-15
>
justinlee00:03:11

shadow just works šŸ™‚

eoliphant00:03:44

yeah iā€™m tempted, but i have to have someting done by morning.

eoliphant00:03:01

this is a luminus generated project

eoliphant00:03:05

so there are some conventions

eoliphant00:03:09

that were causing some issues

eoliphant00:03:21

that never got around to resolvingā€¦ ugh

eoliphant00:03:03

@lee.justin.m do you use shadow with lein integration?

justinlee00:03:12

i donā€™t, no

justinlee00:03:27

but it is documented and iā€™ve seen people do it in the channel

eoliphant00:03:47

ok so just setup the paths and stuff in the shadow=cljs.edn

mikerod01:03:44

@eoliphant I know I had issues with cljsjs/react-sticky ā€œ6.0.1-0ā€

mikerod01:03:12

It was due to some shifting in React libs around prop-types and incompatibility with the version of reagent/react I had.

mikerod01:03:27

The getting nil problem you are having though is odd. Perhaps look at your generated JS and see if you can make sense of that.

mikerod01:03:55

My workaround was to just drop the whole react-sticky js sources in a subdir of the project and :foreign-libs it for now šŸ˜›

mikerod01:03:19

(I too was just hurrying at the time) It sounds like @gadfly361 got it working on a newer version though,

mikerod01:03:33

evaluating to nil seems odd. Perhaps it is just figwheel state being messed up

eoliphant01:03:03

Well i seem to have gotten shadow working

mikerod01:03:06

My :foreign-libs was

{:file     "flibs/cljsjs/react-sticky/development/react-sticky.inc.js"
                                                :file-min "flibs/cljsjs/react-sticky/production/react-sticky.min.inc.js"
                                                :provides ["cljsjs.react-sticky"]
                                                :requires ["cljsjs.react" "cljsjs.react.dom" "cljsjs.prop-types"]}
where I just made this directory. It is a non-elegant answer for sure

mikerod01:03:23

I was using [reagent "0.7.0"]

eoliphant01:03:16

Just ran regression on theapp and its fine. Trying react sticky next

eoliphant01:03:17

Yeah im on 0.7.0 as well

mikerod01:03:01

I thought this looked like an interesting way to get npm libs into a cljs project without too much pain (and not using shadow)

mikerod01:03:16

I havenā€™t tried it yet, but plan to soon

justinlee01:03:10

I have wondered with the uber webpack solution is as efficient as the shadow technique when it comes to libraries that are packaged in distinct modules. Obviously you can manually do it, but I wonder how much of a pain that is.

mikerod01:03:30

@lee.justin.m yeah, I havenā€™t messed around with it much

mikerod01:03:51

but if it ā€œworksā€ that may be good enough in some cases too

mikerod01:03:02

I mean if the bundle isnā€™t too large or whatever

justinlee01:03:21

thatā€™s true. iā€™ve heard that webpackā€™s docs are easier to understand now but i still have ptsd from the first time i tried to figure that thing out

mikerod01:03:33

I donā€™t know much about it either

mikerod01:03:37

I want to spend more time with it

justinlee01:03:24

part of me wonders if the right solution isnā€™t to have the compiler control webpack instead of trying to replicate everything

mikerod01:03:11

You mean just keep it separate?

justinlee01:03:04

well yes, except instead of making me configure webpack, have the compiler tell webpack what to do

justinlee01:03:11

or the build tool

justinlee01:03:41

shadow does both things and thatā€™s what i use so iā€™m really thinking off all the work thheller does to basically replicate a lot of webpack functionality

mikerod01:03:56

Yeah, makes sense

justinlee01:03:28

npm-deps in the main compiler doesnā€™t really work, as I understand it, because it doesnā€™t have a fully functioning module resolution algorithm. but webpack does

justinlee01:03:00

itā€™s a half baked idea

mikerod01:03:07

Yeah, I havenā€™t heard a lot of great things on its success as of yet

mikerod01:03:17

seems to only work for a handful of cases. I havenā€™t invested time into trying to use that

mikerod01:03:50

Iā€™d imagine trying to replicate something like webpack would not be an easy tasks either'

justinlee01:03:14

iā€™ve tried. it is completely non-functional. i donā€™t even understand how it could ever work for anything complicated. the npm ā€œmaximally flat treeā€ or whatever it does is INCREDIBLY complicated

justinlee01:03:23

where ā€œitā€ = npm-deps

justinlee01:03:42

I think you really want a package.json and npm

justinlee01:03:31

and then, to roll everything up, youā€™ve got a giant pile of ad-hoc code to deal with the 73 ways things can be packaged. webpack has already done that work, and to thhhellerā€™s great credit, he seems to have replicated most of it

mikerod01:03:29

I was wanting to spend more time looking through shadows impl to get a feel for what it is doing

mikerod01:03:44

Yeah, JS module world is crazy too in general šŸ˜›

justinlee01:03:56

and getting worse!

quang03:03:37

question, What's the best clojurescript web framework nowadays based on Re-agent?

gadfly36103:03:29

@quang re-frame is what you'll likely be interested in

gadfly36103:03:43

Keechma is a notable alternative

quang03:03:32

cljs-todomvc whoa very nice!

exit214:03:20

How is component life cycle stuff handled? i.e. render something based on various rout params? (`componentWillMount`, componentDidMount, etc..)

justinlee18:03:45

@njj note that you donā€™t need component life cycles just to render based on route parameters. you can just pass them to the render function

exit219:03:30

@lee.justin.m you still switching on :view in your routes?

exit219:03:48

I recall seeing a main page wrapper, and you populated :view on the routes

justinlee19:03:25

I do actually. Itā€™s not the simplest but it does enable me to keep history in my main store which has its uses.

exit219:03:15

can you share a snippet of that? @lee.justin.m

justinlee20:03:31

Itā€™ll be a couple of hours but sure

crinklywrappr20:03:51

What is the recommended way to dangerouslySetInnerHtml using reagent?

crinklywrappr20:03:36

I'm using showdown.js as a markdown->html converter, and want to inject it's output into a react component.

athomasoriginal21:03:42

Hey all, looking for an approach to solving this with Reagent. In React, I can do this:

class NewComponent extends Component {
    constructor () {
        this.state = {
            count: 0;
        }
    }
    render () {
        return (
            <div>
                <button on-click={handleOnClick}>
            <div>
        )
    }

    handleOnClick = () => {
        this.setStat() {
            count: this.state + 1
        }
    }
}
But if your working with reagent, where event-handlers and not stored in the component, I would have something like this:
(defn inc-count 
  [state]
  (fn 
    [e]
    (swap! state update-in [:curr-doc] inc))

(defn new-component 
  (let [state r/atom {:count 0}])
  (fn
    []
    [:button {:on-click inc-count state}]))
This is a simple example, so some would argue that its best to just inline the content of inc-count. However, lets pretend inc-count becomes more complex, inlining is going to be difficult to read, maintain and test. So one would think about making it its own function like the above example. The issue is, what if the logic in inc-count required more variables from the parent component. I would end up having something like:
(defn inc-count
  [state arg1 arg2 arg3 arg4]
      (fn
      [e]
      (swap! state update-in [:curr-doc] inc))
The difference between react and reagent is, generally, things get stored as state or props so there is less passing things into event handlers because I can just access this. I am not saying this is preferred, but maybe I am missing something?

danielcompton21:03:07

Has anyone successfully integrated Highlight JS or a similar syntax highlighting library with Reagent?

danielcompton21:03:38

I've added [cljsjs/react-highlight "1.0.5-0"] but can't seem to make it work

danielcompton21:03:20

(:require [cljsjs.react-highlight])

(def highlight (r/adapt-react-class js/Highlight))

[highlight {:language "clojure"}
               form-str]

danielcompton21:03:39

It creates the right elements, but they don't get highlighted

danielcompton21:03:48

Looking in the inspector I don't see it rewritten with lots of DOM nodes though

juhoteperi21:03:02

and you might need to require cljsjs.highlight.lang.clojure (from memory)

juhoteperi21:03:25

Or not might, you definitely need to require the language foreign-lib

juhoteperi21:03:06

Cljsjs highlight readme mentions this and lists the different namespaces: https://github.com/cljsjs/packages/tree/master/highlight

danielcompton22:03:03

I'm using the React-highlight version, I'm not sure how different it is?

juhoteperi22:03:16

It is only a wrapper for HightlightJS

juhoteperi22:03:47

Haven't used it but I see it depends on cljsjs.highlight

athomasoriginal22:03:33

Thoughts on a good approach to event handler logic ^^

justinlee22:03:18

@tkjone If doing it inline is too much, just bind a function inside of a let block

justinlee22:03:48

that has the nice property that you donā€™t have to pass stuff around ā€” the handler can just close over the local state and refer to it directly

justinlee22:03:03

it feels very much like an es6 class with methods

justinlee22:03:53

@njj the route handler looks like this

(secretary/defroute "/app/notebook/:notebook-id"
                    {notebook-id :notebook-id}
                    (reset! current-route {:page :notebook
                                           :notebook-id (str->int notebook-id)}))

justinlee22:03:30

then the toplevel is like this

(defn router-component
  []
  (case (:page @current-route)
    ...
    :notebook [home-component {:view :notebook :notebook-id (:notebook-id @current-route)}]
    ...
    [:div "Page not found."]))

justinlee22:03:40

it is simpler to just set put [home-component {:view :notebook :notebook-id (:notebook-id @current-route)}] in the atom directly and have router-component return the contents of the router atom. but if you do it this way, you can store the structured data in your main store and do stuff with it.

athomasoriginal22:03:44

Good point. I was exploring that option. That helps with readability and avoiding to pass down too many params, but I still draw issue with the fact that the function itself cannot be tested in isolation...not that this is an issue because in React the same thing would happen...

justinlee22:03:16

(defn component
  []
  (let [*local-state (reagent/atom nil)
        handle-on-click (fn [e]
                          (.preventDefault e)
                          ...)]
    (fn []
      [:div {:on-click handle-on-click}])))

justinlee22:03:31

right yea, itā€™s the same tradeoff as in react basically

justinlee22:03:56

if your handler is so complicated you want to unit test it you will need to split it off and pass params

justinlee22:03:34

but, basically, when I think to myself ā€œI want a methodā€, I do the above

danielcompton22:03:33

Hmm, I can get the highlighting working on the page that uses Reagent, but not one that has a custom mranderson shaded version of Reagent

danielcompton22:03:36

This is likely the issue

danielcompton22:03:16

Ohh, nope it's because of the CSS rules I had set

athomasoriginal22:03:01

True. Are you, or anyone, aware of some well written open source reagent projects?

burke07:03:13

I often look into the project "memory-hole" from yogthos. Don't know if it is well written but he is Mister Luminus - who else if not him, will be a good example for web (reagent and stuff) projects :thinking_face: https://github.com/yogthos/memory-hole/

athomasoriginal13:03:49

I would say that is some very clean work. Thanks!

burke07:03:13

I often look into the project "memory-hole" from yogthos. Don't know if it is well written but he is Mister Luminus - who else if not him, will be a good example for web (reagent and stuff) projects :thinking_face: https://github.com/yogthos/memory-hole/