Fork me on GitHub
#clojurescript
<
2017-11-09
>
fabrao01:11:14

Has anyone made working project with nmp-deps and install-deps?

fabrao01:11:35

I see the module in node_modules but I don´t know how to use it in require

fabrao01:11:50

I tried a simple module like dialog in https://www.npmjs.com/package/dialog and tried to use like (:require ["dialog" :as dlg]) or (:require dialog) but got compiler error

fabrao01:11:29

Am I missing something?

qqq03:11:59

I know about the 300ms delay. I kn,ow about hammer.js Is there some cljs package I ca just require, and have all cljs events not have 300ms delay?

madstap03:11:59

@fabrao I got an error because I had an old node version, which version of node are you on?

madstap03:11:22

I was on an ancient one, don't remember which, and upgraded to 8.6.0, which solved my problem. Yours doesn't seem that old, but I dunno. Maybe post the error you're getting. Your :require seems ok.

fabrao03:11:24

Uncaught Error: Undefined nameToPath for dialog

madstap03:11:04

Try to upgrade your node version and do rm -r node_modules? ¯\(ツ)

fabrao03:11:22

ok, I´ll do it, thanks 4 ur help

fabrao04:11:12

java.lang.AssertionError: Assert failed: cljs.analyzer/foreign-dep? expected symbol got "dialog" (symbol? dep) have you seen this? @madstap

fabrao04:11:35

the node version is 9.1.0

madstap04:11:57

Yes I have. I get that error a lot. When I do rm -r node_modules it goes away ¯\(ツ)

madstap04:11:58

I added "node_modules" to :clean-targets in my project.clj, which feels horribly hacky, but it's convenient.

madstap04:11:01

That way node_modules is deleted when I do lein clean

fabrao04:11:38

I´ve already deleted the node_modules before start repl

fabrao04:11:56

and before updated node

fabrao04:11:59

how do you use it in require?

fabrao04:11:40

["dialog" :as dlg] or dialog direct?

madstap04:11:41

["dialog" :as dlg]

fabrao04:11:16

I´m starting it again, maybe emacs cache?

fabrao04:11:39

I don´t know what is the problem, the problem is the same after removing node_modules and starting it again

fabrao04:11:50

may be Windows problem?

madstap04:11:28

Yeah, I'm on linux so it might be a windows issue. What works for me is just spamming the delete node_modules command. I don't actually understand this stuff, so let's hope someone that does sees this and can help.

Sebastian07:11:01

So, I got another question: I'd like to do some basic dom manipulation and I'm not ready to pull in reagent. I'd rather have something like jQuery. I looked at all the available solutions (jayQ, dommy, hipo, Domina) and it seems they all stopped being developed. Is there anything I'm missing?

Pushkar08:11:31

I'm using Material UI Can I add Scroll to autocomplete?

p-himik08:11:42

@sebastian.goettschkes Depends on what you mean by "basic". If you need only API that's uniformly supported within all modern browsers, you don't really need any library - just use JS interop. That was the reason why I stopped using Domina and didn't turn to any other library - they all offer a thin layer that in the end doesn't really give anything, at least with my usage.

Sebastian09:11:10

@p-himik What I need is some toggling of css classes, logic on form submit, ... It's a prototype so I don't want to invest in a big framework upfront. In the past I just plugged in jQuery and I was now looking for something more in line with Clojurescript

sundarj09:11:04

but also, a lack of activity on a clojure(script) project isn't necessarily a bad thing: it often just means it's stable

fbielejec09:11:26

I'm giving a shot at the new :npm-deps, trying to pull https://github.com/s-yadav/react-meta-tags :

:compiler {
   ...
  :install-deps true
  :npm-deps {:react-meta-tags "0.3.0"}}
I get Error: Can't resolve 'react' in '.../node_modules/react-meta-tags/lib' When I look at package.json for react-meta-tags:
"peerDependencies": {
    "react": "^0.14 || ^15.0.0 || ^ 16.0.0",
    "react-dom": "^0.14 || ^15.0.0 || ^ 16.0.0"
},
"dependencies": {
   "prop-types": "^15.6.0"
},
Looks like peerDependencies are not being pulled (not in node_modules)?

sundarj10:11:48

@fbielejec peerDependencies are not meant to be pulled. they're for a user of a library to install themselves: https://docs.npmjs.com/files/package.json#peerdependencies

fbielejec10:11:26

fair enough; so I'd rather add them

:npm-deps {:react "16.0.0"
           :react-dom "16.0.0"
           :react-meta-tags "0.3.0"}
or add them as a dependency for lein npm? Or perhaps doesn't matter, as long as they end up in node_modules? I believe npm install would print a warning if peer deps are absent - it'd be helpfull is it was preserved in the context of :npm-deps

sundarj10:11:59

i'm not too sure. i would expect that any method of installing the deps would work

fbielejec10:11:21

experimented for posteriority - it's the former 😉

gfredericks13:11:21

https://github.com/clojure/clojurescript/commit/d717b4edea074fcfd3e718a6134238ba26f76f82 I don't know how web web browsers work -- is there some flag to opt-out of ES6 to make old code work again?

gfredericks13:11:23

I have some cljs things compiled decades ago and I would like them to start working again without recompiling if that's easy for some reason

gfredericks13:11:02

man I had the impression browsers were pretty committed to backwards compatibility

sundarj13:11:59

oh, they are. but js engines are a black box to us, so any changes they do make to them are non-negotiable

gfredericks13:11:42

oh I wasn't asking about a flag in CLJS; I was thinking some kind of html attribute on the script tag or something

gfredericks13:11:49

e.g., you can opt-out of HTML5, correct?

sundarj13:11:23

nah, even with no doctype present HTML5 stuff works

gfredericks13:11:40

I'm not asking about opt-ing in to HTML5

gfredericks13:11:45

I'm talking about running really old code

gfredericks13:11:50

on modern web browsers

gfredericks13:11:02

e.g., html from 20 years ago still renders okay afaik

sundarj13:11:11

right yeah, HTML and CSS are much more backwards-compatible than JS is

gfredericks13:11:12

so I was wondering if javascript from 4 years ago also had some hope of running

andrea.crotti13:11:48

I was checking how to change the current location in clojurecsript This according to http://clojurescript-reference.mattho.com/javascript/index.html should work in theory (aset js/window.location "location" "") but doesn't seem to do anything and not failing either, any idea?

sundarj13:11:36

that would be setting window.location["location"] no?

sundarj13:11:01

should just be (set! (.-location js/window) url)

mfikes13:11:51

@sundarj's suggestion is the correct approach. If, for some reason you want to use a string for a property name

(goog.object/set js/window "location" url)
would be correct, while using aset is incorrect (being meant only for setting values in JavaScript arrays).

sundarj13:11:06

@gfredericks JS isn't a lisp, so any new syntax/semantics will be backwards-incompatible. HTML on the other hand, is quite lispy in that you can continually add new elements to it without changing the existing syntax/semantics

gfredericks13:11:01

@sundarj but you could imagine having different versions of js available in the browser, same as html

sundarj13:11:44

@gfredericks you could, and i think that would be a far better way of doing things - but, alas, that is not the case

gfredericks13:11:00

Javascript is the future!

borkdude14:11:07

What does (set! (.-x y) 10) expand into?

borkdude14:11:49

Nothing, it’s a special form right?

bronsa14:11:57

just (set! (. y -x) 10)

thheller15:11:09

(.addEventListener thing "load" (fn [e] ...)) .. using set! will override any other.

borkdude15:11:25

Hmm… still not working. Maybe the error is somewhere else:

(.addEventListener img "load" (fn []
                                      (debug "drawing the image")
                                      (.drawImage ctx img 0 0)))
      (set! (.-src img)
            (str "data:image/svg+xml;charset=utf-8,"
                svg-string))

thheller15:11:33

uhm why do you need the load event? it isn’t loading anything if you set the source?

thheller15:11:48

thats not an URL, so it doesn’t do a network request

thheller15:11:59

just draw after set!

the-kenny15:11:34

no, you can't draw right after setting src, even for data-uris.

thheller15:11:13

really? doh

the-kenny15:11:19

borkdude: tried adding the image to the dom to see if it even loads correctly?

borkdude16:11:00

I’m trying that right now

jrbrodie7716:11:57

Does anyone know how create a view function in Re-frame that returns HTML instead of Hiccup? My app displays a graph that is generated HTML from the backend. I'm wondering how to dump that into my page...

scaturr16:11:03

you can use the :dangerouslySetInnerHTML property provided by react

scaturr16:11:34

something like [:div {:dangerouslySetInnerHTML myGraphHTMLString}]

jrbrodie7716:11:41

Cool, thanks!

orestis16:11:20

Tried adding an onerror listener too?

rauh16:11:57

@borkdude What is img in your code? I have something like this working for webp detection. Though I'm using (gobj/set img "onload"...)

borkdude16:11:55

@orestis Yes, did that. I get an error. Thanks!

borkdude16:11:31

@rauh img is (js/Image.)

borkdude16:11:15

Apparently it doesn’t like something in my svg. Going to debug that. Thanks for now folks!

Sebastian16:11:58

Question: How do I specify the clojurescript build id if I use :hook? I have 3 different clojurescript build maps and I'd like to specify which one to use when building the uberjar

borkdude16:11:49

Gotcha, I needed to add xmlns=" which d3 doesn’t do

scknkkrer17:11:59

Hi guys, I am writing a small library. How can I deploy for others usage ?

scknkkrer17:11:26

@darwin any detailed document for idiots ?

darwin17:11:08

@scknkkrer not easy to answer, depends on which tools do you prefer to use

darwin17:11:30

lein? boot? maven?

darwin17:11:57

or you could even use a zip and go low-level 🙂

scknkkrer17:11:32

I am sorry, what ?

darwin17:11:00

nevermind, consult your favourite tool's documentation: https://github.com/technomancy/leiningen/blob/stable/doc/DEPLOY.md

darwin17:11:22

not an easy read in case of lein

scknkkrer17:11:17

@darwin, Should I encrypt deployment with gpg ?

darwin17:11:40

not encrypt, you should sign it

scknkkrer17:11:44

Thanks for the link, BTW. It really helped me.

scknkkrer17:11:40

Generating an key with gpg and write it down in project.clj as :signing value. Right ?

darwin17:11:57

@scknkkrer I personally put this into ~/.lein/profiles.clj because it is used for all my libs

darwin17:11:17

this will ensure correct specific gpg key is used and maybe some library metadata is properly set, but I'm no clojars expert, this has been working for me

darwin17:11:28

you should inspect generated jar file to be deployed (which is just a zip file with some well-defined structure), inspect xml files there and make sure they look ok, especially make sure you did not include there some garbage

scknkkrer18:11:34

Is there any template eleminate all those problems ? I just want to create basic --really basic-- library for clojurescript.

darwin18:11:59

then distribute it in source form, and instruct library users just copy sources into their src folders (or symlink them / whatever)

darwin18:11:14

git submodules could work for this as well

thheller18:11:00

(defproject your-group/the-thing "0.0.1"
  :description "FIXME"
  :url "FIXME"
  :license {:name "Eclipse Public License"
            :url ""}

  :dependencies
  [[org.clojure/clojurescript "1.9.946" :scope "provided"]])

thheller18:11:12

put sources in src, lein deploy clojars

scknkkrer18:11:32

Ok. Thanks @darwin. I am digging down a little bit. If I can’t. I will do as you said.

scknkkrer18:11:43

I will dig about leiningen project structure a little bit. I think I am not good enough.

scknkkrer18:11:49

Thanks for your helps.

scknkkrer18:11:24

I know this is weird, but I generate a key for me and set this. When I deploy; gpg: signing failed: Inappropriate ioctl for device. Error returned twice.

noisesmith18:11:36

that might mean you have the CLI version of gpg installed and are using leiningen

noisesmith18:11:29

a workaround is to use the same gpg key for something else so it is in fresh cache, a fix is to use a GUI gpg, or fix lein to share stdio with gpg when shelling out

scknkkrer18:11:20

I think the problem is my name. Contains non-ascii character. The GUI of gpg solved the problem well. Thanks again @darwin.

noisesmith18:11:01

it’s not your name, it’s the fact that lein can’t let gpg prompt for user input like passwords

joelsanchez19:11:17

hi, I'm using transit-cljs for providing bigdecimals in cljs. I need to turn those bigdecs into strings and back, but I'm having problems transforming a bigdec into a string as per http://increasinglyfunctional.com/2015/11/12/transit-clojurescript-big-decimal/ I wrote this: (cljs.reader/read-string (.-rep my-bigdec)) but it looks slightly ugly, anyone knows a better way?

noisesmith19:11:13

@joelsanchez wait - you are asking read-string to consume a float and you want that to return a string? I’m confused

joelsanchez19:11:33

read-string consumes a string

joelsanchez19:11:39

the .-rep value is a string

noisesmith19:11:43

but you said you wanted to create a string

joelsanchez19:11:32

ah sorry...yes, .-rep is enough

joelsanchez19:11:57

it just looks sort of internal, but yes, I can just use it

joelsanchez19:11:34

it's a pity they didn't implement the str fn

noisesmith19:11:51

anyway, read-string is a big tool for such a specific task - you can also use (js/Number. (.-rep my-bigdec)), or something more like (-> my-bigdec (.-rep) (js/Number.))

joelsanchez19:11:23

👍 I'll go with that, and I'll hide the .-rep uglyness and forget that it exists 😛 thanks

ajs19:11:29

@mfikes helpful blog post, thanks

bbrinck20:11:57

I’m trying to use the fetch API https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API within CLJS. It uses Headers (https://developer.mozilla.org/en-US/docs/Web/API/Headers) which in turn returns iterators. Is there a simple way to treat iterators as seqs in CLJS?

bbrinck20:11:52

I can always write some custom code using .done and .next, but perhaps there is some way I’m missing?

thheller20:11:20

nvm missed the obsolete part

scknkkrer20:11:24

I am writing a small library for fetch api and I really wonder about this too.

thheller20:11:03

es6-iterator-seq?

bbrinck20:11:39

@thheller That’s perfect, thanks!

wpcarro21:11:21

I’m looking for the path to where a cljsjs or any project.clj dependency is installed. Can anyone help me?

thheller21:11:11

~/.m2/repository/...