Fork me on GitHub
#clojurescript
<
2017-02-09
>
borkdude14:02:40

@nberger @drapanjanas Hi, I found a snippet about lazy loading here: https://gist.github.com/nberger/b5e316a43ffc3b7d5e084b228bd83899. It’s not clear to me how I could use it, do you have an example of its usage?

hlolli14:02:09

Is there a way to stop or restart a nodejs repl session that was started via piggyback? Hoping to restart to cljs repl without restarting cider.

dorianc.b15:02:11

Is it possible to use clojurescript on static site generators like jekyll, hexo or hugo instead of javascript? I know clojurescript compiles down to javascript so does that mean I can just replace the javascript in a theme with clojurescript?

dorianc.b15:02:07

@isak thanks, I was thinking about picking up going to javascript but the though of going back to an imperative language but it was....difficult

dnolen15:02:11

@dorianc.b it’s really easy, I have a Jekyll blog where all the JS is ClojureScript

borkdude16:02:08

Is it possible to destructure js properties as in {:keys [a b]}?

borkdude16:02:56

maybe (let [{:strs [a b]} (js->clj o)] …) is the closest then

jr16:02:00

you can extend object type with ILookup in your application

jr16:02:09

not recommended for a library

jr16:02:31

(extend-type object ILookup (-lookup [o k] (aget o k)))
and you'll want to provide the not-found arity as well

jr16:02:12

and then destructure with {:strs []}

miikka16:02:51

By the way, is it possible to look up the names of defrecord fields after closure has renamed them in :advanced mode? Other than parsing them from the string representation of the constructor function?

thheller16:02:51

@miikka (defrecord Thing [field]) (:field (Thing.)), keyword access always works for records

miikka16:02:17

Yeah but if you need the actual names of the fields for some JavaScript interop

thheller16:02:10

hmm don't think that is possible

thheller16:02:26

there is some stuff in goog.reflect but I doubt that works

miikka16:02:01

Oh! goog.reflect.objectProperty looks useful. Thanks for the pointer.

thheller16:02:10

let me know if it works, never actually used anything other than sinkValue 😛

miikka16:02:13

Well, it's a bit tricky since it takes as an argument a string literal. But I guess it'd be possible to do something nice with sufficiently advanced macro trickery.

thheller16:02:06

what kind of JS interop are you doing that you are passing records into it?

thheller16:02:06

maybe externs can help to prevent the rename?

miikka17:02:03

I'd like to feed records to Vega (https://vega.github.io/vega/), which does string-based property access and code generation under the hood. Externs are fine for solving this, but I was thinking that maybe I could do something more automated.

dnolen17:02:47

@miikka pretty sure we have (.getBasis Foo) ?

dnolen17:02:21

but as @thheller implied, you can't use these directly, you might need to use reflect (but not sure if that’s applicable here)

dnolen17:02:16

you can of course use getBasis plus conversion to keyword

miikka17:02:32

Yeah, getBasis gives the CLJS names of the fields and reflect would give me the renamed property names except that it takes string literals, so I can't just apply it to getBasis results at runtime

dnolen17:02:44

oh I missed the part about Vega

dnolen17:02:00

yeah dunno then

dnolen17:02:39

@thheller interesting though it always so annoying that these posts have the Google spin

dnolen17:02:02

I think JavaScriptCore has like 10X fewer engineers than V8

thheller17:02:43

yeah but I agree with the point that benchmarks typically do not reflect real world results

thheller17:02:12

real world apps usually do not do the same thing 1.000.000 times

thheller17:02:25

it is nice to know though that the Closure Compiler (probably) does the most efficient thing already which we get for free

octahedrion18:02:00

does clojurescript not have extends?

jr18:02:41

it does

octahedrion19:02:03

well, I have a cljc ns that's fine in a clojure repl, but won't compile in cljs with errors: WARNING: Use of undeclared Var myns.core/extends?

negaduck19:02:03

here is a solution

negaduck19:02:23

oh, I’m sorry, wrong channel

jr19:02:01

are you checking that an object satisfies a protocol?

jr19:02:19

(satisfies? Protocol obj)

octahedrion19:02:45

WARNING: Can't take value of macro cljs.core/satisfies?

octahedrion19:02:10

...maybe i should find another way altogether

Pablo Fernandez19:02:11

When I run lein cljsbuild once, my app compiles without errors, but when I start a ClojureScript REPL using figwheel, I get this error: No such namespace: cognitect.transit, could not locate cognitect/transit.cljs, cognitect/transit.cljc, or Closure namespace "cognitect.transit". I did include [com.cognitect/transit-cljs "0.8.239"] in my project.clj. Any ideas what's going on?

borkdude19:02:46

I need to write something like this in ClojureScript:

<List …>
I tried:
(def List* (.createFactory js/React js/ReactVirtualized.List))
and then:
(List* …)
but I get: Warning: Something is calling a React component directly. Use a factory or JSX instead. What I am doing wrong?

jr19:02:11

are you using reagent?

Pablo Fernandez19:02:12

@borkdude: have you tried [(reagent/adapt-react-class js/ReactVirtualized.List)]?

borkdude19:02:50

I’m trying to write this example in cljs: https://github.com/bvaughn/react-virtualized/blob/master/docs/InfiniteLoader.md#examples (search for list to see what I’m trying)

borkdude19:02:02

Yes, I am using reagent, but I can’t use [....] I think (just look at the example)

Pablo Fernandez19:02:33

borkdude: yes, you can use [...], but it requires a reagent component.

Pablo Fernandez19:02:04

reagent/adapt-react-class adapts a react component (class) into a reagent component (function)

Pablo Fernandez19:02:28

(def list* (reagent/adapt-react-class js/ReactVirtualized.List))

nberger19:02:21

Also fixed a couple issues with the infinite-scroll logic itself. Use it at your own risk though 🙂

borkdude19:02:52

@pupeno Yes, but does that work in this example?

<InfiniteLoader
    isRowLoaded={isRowLoaded}
    loadMoreRows={loadMoreRows}
    rowCount={remoteRowCount}
  >
    {({ onRowsRendered, registerChild }) => (
      <List
        height={200}
        onRowsRendered={onRowsRendered}
        ref={registerChild}
        rowCount={list.length}
        rowHeight={20}
        rowRenderer={rowRenderer}
        width={300}
      />
    )}
  </InfiniteLoader>

borkdude19:02:12

The InfiniteLoader expects a function which returns a component

borkdude19:02:45

@nberger thanks, I’ll check it out!

thheller19:02:15

(js/React.createElement List #js {} ...) is equal to jsx <List ...>

Pablo Fernandez19:02:49

Yeah, in that case, you should just create the react element, but if you needed to pass a reagent component, you should use reagent/as-element

borkdude19:02:55

Hmm, with js/React.createElement js/ReactVirtualized.List, I still get the same error message

borkdude19:02:40

Ah, the error is coming from row-renderer* now I think

thheller19:02:18

uhm I don't know enough about reagent, I don't understand what all that means

thheller19:02:08

but if you just do the (js/React.createElement List ...) call alone it should work?

thheller19:02:39

what is :>?

thheller19:02:44

just do React.createElement for that bit as well? 🙂

borkdude19:02:10

Got it… If I replace row-renderer with:

(defn row-renderer []
  (js/React.createElement "div" #js {} “foo”))
the errors disappear

borkdude19:02:53

@thheller :> is short for adapting a reagent component to a react component

borkdude19:02:05

no sorry, the other way around 🙂

borkdude19:02:38

Someone out here who can help me with upgrading a cljsjs package? I need the checksum, but it doesn’t print it

borkdude19:02:44

it’s the only thing I need before committing

Pablo Fernandez19:02:28

There are #reagent and #cljsjs channels as well.

borkdude19:02:24

@pupeno Thanks, I already spammed those 🙂

borkdude19:02:47

Also solved now.

borkdude21:02:27

if I want to return a promise in clojurescript, can I use goog.Promise?

borkdude21:02:11

I guess I can just use a vanille JS one

jr21:02:37

I tend to reach for closure features because they are backwards compatible