Fork me on GitHub
#clojurescript
<
2017-09-28
>
dsapoetra00:09:40

Is there any good implementation on how to scroll to top using cljs?

anmonteiro01:09:52

@dsapoetra ?

(try (.scrollTo js/window 0 0)
     (catch :default _ nil)))

souenzzo04:09:35

(defn resolve
  [x]
  (let [p (string/split (str x) #"\.|\/")
        resolver (fn []
                   (loop [[s & ss] p
                          r js/global]
                     (if s
                       (recur ss (js/goog.object.get r s))
                       r)))]
    (when (resolver)
        (new cljs.core.Var resolver x nil))))
Is it a possible resolve function to commit to clojurescript? (sure, taking care about js/window/`js/root` and maybe better naming and others signatures) Due the late binding on js, maybe will make sense remove the when, allowing create Var to a "undefined" variable...

anmonteiro05:09:28

@souenzzo cljs.core/resolve already exists

benny06:09:07

any ideas why when i run my tests using karma everything builds but before running the actual tests, it just returns to a prompt?

benny06:09:26

running the tests directly via karma works just fine, it's when i run via lein that it stops

benny06:09:17

it's worth mentioning, I'm using re-frame as a guide to implement tests

rauh07:09:43

Hmm looks like React 16.0.0 productions builds defines y and Nb into the global namespace causing issues if you load React after your CLJS app... Adding these to the externs fixes it. Ugly.

pesterhazy08:09:37

Or using output-wrapper, @rauh ?

rauh08:09:06

No just using the UMD builds form . @pesterhazy

thheller08:09:34

@rauh that look suspicious, which unpkg url are you using?

thheller08:09:05

ah yeah that leaks indeed

rauh08:09:47

The 16.xx beta builds didn't have that issue. Should I open a React issue for this? Probably going to bite a few people

thheller08:09:52

https://unpkg.com/[email protected]/umd/react.development.js this has a proper UMD wrapper, no idea why the production version doesn’t include it

levitanong09:09:11

I’m getting a complaint from chrome that your cert is invalid.

thheller10:09:54

Odd, I’m using chrome as well without issue? The cert is from http://letsencrypt.org. Which chrome version are you on?

thheller10:09:18

Indeed it was configured incorrectly. Should be fixed now. Thanks for the heads up.

thheller08:09:32

Looking for a few testers that currently have to jump through hoops to make JS dependencies work.

thheller08:09:08

If you tried :npm-deps before and had issues with that this might work for you.

souenzzo11:09:51

Is it definitive? It doesn't fit in my use case because it's a macro :/

thheller11:09:19

@souenzzo resolving at runtime is not possible in CLJS due to :advanced compilation

pesterhazy12:09:52

What's the best way to customize the cljs.user ns when working with Figwheel? I.e. I want the dev:cljs.user=> prompt preloaded with functions, aliased namespaces etc.

souenzzo13:09:50

I use on-reload-ns

pesterhazy12:09:17

When I add a file called cljs/user.cljs on the classpath, it doesn't get loaded automatically (lein-figwheel "0.5.13"). I can require it in my core.cljs, but then it also ends up in production builds.

zakpatterson12:09:10

hey, can someone tell me why it's (require '[blah.blah]) in the REPL? What does '[xxx] mean? I know sequences literals have to be declared with quotes, but what does quoting a vector mean

mccraigmccraig12:09:15

@zakpatterson quoting the vector also quotes the symbols inside the vector - you could e.g. write (require ['clojure.string :refer ['join]]) at the expense of more quotes

zakpatterson12:09:55

Ah, that makes sense. so wait, now sequences don't make sense anymore, as (def x 2) '(x 3) produces (x 3) rather than (2 3)

zakpatterson13:09:10

i can get back to google too, that point about quoted vectors wasn't apparent to me

pesterhazy13:09:23

with a list, quote is special - it does two things: it quotes each of the members of the list and it prevents the evaluation of the list (i.e. it evaluates to itself rather than causing a function call)

pesterhazy13:09:27

if you only want to prevent evaluation without quoting the members, you can use (list x 2); if you want to quote members without preventing evaluation (which is silly mostly), you can do ('x '2)

pesterhazy13:09:04

Vectors are different because they never get interpreted as a function call - but you may still want to quote contents.

pesterhazy13:09:32

Almost everything in Clojure evaluates to itself - the exception are symbols (which evaluation to what they refer to) and lists (which evaluate as function calls)

pesterhazy13:09:39

Am I missing anything?

zakpatterson13:09:15

that's super helpful, i was mixing my understanding of '(x 2) with backtick syntax, like

`(~x 2) 
works

zakpatterson13:09:06

and the backtick operation seems to retain the notion of which namespace the variable existed in, rather than treating it as a raw symbol

pesterhazy13:09:08

yeah forget about backticks - that's advanced level macro business, not be touched in your 1st year in clojure

zakpatterson13:09:28

yeah i'm surprised I got this far without figuring the quoting thing out, i was about to write a macro

nwjsmith13:09:20

#inst "2017-09-28T13:08:49.019-00:00" will evaluate to a JS/Java Date

pesterhazy13:09:03

@nwjsmith yeah although arguably that's "itself" as if you print it you get the same string back

vinai13:09:42

@pesterhazy With the source paths compiler option in your build config (e.g. project.clj) to include the dev directory it works for me e.g. :source-paths ["src/cljs" "src/cljc" "dev"]

pesterhazy13:09:15

@vinai do you require the ns anywhere explicitly?

pesterhazy13:09:21

or do you do that from emacs?

vinai13:09:59

No, I don't require it explicitly.

vinai13:09:26

I do have the :repl-options {:init-ns user} set in my project.clj tough

vinai13:09:35

Not sure that is actually needed.

pesterhazy13:09:53

it's user, not cljs.user?

vinai13:09:09

@pesterhazy It's cljs,user. The repl.options was for the clojure repl.

vinai13:09:11

In the dev/cljs/user.cljs file the namespace declaration is (ns cljs.user).

lilactown15:09:58

can I use core.async and leiningen packages with lumo?

mfikes15:09:05

@lilactown If you want to use core.async with Lumo, you could consider Andare, which is a port of core.async that is compatible with self-hosted ClojureScript. https://github.com/mfikes/andare

mfikes15:09:22

If you want to use "leiningen packages" with Lumo, you really just need to put dependency JARs on Lumo's classpath, using Lumo's -c option or -D sugar

benny16:09:02

any suggestions for my karma testing question?

borkdude16:09:42

I’m testing our clojurescript app on the newest clojurescript (1.9.908) + clojure 1.9.0-beta1. I get this error in the console: “Uncaught SyntaxError: Invalid or unexpected token”

lilactown16:09:09

@mfikes thanks. I ended up just running with figwheel-node, I think the CLI app I'm writing is complicated enough to warrant it

borkdude16:09:32

It seems to be coming from the cljs.test namespace

mfikes16:09:57

@borkdude You are likely hitting a popular known issue... looking it up...

borkdude16:09:40

cool, so it’s fixed but not yet released

borkdude17:09:19

With the newest ClojureScript from master I get a warning in transit-cljs about uri? being redefined. I’ll file an issue at the transit-cljs repo.

borkdude17:09:43

Ah, it’s already there

mj_langford17:09:41

Is there a good example/tutorial/book chapter of a ClojureScript on node app out there?

turbopape19:09:05

just realeased version 0.3.0 of postagga, the easy natural language parser - now with more flexible parsing rule 🙂 https://github.com/fekr/postagga

lilactown20:09:00

I'm writing a node app in CLJS - what's the ceremony around accessing a part of the Node.js standard library e.g. fs?

anmonteiro20:09:30

@lilactown if you’re on CLJS 1.9.908:

(ns my-ns.core
  (:require fs))

anmonteiro20:09:32

that’s it!

anmonteiro20:09:15

then use functions as: (fs/readFileSync ...)

lilactown20:09:29

now to work on setting file reading/writing into using channels -_-

anmonteiro20:09:40

core.async channels?

anmonteiro20:09:35

shouldn’t be hard (untested):

(let [c (chan)] 
  (fs/readFile "foo.txt" #(put! c %))
  c)