Fork me on GitHub
#clojurescript
<
2017-07-05
>
wistb00:07:18

Hi, I want our UI team to look at ClojureScript. In the interest of time, I am looking for someone who can walk the team through the clojurescript eco system and answer their questions. Currently they are using Ext-js. I want someone who can demonstrate how clojureScript can help where other javaScript approaches may fall-short. I am looking at 4-6 hours of engagement. The team is in India, so, the meetings will be over zoom. I will pay. If anyone is a practicing UI expert with active usage of ClojureScript and (if can give ideas why ClojureScript is better compared to Angular .. or for that matter if Angular or something else is better explain why ). If anyone interested and fits the requirement, please let me know. thanks

ioneyed01:07:42

@wistb I do not fulfill your requirements as I have never used clojurescript (been trying to find a project that isn't pressing to try it on) but clojurescript compiles to JS so you can use any of the frameworks that are available (unless I am oblivious to an underlying issue with clojurescript and this statement) for example here is a post on using clojurescript with AngularJS 2 - http://deliberate-software.com/cljs-angular2/

mikerod02:07:29

@grav thanks. Yeah that sounds sort of like what I was thinking. Seems like server side may be safest still. Hah

didiercrunch02:07:34

@rnagpal if you are still around. reagent lein plugin is amazing! To create a new project, just use lein new reagent myproject +spec +sass. Then you will need two separe terminals, one with lein run to run the server the other will run lein figwheel and run figwheel. Both command will need to be run from the myproject directory. The server will run at http://localhost:3000 by default

minikomi04:07:56

@anmonteiro I had just that problem a few months ago.. nice one

pesterhazy10:07:35

note, it's often better to use #js (repeated inside nested collections) instead of clj->js

dsapoetra11:07:42

thank you @vbedegi , uhm, can you elaborate more @pesterhazy? I’m new to this

pesterhazy11:07:54

clj->js is a function that transforms a datastructure at runtime

pesterhazy11:07:39

#js {"a" "b"} is short for (js-obj "a" "b") and #js [1 2 3] is short for (array 1 2 3)

pesterhazy11:07:13

or maybe that's not quite accurate

pesterhazy11:07:15

#js {"a" "b"} transpiles directly to {"a": "b"}, so there's no runtime cost

pesterhazy11:07:02

this also means you have to use repeat #js when nesting data structures, e.g. #js {:foo #js [1 2 3]}

mfikes14:07:02

You can even mix a little compile time and runtime, as in

(defn f [x] 
  #js {:a (inc x)})

fabrao14:07:37

Hello all, anyone with the same problem using :npm-deps? java.io.IOException: Cannot run program "npm": CreateProcess error=2

fabrao14:07:48

on Windows

dnolen14:07:50

@fabrao did you install Node.js?

fabrao14:07:19

Yes, it´s running from Command Prompt

fabrao14:07:36

I did a lein cljsbuild once the result is

Compiling ClojureScript...
Compiling "resources/public/js/compiled/sta.js" from ["src"]...
Compiling "resources/public/js/compiled/sta.js" failed.
java.io.IOException: Cannot run program "npm": CreateProcess error=2, O sistema nÒo pode encontrar o arquivo especificado

fabrao14:07:20

and the smae prompt

npm version
{ sta: '1.0.0',
  npm: '3.10.9',
  ares: '1.10.1-DEV',
  http_parser: '2.7.0',
  icu: '57.1',
  modules: '48',
  node: '6.9.2',
  openssl: '1.0.2j',
  uv: '1.9.1',
  v8: '5.1.281.88',
  zlib: '1.2.8' }

fabrao14:07:01

I checked the PATH and the nodejs is there too

dnolen14:07:21

hrm … probably something wrong w/ how we try to execute npm under Windows

anmonteiro15:07:22

I might know what's wrong. I'll work on a patch in the next hour

fabrao15:07:31

Oh, thanks

fabrao16:07:11

What´s is the difference from this method :npm-deps from using lein-npm and after using <script src='dependency'>

dnolen16:07:50

@fabrao very different - everything goes through Google Closure with :npm-deps

dnolen16:07:26

if you’re doing Node.js stuff (not web stuff) you don’t really need :npm-deps

fabrao16:07:18

I´m doing web stuffs, that´s because it´s important, but I´m having problems with using lein-npm and after including it with script, It seems always breaks dependency

fabrao16:07:55

or it will not work with clojurescript

fabrao16:07:50

like here https://anmonteiro.com/2017/03/requiring-node-js-modules-from-clojurescript-namespaces/ , I did

:npm {:dependencies [[left-pad "1.1.3"]]
        :root "resources/public/js"}
in project.clj ran lein npm install, and use <script type="text/javascript" src="js/node_modules/left-pad/index.js"></script> I run figwheel and it´s getting
index.js:7 Uncaught ReferenceError: module is not defined
    at index.js:7
in browser console

fabrao16:07:55

Can I use left-pad direct in script load?

dnolen16:07:04

@fabrao that’s what I was saying lein npm just grabs your deps - it doesn’t help you with your build

dnolen16:07:21

either you need to build a foreign dep separately with Webpack or you can try :npm-deps

fabrao16:07:37

oh, I got it

fabrao16:07:41

Is it a bug when I changed the clojuscript 1.9.660 to 1.9.671 is getting this WARNING: Use of undeclared Var cljs.js/lib at line 450 resources\public\js\compiled\out\cljs\js.cljs?

mfikes16:07:04

That's a known issue…

fabrao16:07:43

Is there any place to see this kind of issue before asking here?

mfikes16:07:12

It is innocuous for most self-hosted capabilities, FWIW

mfikes16:07:06

This particular issue is CLJS-2141

fabrao16:07:29

Many thanks for your information

anmonteiro16:07:04

another thing to make sure is that you have a package.json in your project’s directory

fabrao16:07:57

Thanks @anmonteiro , so, I have to wait other clojurescript version to use it? Sorry my question, I´m newbe in some things

anmonteiro16:07:53

@fabrao I’d prefer you try the patch once David applies it, following these instructions: https://clojurescript.org/community/building

anmonteiro16:07:59

to make sure everything works before the release

dnolen17:07:05

@anmonteiro @fabrao patch applied to master

fabrao17:07:12

@anmonteiro other newbe question 🙂 , is that possible to build it on Windows? Or only linux and mac? I only see sh script

anmonteiro17:07:30

good point, I don’t know

anmonteiro17:07:37

I don’t have access to a Windows machine

fabrao17:07:45

I did some lein uberjar and worked

anmonteiro17:07:14

@fabrao let me know if :npm-deps works now

fabrao17:07:47

I´ll replace clojurescript old jar and let you know

fabrao17:07:51

Compiling "resources/public/js/compiled/sta.js" from ["src"]...
Installing Node.js dependencies
events.js:160
      throw er; // Unhandled 'error' event
      ^

fabrao17:07:13

the npm call worked

fabrao17:07:21

not the rest

anmonteiro17:07:21

hey at least it’s calling NPM now

anmonteiro17:07:04

@fabrao do you have a package.json in your project’s directory?

fabrao17:07:43

I created it with npm init

fabrao17:07:57

Do I have to include the lib there

fabrao17:07:35

in dependencies?

anmonteiro17:07:42

you shouldn’t need to

fabrao17:07:21

so, this error is something else?

anmonteiro17:07:28

what Node.js version are you running?

fabrao17:07:48

look at this `Error: Cannot find module 'c:\Trabalho\Cliente\FDABRAO ME\Projetos\Clojure\sta\TrabalhoClienteFDABRAO MEProjetosClojuresta esourcespublicjscompiledoutcljs$node_modules.js' from 'c:\Trabalho\Cliente\FDABRAO ME\Projetos\Clojure\sta'`

fabrao17:07:13

maybe it´s messing with \ separator

fabrao17:07:57

@anmonteiro Your environment has been set up for using Node.js 6.9.2 (x64) and npm.

fabrao17:07:34

so, the problem is not in Node.js but in backslashes ?

wistb17:07:58

looking for a UI/clojureScript practicing professional to help our team with 'demo, QA' over 4-6 hours (one hour at a time) of 'online zoom sessions'. Will Pay. If anyone interested , please let me know.

dnolen17:07:56

@wistb cool! Also reach on the ClojureScript mailing list

eistre17:07:32

The new clojure spec in clojure 1.9 throws compile errors now on some old forms of silent invalid syntax. Is there a way to get the same sorts of spec exceptions on ClojureScript code as well?

dnolen18:07:41

@eistre we could copy that stuff, the main reason we haven’t done it directly is to not have a hard dep on 1.9

fabrao18:07:23

@anmonteiro

Installing Node.js dependencies
Failed to compile "resources/public/js/compiled/sta.js" in 3.97 seconds.
----  Exception    ----

  JSON error (end-of-file)

----  Exception Stack Trace  ----

java.io.EOFException: JSON error (end-of-file)

erwinrooijakkers18:07:01

I added a question to Stack Exchange Code Review. I want to see how I can clean up my “essay” that retrieves two files asynchronously: https://codereview.stackexchange.com/questions/167414/retrieve-compilation-files-of-smart-contracts-asynchroniously-via-ajax-and-add-t

erwinrooijakkers18:07:03

I would appreciate if someone can take a look and tell me how to improve.

anmonteiro19:07:14

@fabrao is that with just left-pad?

fabrao19:07:57

well, I´m testing the integration, and I saw your blog post

anmonteiro19:07:43

I’d encourage you try the simplest project first

anmonteiro19:07:46

with a build from master

anmonteiro19:07:53

and report back

anmonteiro19:07:59

then we can go from there

fabrao19:07:42

ok, I´ll go for it, thanks

fabrao19:07:05

@anmonteiro I did lein new reagent-frontend npm-test changed the project to include :npm-deps {:left-pad "1.1.3"} , go to cmd and run lein figwheel The error is the same

Figwheel: Cleaning build - app
Compiling "public/js/app.js" from ["src" "env/dev/cljs"]...
Failed to compile "public/js/app.js" in 4.431 seconds.
----  Exception    ----

  JSON error (end-of-file)

----  Exception Stack Trace  ----

java.io.EOFException: JSON error (end-of-file)
 at clojure.data.json$_read.invokeStatic (json.clj:182)

fabrao19:07:36

well, do you think the problem is with figwheel?

fabrao19:07:11

lein cljsbuild once goes ok

fabrao20:07:18

@anmonteiro it seems that your change affect the result, look that :

node --eval "var path = require('path');\r\nvar mdeps = require('module-deps');\r\nvar nodeResolve = require('resolve');\r\nvar browserResolve = require('browser-resolve');\r\n\r\nvar target = '';\r\nvar filename = path.resolve(__dirname, 'C:\\Trabalho\\Cliente\\FDABRAO ME\\Projetos\\Clojure\\bombom\\public\\js\\out\\cljs$node_modules.js');\r\nvar resolver = target === 'nodejs' ? nodeResolve : browserResolve;\r\n\r\nvar md = mdeps({\r\n  resolve: function(id, parent, cb) {\r\n    // set the basedir properly so we don't try to resolve requires in the Closure\r\n    // Compiler processed `node_modules` folder.\r\n    parent.basedir = parent.filename === filename ? __dirname: path.dirname(parent.filename);\r\n\r\n    resolver(id, parent, cb);\r\n  },\r\n  filter: function(id) {\r\n    return !nodeResolve.isCore(id);\r\n}});\r\n\r\nvar pkgJsons = [];\r\nvar deps_files = {};\r\n\r\nmd.on('package', function (pkg) {\r\n  // we don't want to include the package.json for users' projects\r\n  if (/node_modules/.test(pkg.__dirname)) {\r\n    var pkgJson = {\r\n      file: path.join(pkg.__dirname, 'package.json'),\r\n    };\r\n\r\n    if (pkg.name != null) {\r\n      pkgJson.provides = [ pkg.name ];\r\n    }\r\n\r\n    if (pkg.main != null) {\r\n      pkgJson.main = path.join(pkg.__dirname, pkg.main);\r\n    }\r\n\r\n    pkgJsons.push(pkgJson);\r\n  }\r\n});\r\n\r\nmd.on('file', function(file) {\r\n  deps_files[file] = { file: file };\r\n});\r\n\r\nmd.on('end', function() {\r\n  for (var i = 0; i < pkgJsons.length; i++) {\r\n    var pkgJson = pkgJsons[i];\r\n\r\n    if (deps_files[pkgJson.main] != null && pkgJson.provides != null) {\r\n      deps_files[pkgJson.main].provides = pkgJson.provides;\r\n    }\r\n\r\n    deps_files[pkgJson.file] = { file: pkgJson.file };\r\n  }\r\n\r\n  var values = [];\r\n  for (var key in deps_files) {\r\n    var dep = deps_files[key];\r\n\r\n    if (dep.provides == null && !/node_modules\\/[^/]*?\\/package.json$/.test(dep.file)) {\r\n      var match = dep.file.match(/node_modules\\/(.*)\\.js(on)*$/)\r\n\r\n      if (match != null){\r\n        dep.provides = [ match[1] ];\r\n      }\r\n    }\r\n\r\n    values.push(dep);\r\n  }\r\n\r\n  process.stdout.write(JSON.stringify(values));\r\n});\r\n\r\nmd.end({\r\n  file: filename,\r\n});\r\n\r\nmd.resume();\r\n"
from
(cond->> ["node" "--eval" code]
                      util/windows? (into ["cmd" "/c"]))
I did the change to see the result
(println (str "JSON => " iw))
         (next (json/read-str (str iw)))
JSON => (empty)

anmonteiro21:07:43

@fabrao what if you execute that snippet in the command line?

anmonteiro21:07:47

does it output anything?

anmonteiro21:07:08

the node --eval thing

fabrao21:07:05

@anmonteiro it seems that there is limit for command length

anmonteiro21:07:33

that’s unfortunate

fabrao21:07:48

`SyntaxError: Unexpected end of input at createScript (vm.js:74:10) at Object.runInThisContext (vm.js:116:10) at Object.<anonymous> ([eval]-wrapper:6:22) at Module._compile (module.js:569:30) at evalScript (bootstrap_node.js:432:27) at startup (bootstrap_node.js:139:9) at bootstrap_node.js:575:3`

fabrao21:07:32

maybe it´s better run it from file

fabrao21:07:11

like node --eval code.js

fabrao21:07:48

@anmonteiro writting it to file and run it node code.js ->

if (dep.provides == null && !/node_modules\\/[^/]*?\\/package.json$/.test(dep.file)) {
                                                  ^

SyntaxError: Unexpected token ^

anmonteiro21:07:09

I think I just fixed that in master

fabrao21:07:00

@anmonteiro sorry bodering you, but it failed again

anmonteiro21:07:23

@fabrao no problem, I wanna make sure this works on windows

qqq23:07:34

Is there a flag somewhere that tells assoc / dissoc / update / any-op-that-updates-maps to strip the meta data ?