Fork me on GitHub
#reagent
<
2018-02-28
>
jmckitrick12:02:06

Hi all! I’m working on a POC for our company that has me frustrated. Everything I’m doing so far works great, until I try to use these 2 components:

jmckitrick12:02:43

I’ve seen a variety of suggested approaches, from using webpack to :npm-deps, as well as others. Feeding the source for these 2 components into the externs generators online both generate the same error, that the target class I want to export is not found.

jmckitrick12:02:44

Is there a way to tell from reading the component code which approach is best?

jmckitrick14:02:50

So here’s what I discovered. I’m able to view both components only when I use webpack to build them and :foreign-libs to import them. On top of that, the gallery requires I use (.-default image-gallery) to access it. I’d rather use both of these components without the extra layer of webpack. How can this be done?

mikerod19:02:42

This is a good idea. Especially if the struggle gets too hard with :npm-modules or cljsjs. Thanks for posting and the example!

martinklepsch21:03:28

@pesterhazy I think in theory the double bundle approach could also work with :npm-deps and Closure’s module splitting stuff

martinklepsch21:03:21

In the long run :npm-deps will be nicer because we can delete dead code from dependencies. If you build both bundles differently that will be harder to utilize

pesterhazy21:03:10

I’d be curious how that might work

pesterhazy15:02:46

it's the pragmatic approach and, most importantly, it's guaranteed to work, because everyone else is using webpack

pesterhazy15:02:13

so if you run into issues, you can be sure that most other users are running into the same problems

pesterhazy15:02:03

granted, it's not philosophically pure, but you can use any npm/react dep you want without worrying

jmckitrick15:02:11

If so, I’ll stop wasting time to get it working, and read that article you linked @pesterhazy

pesterhazy15:02:45

full disclosure, I haven't tried the "new style" cljs integration options, because what I have (and have described in the article) just works

pesterhazy15:02:33

I personally would suggest trying that approach and embrace webpack as a secondary build tool

pesterhazy15:02:10

that's not an official recommendation from the core team of cljs though; I know they dislike webpack

pesterhazy15:02:41

also re: externs, I'd suggest using Simple Optimizations to get started

pesterhazy15:02:37

and only switch to Advanced once you have strong business reasons for smaller bundle sizes

pesterhazy15:02:59

I've built entire projects and never gotten around to switching to Advanced because it wasn't a priority

pesterhazy15:02:33

the upside is you bracket the entire host of issues surrounding externs and minification

pesterhazy15:02:01

then treat it as a separate step (and don't let it block your initial progress)

pesterhazy15:02:41

all react libs will just work that way (provided you understand JS interop and Reagent interop well)

jmckitrick15:02:00

ok, I’ll dive in and give it a shot.

jmckitrick16:02:15

Ok, I’ve got my POC working with your approach. Excellent!

justinlee16:02:11

nice approach @pesterhazy--thanks for sharing. @jmckitrick, by the way, you’re not crazy. for peons like me, the “new style” integration approaches like the one in that article have never worked for me and just wasted a bunch of my time. I’ll add two tips: one, instead of calling goog.object directly, use cljs-oops, which has some development-time debugging built in and is a little bit more ergonomic. second point is that if you don’t like the webpack approach (though honestly if it is working for you, I think it’s a good approach), there is also shadow-cljs, which so far has worked very smoothly for me and has webpack-like module bundling and splitting built in

jmckitrick16:02:15

@pesterhazy Is there any drawback to using aget rather than goog.object/get ?

jmckitrick16:02:09

@lee.justin.m Given that I want to reduce friction with non-cljs members of my team, I’ll stick with webpack 😉

thheller16:02:14

I'd argue that friction will be a gazillion times lower with shadow-cljs 😉

justinlee16:02:17

the reality is that aget will work but it is documented explicitly as to be used on arrays in its docstring. they’ve said they want to start adding runtime checks to it to warn when it is misused. reality is too much code abuses it so it’ll probably work always 🙂

justinlee16:02:09

i can testify that shadow-cljs is way easier than futzing with webpack but maybe using webpack will be a nice comforting blanket for your team

jmckitrick16:02:58

@thheller How so? I’m intrigued….

jmckitrick16:02:25

Disclaimer: I’ve just started reading about shadow-cljs

thheller16:02:35

well you can consume direclty from npm without any hacks or cljsjs

thheller16:02:56

you can also compile the output in a way so that the final build is done by webpack

jmckitrick16:02:49

@thheller What is an ‘HMR app’ ?

thheller16:02:16

hot-module-reload from webpack

thheller16:02:55

just a demo. its much worse than just using the built-in reloading for cljs.

thheller16:02:07

just demonstrating how you'd use CLJS inside a JS project

pesterhazy19:02:30

yeah shadow-cljs is another option to consider

pesterhazy19:02:02

gobj/get is recommended and aget may cause issues in the future, like @lee.justin.m mentioned

pmooser23:02:10

Do you guys have any advice for debugging when a component isn't updating as you think it should? I'm doing something sort of tricky where I'm passing in a completely different atom/cursor to a component to show a different historical state, and in the particular case of HTML input elements, I don't always see the state accurately reflected.

pmooser23:02:33

I may be doing something crazy but it's hard to boil it down to a minimal (shareable) example, but I'm also not having a lot of luck figuring out why it's choosing not to update.

gadfly36123:02:05

@pmooser take a look at this FAQ. However, if that doesn't help, I'd encourage you to try to boil it down as best you can .. difficult to help otherwise.

pmooser23:02:38

Thanks. It's none of those things, as far as I can tell, but I'll keep digging and let you guys know when I figure it out.