This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-15
Channels
- # aatree (1)
- # atlanta-clojurians (3)
- # beginners (112)
- # boot (4)
- # boot-dev (1)
- # bristol-clojurians (1)
- # cider (55)
- # cljs-dev (23)
- # cljsjs (1)
- # cljsrn (7)
- # clojars (24)
- # clojure (84)
- # clojure-brasil (1)
- # clojure-china (1)
- # clojure-italy (27)
- # clojure-norway (17)
- # clojure-romania (1)
- # clojure-spec (109)
- # clojure-uk (92)
- # clojurescript (94)
- # community-development (1)
- # core-matrix (1)
- # cursive (12)
- # datascript (1)
- # datomic (23)
- # figwheel (1)
- # fulcro (17)
- # hoplon (11)
- # jobs-discuss (3)
- # keechma (6)
- # lein-figwheel (4)
- # leiningen (79)
- # lumo (32)
- # mount (42)
- # off-topic (22)
- # onyx (13)
- # parinfer (30)
- # portkey (47)
- # powderkeg (1)
- # programming-beginners (24)
- # protorepl (3)
- # re-frame (16)
- # reagent (100)
- # ring-swagger (7)
- # shadow-cljs (134)
- # spacemacs (3)
- # sql (1)
- # tools-deps (48)
- # uncomplicate (1)
- # unrepl (14)
- # yada (1)
@lee.justin.m do you use shadow with lein integration?
@eoliphant I know I had issues with cljsjs/react-sticky ā6.0.1-0ā
It was due to some shifting in React libs around prop-types and incompatibility with the version of reagent/react I had.
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.
My workaround was to just drop the whole react-sticky js sources in a subdir of the project and :foreign-libs it for now š
(I too was just hurrying at the time) It sounds like @gadfly361 got it working on a newer version though,
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 sureyou may also try https://github.com/pesterhazy/presumably/blob/master/posts/double-bundle.md
I thought this looked like an interesting way to get npm libs into a cljs project without too much pain (and not using shadow)
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.
@lee.justin.m yeah, I havenāt messed around with it much
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
part of me wonders if the right solution isnāt to have the compiler control webpack instead of trying to replicate everything
well yes, except instead of making me configure webpack, have the compiler tell webpack what to do
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
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
seems to only work for a handful of cases. I havenāt invested time into trying to use that
Iād imagine trying to replicate something like webpack would not be an easy tasks either'
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
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
I was wanting to spend more time looking through shadows impl to get a feel for what it is doing
thanks @gadfly361!
How is component life cycle stuff handled? i.e. render something based on various rout params? (`componentWillMount`, componentDidMount
, etc..)
@njj , you need to use the create-class
function: http://blog.ducky.io/reagent-docs/0.6.0-alpha2/reagent.core.html#var-create-class
aka Form-3 components https://github.com/reagent-project/reagent/blob/master/docs/CreatingReagentComponents.md#form-3-a-class-with-life-cycle-methods
@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
@lee.justin.m you still switching on :view
in your routes?
I do actually. Itās not the simplest but it does enable me to keep history in my main store which has its uses.
can you share a snippet of that? @lee.justin.m
What is the recommended way to dangerouslySetInnerHtml
using reagent?
I'm using showdown.js as a markdown->html converter, and want to inject it's output into a react component.
Looks like an answer here: https://github.com/reagent-project/reagent/issues/14
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?Has anyone successfully integrated Highlight JS or a similar syntax highlighting library with Reagent?
I've added [cljsjs/react-highlight "1.0.5-0"] but can't seem to make it work
(:require [cljsjs.react-highlight])
(def highlight (r/adapt-react-class js/Highlight))
[highlight {:language "clojure"}
form-str]
It creates the right elements, but they don't get highlighted
@danielcompton Did you add CSS?
I think so
Looking in the inspector I don't see it rewritten with lots of DOM nodes though
and you might need to require cljsjs.highlight.lang.clojure
(from memory)
Or not might, you definitely need to require the language foreign-lib
Cljsjs highlight readme mentions this and lists the different namespaces: https://github.com/cljsjs/packages/tree/master/highlight
I'm using the React-highlight version, I'm not sure how different it is?
It is only a wrapper for HightlightJS
Haven't used it but I see it depends on cljsjs.highlight
Thoughts on a good approach to event handler
logic ^^
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
@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)}))
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."]))
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.
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...
(defn component
[]
(let [*local-state (reagent/atom nil)
handle-on-click (fn [e]
(.preventDefault e)
...)]
(fn []
[:div {:on-click handle-on-click}])))
if your handler is so complicated you want to unit test it you will need to split it off and pass params
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
This is likely the issue
Ohh, nope it's because of the CSS rules I had set
True. Are you, or anyone, aware of some well written open source reagent projects?
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/
I would say that is some very clean work. Thanks!
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/