Fork me on GitHub
#clojurescript
<
2016-08-26
>
hlolli11:08:14

After getting (cljsjs) react infinite to work, I wonder what would be benefitial using a react library for infinite scrolling versus just use cljs(closure event fns) to detect scrolling events and on designated point, fetch the needed data (say for a table) and concatenate it in a for loop?

vinodg12:08:54

any libraries for implementing scrollspy ?

chrisetheridge12:08:11

@hlolli i guess it depends on how well that library does the infinite scrolling, and what features of it you use. if you heavily use the library, there is nothing wrong with keeping it. but, if its just for a small component, it could be better to do it yourself. weigh the two up 🙂

hlolli12:08:30

this comes down a bit to what involves in infinite scrolling, read a stackoverflow reply from 2012 that the facebook infinite scrolling only stopped after 500Mbs were added to the memory trough firefox. Seems to me now when scrolling the newsfeed, that the elements are redisplayed. What im working on now is only text in a table, I think that I will just concatinate the text at certain points, and yes, just inject them into the memory of the user, except anyone knows of any trick to free the dom and reinsert them when scrolling up. The method Im thinking about would probably involve slow scrollup in case of long scrolldown.

hlolli12:08:28

and scrollspy, sounds like some tool I could use for this. Guessing doing a core.async event loop would slow things down a bit, but Im not sure.

nickt13:08:03

Hi all. Why does this macro throw a null-pointer exception during compilation? (defmacro ident [x] (var-get (ns-resolve *ns* x)))

shaunlebron13:08:48

@nickt: var-get is not in clojurescript that I can see

nickt13:08:17

I'm trying to write a macro that would inline the value of a constant variable during the cljs -> js stage

shaunlebron13:08:29

is that not what ~foo does? I rarely write macros

nickt13:08:45

something like....

(def my-class
  (.createClass js/React #js
    {:displayName (macros/ident constants/modal)
     ...}))
getting compiled to
React.createClass({
  displayName: "someConstantModalRelatedString"
})
as opposed to
React.createClass({
  displayName: hello_world.constants.modal
})

shaunlebron13:08:13

:displayName constants/modal would not be evaluated to that?

nickt13:08:38

no it gets evaluated to hello_world.constants.modal

nickt13:08:53

rather it gets compiled to that

shaunlebron13:08:51

(defmacro ident [x]
  `~x)
lol I’m spitballing

nickt14:08:10

I think I tried that

nickt14:08:12

I'll try it again

nickt14:08:01

yea it still resolves to a reference not to a constant

shaunlebron14:08:27

so var-get is getting the value at a var

nickt14:08:30

@shaunlebron definitely open to ideas, I'll keep trying it out 😛

shaunlebron14:08:51

in cljs, (deref #’foo) will get you the value at foo

shaunlebron14:08:05

in sort of a roundabout way

nickt14:08:57

maybe (deref (ns-resolve *ns* x)) ?

nickt14:08:53

don't think that worked

nickt14:08:57

@shaunlebron does that work at compile-tiem?

shaunlebron14:08:56

i’ll have to check the IDeref implementation for cljs vars

shaunlebron14:08:36

(defn ns-resolve
  "Given a namespace and a symbol return the corresponding var analysis map.
  Analagous to clojure.core/ns-resolve but returns var analysis map not Var.”
https://github.com/clojure/clojurescript/blob/7a06d008fadf56b11dba0f9e2ab97e61059f44fc/src/main/clojure/cljs/analyzer/api.cljc#L196-L199

shaunlebron14:08:02

@nickt: ns-resolve does not give you a var even

alpheus14:08:07

I'd like to include a file in my build that's not in the dependency graph of requires. I think that when using cljsbuild, the :main ns in the :compiler map is the root namespace and everything it leads to is built into the program. Can I add another namespace to the build somehow without having main require it?

alpheus14:08:12

FWIW, I'd like to include tests in the emitted JS to aid in automated regression testing.

nickt14:08:36

hm do you know if what I'm trying to do here is even possible?

shaunlebron14:08:30

if ns-resolve gives you an analysis map of a constant, you might find the value in there. it might just be a matter of inspecting that map and finding the right key

nickt14:08:07

how might I do that?

nickt14:08:16

i'm super new to this

shaunlebron14:08:03

same, I’m making some progress in test project, just poking around

nickt14:08:11

cool, I'm doing the same. Let me know if you find anything 🙂

shaunlebron14:08:29

@nickt: analysis map does not have a value "{:name test.core/foo, :file \"src/test/core.cljs\", :line 5, :column 1, :end-line 5, :end-column 9, :meta {:file \"/Users/swilliam/cljs-inline/src/test/core.cljs\", :line 5, :column 6, :end-line 5, :end-column 9}}”

nickt14:08:19

Dang... I feel like the compiler should have some way of identifying that this is a constant value

nickt14:08:27

and just swapping in the literal value at compile time

shaunlebron14:08:11

i’ll look at how the constant is emitted

nickt14:08:46

@shaunlebron so in the repl, (deref #'hello_world.constants/blue)

nickt14:08:52

gives the right value

nickt14:08:04

but it's hard to say whether or not that's runtime or compile time

darwin14:08:08

@nickt: didn’t follow the discussion from the beginning but I have done some “constant folding” at compile-time with macros

nickt14:08:21

that's exactly what I need 🙂

darwin14:08:24

you can use eval for that (carefully)

darwin14:08:46

if the code passed into macros can be eval’d at compile-time, you can just feed it into eval, or provide some boilerplate around, it is not a general technique, I have used it for concatenating CSS into single strings just to produce more optimized sources 🙂

darwin14:08:52

kinda what you want to do I guess 😉

nickt14:08:00

yea that's extremely similar to what I want

nickt14:08:14

any chance you have code available for that that I can look at?

nickt14:08:31

0_0 this looks so very much like what I need

darwin14:08:11

in my “sublanguage” I allow all clojure.core functions and my own devtools.defaults macros, as long as the body of css macro can be eval’d as this restricted clojure code, I can fold it at compile-time

darwin14:08:43

turned out to be good-enough for my use-case there

nickt15:08:01

what would be an example of something that doesn't fold?

darwin15:08:57

for example you thinking that you can use js-interop inside css macro, you can’t because the code there is clojure core

dnolen15:08:32

@alpheus if you want that file to appear consistently in your build you must require it

nickt15:08:35

ohhhh interesting, maybe the issue I've been having is that my constants are in cljs not in clj

darwin15:08:47

or using any other clojure function/macro in your project which is not exposed to the eval

nickt15:08:37

how can I write a clojure module that can be require'd by both cljs and clj?

alpheus15:08:38

@dnolen that's what I thought; since it's a test and requires the main namespace, it causes circular dependencies. So this may just be a bad idea.

darwin15:08:57

@nickt: not sure what is your goal, but you have eval only in clojure (via compile-time macro), you cannot feed it with cljs code

nickt15:08:46

@darwin but if my constants are defined in a cljc file, then I can eval them at compile-time in something like your css macro, but also reference them at runtime if I need dynamic calculations in my javascript, right?

nickt15:08:39

*in two separate places I mean

darwin15:08:19

this is pretty tricky topic, you can have constants defined in a clojure file, you can decide to “emit” their results as (evaluated) cljs variables

darwin15:08:33

you don’t need eval for this

darwin15:08:05

eval is needed if you are passed some “unknown” code from user of your macro and you want to emit another “code”

darwin15:08:12

in my css case, user of css macro gives me arbitrary code-like data structure, it happens to be evaluate-able by my eval function, so I eval it and then return concatenated string to be emitted in original place

darwin15:08:29

but I could also emit some cljs code based on eval results

shaunlebron15:08:05

the values of vars simply don’t seem available at compile-time to cljs macros

nickt15:08:07

oh... interesting. How do I "emit" their results as evaluated cljs varaibles?

darwin15:08:11

Macros are quite dense thing to learn, for me initially was very confusing and blurry the distinction between clojure (macros) and clojurescript (normal code). Because I came from Javascript lands, not from Java lands. So I happened to be first exposed to clojurescript and then when I started messing with macros with the whole Clojure/Java side which is a different thing on this level - it helps to understand how clojurescript compiler is implemented first. I would recommend this book: https://pragprog.com/book/cjclojure/mastering-clojure-macros

shaunlebron15:08:41

I traced (defmethod parse ‘def all the way to emit, and the constant expression isn't persisted anywhere for use at compile-time

darwin15:08:30

(at compile time) macro gets some data (which may be code) and emits some (other) data which happens to be code

nickt15:08:40

dang maybe I gotta really put some time into this... I'll be back in a bit, gotta do some work-related work 😛

shaunlebron15:08:06

@darwin: nice, I didn’t know you could put arbitrary data in compiler options and retrieve them at compile-time like that: (get-in @cljs.env/*compiler* [:options :external-config :devtools/config])

darwin15:08:20

@shaunlebron yeah, it is a gem, discovered it just recently thanks to @bhauman

darwin15:08:18

you should use :external-config to prevent warnings from figwheel validations, freshly written it could look like this: https://github.com/binaryage/dirac/blob/master/src/runtime/dirac/runtime/preload.clj

dnolen15:08:30

@alpheus if you’re making a test build than just make :main the test ns to avoid that circularity right?

alpheus15:08:55

That makes sense and I tried just that but when I ran the tests from the browser none were exercised. That's probably a different problem but I thought I'd better ask here, in case there was a well-known way of doing this.

dnolen15:08:51

@alpheus tests don’t automatically run, you need to invoke them via cljs.test/run-tests

dnolen15:08:25

there’s tooling out there to run them for you which is why you might not know you need to do this

alpheus15:08:30

I called run-all-tests

dnolen15:08:17

@alpheus so try run-tests on a particularly ns then to determine if there’s a bug or something here

alpheus15:08:30

I'll do that, and thanks

dnolen15:08:05

@alpheus yeah I can see there’s a bug with run-all-tests

dnolen15:08:27

oh hrm or not

dnolen15:08:34

anyways, try run-tests

alpheus15:08:33

That may solve my problem, but out of curiosity, how does the cljs.user namespace make it into the JS, and is there a way to add more there?

dnolen16:08:50

@alpheus cljs.user isn’t a thing, just something for the REPL

lwhorton19:08:23

is there an idiomatic way to invoke a fn that is a key inside a map? for example, it feels awk to do ((:some-fn my-map))

lwhorton19:08:36

(and error prone)

dnolen19:08:54

@lwhorton that’s how you do it

lwhorton19:08:46

hmm, okay, if that’s idiomatic its fine with me. personal taste says it reads easier when scanning to be something like (call :some-fn my-map)

dnolen19:08:06

@lwhorton sure but you can write that yourself, it’s not so common a pattern that anything needs to be done about it

Alex Miller (Clojure team)19:08:45

I would probably use get in that case to make it more readable

Alex Miller (Clojure team)19:08:29

although maybe that’s not any better since it doesn’t remove the double parens

Tim20:08:01

yeah, I’ve found double parens to be someone difficult to follow

Tim20:08:12

reminds me of double pointers or something

fenton20:08:55

do others find it difficult to spec functions that use core-async for backend comms? This seems where stubbing would be very helpful, that is to stub out backend service calls. However since core-async based functions only return channels, not request responses...how do other people tackle this issue?

fellshard20:08:57

I suspect it's something you get used to over time

shaunlebron20:08:17

@lwhorton: I only like primitives in the call position of a list, e.g.:

(let [some-fn (:some-fn my-map)]
  (some-fn))

shaunlebron20:08:51

or even:

(let [{:keys [some-fn]} my-map]
  (some-fn))

dotboris20:08:52

I want to build a little clojurescript library but I don’t know how to get started. Can someone point me to a simple example with tests and a repl?

erlis20:08:03

hi guys, do we have any "videos training" on clojurescript? Do we have any clojurescript in Pluralsight?

shaun-mahood21:08:16

@erlis: There's some good content at both https://purelyfunctional.tv/ and https://lambdaisland.com/, both are actively producing content. Pluralsight has some Clojure content but it is pretty old, and no ClojureScript content that I am aware of. Safari books have a few pieces of ClojureScript video content, but I've not watched any of it.

shaun-mahood21:08:12

Also, @ericnormand (http://purelyfunctional.tv) and @plexus (lambda island) are both great if you have questions about any of their content.

shaun-mahood21:08:27

Are you looking specifically for video, or would good written content help as well? There are lots of good ClojureScript specific resources available now, so if you have specific interests I'm sure someone here can recommend something.

erlis21:08:50

lambda island only have 15 videos

erlis21:08:31

I was watching @ericnormand with some of the free content. I was aware of the purely http://functional.tv site

shaun-mahood21:08:05

Yeah, it's not been active for long, but it's very reasonably priced and the content is excellent of the videos I've watched.

erlis21:08:27

I think the community is lacking of this type of material

erlis21:08:55

for example, recently I started to work on ReactJs + Redux

erlis21:08:18

Adam Abramov (creator of Redux) one guy, created tons of material so your start is easy

erlis21:08:29

for me it was a great learning experience

shaun-mahood21:08:25

@erlis: Is there a particular area you're having trouble with? I've found the available ClojureScript content is generally very good once you find it, but it can be difficult to find if you don't know where to look. I've heard the same comment from others who have previously worked with React + Redux, so it may be that their documentation is just that much better.

erlis21:08:09

you will see what I mean

erlis21:08:11

free content

erlis21:08:36

Just a comment about the video part

shaun-mahood21:08:03

That's awesome that it exists. The React and Redux community is definitely much larger than the ClojureScript community, so I'm not too surprised.

dnolen21:08:11

@erlis Dan sunk a ridiculous amount of time into that stuff

dnolen21:08:21

doesn’t have anything to do with size of the community

erlis21:08:25

I've found good material in clojurescript, the videos bring another dimension to the learning experience. You can see how people are using it, specially the more advanced users

dnolen21:08:29

you just have to want to do that kind of thing

shaun-mahood21:08:47

Oh wow, that's really impressive then

dnolen21:08:48

for free I might add

dnolen21:08:44

@erlis there are few things, but your assessment is correct

erlis21:08:14

I'm not saying anything about the size of the community, I've been trying to use clojureScript for a while and I've learning from tons of resources (good work out there) I was just comparing my personal experience while learning something new like Redux

dnolen21:08:17

@shaun-mahood’s suggestions are probably the best

shaun-mahood21:08:19

Not sure about others, but I find it way easier to learn from written or interactive content than video so it's not really bothered me.

erlis21:08:26

and the same experience while learning clojurescript

dnolen21:08:35

@erlis sure, work for somebody to do is all I am saying

dnolen21:08:22

based on Dan’s Twitter statements doing that kind of thing is also a good way to burnout

erlis21:08:33

I found one series "parens of the death" free on youtube, really nice

erlis21:08:57

I wish I have only 0.0001 the knowledge on clojurescript you have Nolen so I can do something for others... I'll keep learning though. Thanks for listening...

erlis21:08:12

don't burnout please 🙂

dnolen21:08:20

@erlis this is why I don’t make videos 🙂

dnolen21:08:29

ridiculous amount of work

dnolen21:08:11

@erlis I do know that PluralSight has asked about CLJS content before

dnolen21:08:28

so probably just a matter of someone who’s interested reaching out to them

erlis21:08:37

that will be great, in the meantime I'll check some content there for clojure. I was just surprised clojurescript is not listed

shaun-mahood21:08:14

@erlis: If you're interested in helping improve the situation I think we would all welcome it - I just noticed there's a bunch of video content listed on http://clojure.org/community/resources that hasn't been added to http://clojurescript.org/community/resources yet. I also think it would be safe to say that most of the community would be receptive to ideas to help the learning experience.

dnolen21:08:26

@erlis they have asked me several time but I don’t have time for it- I’m not sure how it works so maybe they want somebody that’s known in the community or something

dnolen21:08:47

but it might just be that no one’s offered

dnolen21:08:01

I’d be happy to help promote such a thing if someone was working on it of course

erlis21:08:57

most sure they want the very first course to be from someone known to promote it. But usually they have regular people that are "presenters" and they do this type of stuff, I love the coursed presented by Scott Allen known for his website Odetocode

dnolen21:08:44

@erlis that’s interesting to know

dnolen21:08:20

@erlis the Scott Allen stuff looks good

erlis21:08:33

don't know if any of those guys knows anything about Clojurescript, probably not. And probably that's why they are asking you

dnolen21:08:09

well if somebody else’s wants to actually do it and have me put a stamp on it I’d be happy to oblige

erlis21:08:26

maybe that's something you can tell Pluralsight if they contact you again. Also this is not free, they should pay for this

erlis21:08:31

site is not free

erlis21:08:05

I really don't know how Dan this all that, this guy is like a machine

shaun-mahood21:08:05

@erlis: Pluralsight authors get paid for sure, it looks like the really popular ones actually make a very good living.

erlis21:08:28

this can be a good incentive to someone from the community to put some content and see what happens, @dnolen said it can help with the material.

dnolen21:08:40

@shaun-mahood yes it seems like a pretty good deal for the content authors

erlis21:08:24

few years ago Pluralsight was BS, but they have been buying some of the best sites and authors and now their content is top notch

erlis21:08:04

they bought peepcode

erlis21:08:00

well, I think they bought everyone 🙂 just googled pluralsight adquires and you will see

erlis21:08:06

they have big money now

fellshard21:08:14

And they're focusing on curation a bit more now

shaun-mahood21:08:26

@erlis: http://purelyfunctional.tv is also looking for content authors - I don't think it's an issue of demand as much as the fact that video just takes so much effort - for a current example, the untangled videos are pretty recent and really good but I believe there are already portions of them that need updating. I can't imagine the amount of time it would take to keep up with some of the fast moving changes in the Clojure world, it's hard enough to do with text based documentation.

erlis21:08:36

@shaun-mahood thanks for the resources I'll take a look for what's there.

risto21:08:33

Has anyone thought about writing a time-travel debugger for clojurescript?

dnolen22:08:19

@risto not aware of anyone trying to tackle the general problem

risto22:08:13

@dnolen It definitely would be an interesting project. Since atoms are watchable, you can use them in almost the same way as Redux

risto22:08:12

I think you would need at least a lightweight reducer though because it rely's on foldp

dnolen22:08:33

@risto if you’re talking about for applications yes people have done that

dnolen22:08:02

but I’m not aware of a generic reusable thing

ag22:08:40

doesn’t om.next provide you “time/traveling” almost out of the box? or I’m confusing it with something else?

risto22:08:16

@ag I'm thinking more of something generic and reusable, like an instrument function that records history across changes in the atom

risto22:08:34

which you could rewind or write up your own interface for

risto22:08:50

something framework agnostic

dnolen22:08:00

@ag it gives you the structure for it but none of the helper stuff that might be useful

jasonjckn23:08:24

so I wrote a macro that references another namespace admin.core/app in the generated code, except when I compile my clojurescript it says admin.core/app is undeclared var by every cjls file that uses this macro I wrote. Any way for the macro definition to specify dependencies of the generated code?

darwin23:08:58

@jasonjckn: I would like to know as well, but I’m afraid it is not possible

darwin23:08:12

I tend to use same name for clj and cljs namespace (even empty) and in cljs namespace I add all dependencies possibly used by macro-generated code. In macros I then use fully-qualified names to dependent code (not aliases). And at macro call sites I tend to require macros via cljs namespace, which then implicitly brings dependencies along. Make sense?

jasonjckn23:08:40

@darwin thanks, that's what I attempting to do next 🙂

jasonjckn23:08:44

glad to know it's a pattern

darwin23:08:48

good luck, I wish there was a safer/better way how to add dependencies introduced via macros, another option might be to dynamically goog.require stuff and use js interop to reference it, but that seems to be way too low-level

darwin23:08:15

and might break under :advanced optimizations if not done extra carefully

jasonjckn23:08:09

my advanced broke long ago 😉

jasonjckn23:08:18

i'm a simple man

darwin23:08:31

hehe, simple men use copy&paste instead of macros 😉