Fork me on GitHub
#clojurescript
<
2017-04-14
>
john00:04:24

I think I got it working...

john00:04:30

@thheller re: your comment early about advanced compilation. I managed to get the project to compile in advanced mode. After fiddling with it for a while, it seems to be working. I'm passing messages between workers. It just seems way, way faster. So I could be wrong. But I have plenty of (when (= "this-workers-name" (get-id)) ..., where computations are only supposed to take place in that workers context... All printing from workers appears to have broken, but I routed messages back to the ui thread, showing some computation done on the workers... I think it's working.

john00:04:55

granted, I think you're right that certain things might get clobbered here and there. Need to explore.

john00:04:25

It's just, like, 10 or 20 times faster.. So I'm not sure if it's actually not working or it's just way more performant with a smaller code base on workers.

thheller07:04:50

it would help if there was actual code one could look at ... I have no idea what your goal is still.

john10:04:59

working on it. I'm going to be asking for yours and others eyes on the code, once its ready. I'm still working through some architectural decisions that requires more testing.

john10:04:28

The goal is to be able to share compiled javascript code (and clojure data) across webworker instances, within the same browser, in advanced mode, so as to abstract over web worker's message passing interface and provide a generic threading service (asynchronous threads). And provide an Agents implementation on top of that.

john10:04:08

And long term explore the potential of STM on top of that.

john10:04:06

I'd actually like to discuss some of the architectual questinos with some folks, but I don't to clutter up the slack

john11:04:55

It is not a goal here to provide a self-hosted repl in a worker, though I did do that and it works, which is cool.

dvingo13:04:15

would be interesting if the other clojure references could be brought to the browser

john13:04:42

@thheller to further clarify: for any javascript code sent to the target that makes calls to other functions, those other functions must be present at compile time for the target environment. Because they all launch from the same file, they all have the same munged names.

mikeb00:04:53

What's the suggested way to pass url parameters to reagent components?

mikeb00:04:45

I found an answer http://stackoverflow.com/questions/38469327/what-is-correct-way-to-broadcast-secretary-url-parameters-to-reagent-component) and just wondering if it's still valid, i.e. putting the param into a db which the component can refer to. It seems counter intuitive to store in shared location rather than simply passing it directly to the component.

mikethompson02:04:15

@mikeb you might want to ask your questions in the #reagent channel, or perhaps #re-frame

mikethompson02:04:32

But in general, if you are using re-frame, then there's no problem putting the id into app-db. It is part of the application's state, afterall.

mikeb02:04:53

But is that the preferred way? Somehow it just doesn't feel right putting a parameter like that in a shared global var, rather than just passing it directly to the component. Do other cljs ui libs generally work the same way?

mikethompson02:04:59

In a re-frame app ALL application state is held in app-db. We actively resist "distributing state" around the components.

mikethompson02:04:51

If you have an OO mindset, which encourages partitioning, this can seem very wrong

ul05:04:52

Recently I started to think that FP and OOP are not opposed, because they are on different levels. This http://lionet.info/pdf/railsclub-echo-oop-vs-fp.pdf sketch that point of view quite clearly.

mikeb05:04:18

OO seems like a tangential analogy, though I can see what your thinking in terms of splitting state up. I was thinking more in terms of pure functions which depend only on parameters, not an external var existing in the environment, and why wouldn't you pass parameters to a component function to set it's initial state?

ul09:04:34

Probably what are you talking about is more about normalization & smart/dumb components. Like if route is shared by entire application, why not to normalize such piece of state by putting parsed route in the single place in app-db? OTOH, most of you components which rely on route have no need to know about the fact that those parameters come from special place for route parameters. Then they could be wrapped up with thin containers which knows that this bunch of props are taken from parsed route in app-db, and that they should be passed to pure function dumb presentational component.

mikethompson02:04:20

But that discomfort will pass, I assure you. You'll later be quite delighted by the simplicity it brings. https://github.com/Day8/re-frame/blob/master/docs/ApplicationState.md#the-benefits-of-data-in-the-one-place

ul05:04:52

Recently I started to think that FP and OOP are not opposed, because they are on different levels. This http://lionet.info/pdf/railsclub-echo-oop-vs-fp.pdf sketch that point of view quite clearly.

chpill12:04:50

Hello everyone, I'm trying to use a js regex into my clojurescript code (the regex in question: http://regexr.com/355hb). I tried to escape some characters, but I cannot for the life of me get the right regex in the generated javascript code. Is there a way I can use the raw js regex (wihtout adding it as a foreign lib if possible)?

chpill12:04:15

It's a bit infuriating when I know exactly the regex I want to get generated (and yes, I tried using (js* ...))

dvingo12:04:48

i don't think that is a valid js regexp:

dvingo12:04:53

new RegExp("\(?(?:(http|https|ftp):\/\/)?(?:((?:[^\W\s]|\.|-|[:]{1})+)@{1})?((?:www.)?(?:[^\W\s]|\.|-)+[\.][^\W\s]{2,4}|localhost(?=\/)|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?::(\d*))?([\/]?[^\s\?]*[\/]{1})*(?:\/?([^\s\n\?\[\]\{\}\#]*(?:(?=\.)){1}|[^\s\n\?\[\]\{\}\.\#]*)?([\.]{1}[^\s\?\#]*)?)?(?:\?{1}([^\s\n\#\[\]]*))?([\#][^\s\n]*)?\)?")

dvingo12:04:02

Uncaught SyntaxError: Invalid regular expression: /(?(?:(http|https|f....

dvingo12:04:38

oh, i see the tool is executing that in the browser so it must be - seems the problem is in copying it out of the tool

dvingo12:04:05

if you can get the regex to execute in JS then you should be able to just do a (js/RegExp. "regex-here")

juhoteperi12:04:33

If you use string, you need to escape \ and such

juhoteperi12:04:40

Use regex literal instead #"...", no escaping needed

chpill12:04:49

You are right, it does not work when you do a new RegExp(...)

chpill12:04:20

@danvingo but it works if you use the js literal regex syntax /.../

chpill12:04:37

like this /\(?(?:(http|https|ftp):\/\/)?(?:((?:[^\W\s]|\.|-|[:]{1})+)@{1})?((?:www.)?(?:[^\W\s]|\.|-)+[\.][^\W\s]{2,4}|localhost(?=\/)|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?::(\d*))?([\/]?[^\s\?]*[\/]{1})*(?:\/?([^\s\n\?\[\]\{\}\#]*(?:(?=\.)){1}|[^\s\n\?\[\]\{\}\.\#]*)?([\.]{1}[^\s\?\#]*)?)?(?:\?{1}([^\s\n\#\[\]]*))?([\#][^\s\n]*)?\)?/

dvingo12:04:27

did that work @chpill ?

dvingo12:04:38

replacing / / with #""

chpill12:04:59

@danvingo @juhoteperi sadly no. The thing generated is not even a valid js regex

dvingo12:04:49

(re-seq #"\(?(?:(http|https|ftp):\/\/)?(?:((?:[^\W\s]|\.|-|[:]{1})+)@{1})?((?:www.)?(?:[^\W\s]|\.|-)+[\.][^\W\s]{2,4}|localhost(?=\/)|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?::(\d*))?([\/]?[^\s\?]*[\/]{1})*(?:\/?([^\s\n\?\[\]\{\}\#]*(?:(?=\.)){1}|[^\s\n\?\[\]\{\}\.\#]*)?([\.]{1}[^\s\?\#]*)?)?(?:\?{1}([^\s\n\#\[\]]*))?([\#][^\s\n]*)?\)?" "URLs within text:
* Create Share Links to send your expressions to co-workers or link to them on Twitter or your blog [ex. ].")

dvingo12:04:52

that's working for me

qqq12:04:15

lol, I think this is evidnece someone needs ot invent a DSL that replaces regexes 🙂

chpill12:04:15

@danvingo can you try that in a non self hosted cljs repl? I really need to check my sanity 😞

claudiu12:04:51

crazy idea 🙂. But would be really nice to see a series on clojurescript on http://egghead.io. Maybe it would boost the adoption from javascript developers. Purescript & Elm seem to be there.

juhoteperi12:04:53

I'm getting Uncaught SyntaxError: Invalid regular expression flags

chpill12:04:08

@juhoteperi if you look at the generated js regex, you will see there is a closing / that appears in the middle

juhoteperi12:04:16

this might be related to / needing escaping in JS regex literal but not in Cljs

dvingo12:04:55

verified, also getting that error in Clojure cljs:

dvingo12:04:00

(re-seq #"\(?(?:(http|https|ftp):\/\/)?(?:((?:[^\W\s]|\.|-|[:]{1})+)@{1})?((?:www.)?(?:[^\W\s]|\.|-)+[\.][^\W\s]{2,4}|localhost(?=\/)|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?::(\d*))?([\/]?[^\s\?]*[\/]{1})*(?:\/?([^\s\n\?\[\]\{\}\#]*(?:(?=\.)){1}|[^\s\n\?\[\]\{\}\.\#]*)?([\.]{1}[^\s\?\#]*)?)?(?:\?{1}([^\s\n\#\[\]]*))?([\#][^\s\n]*)?\)?" "URLs within text:
* Create Share Links to send your expressions to co-workers or link to them on Twitter or your blog [ex. ].")
#object[SyntaxError SyntaxError: Invalid regular expression flags]
   figwheel$client$utils$eval_helper (jar:file:/Users/dvingo/.m2/repository/figwheel/figwheel/0.5.9/figwheel-0.5.9.jar!/figwheel/client/utils.cljs:69:5)

chpill12:04:15

So is it a bug in clojurescript itself?

juhoteperi12:04:18

Yeah, / is escaped in JS literal format because that uses / for start and end, but Cljs doesn't

juhoteperi12:04:36

Not sure if this is bug or not

dvingo12:04:10

output by cljs compiler:
/\(?(?:(http|https|ftp):\\/\\/)?(?:((?:[^\W\s]|\.|-|[:]{1})+)@{1})?((?:www.)?(?:[^\W\s]|\.|-)+[\.][^\W\s]{2,4}|localhost(?=\\/)|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?::(\d*))?([\\/]?[^\s\?]*[\\/]{1})*(?:\\/?([^\s\n\?\[\]\{\}\#]*(?:(?=\.)){1}|[^\s\n\?\[\]\{\}\.\#]*)?([\.]{1}[^\s\?\#]*)?)?(?:\?{1}([^\s\n\#\[\]]*))?([\#][^\s\n]*)?\)?/

JS regex:
\(?(?:(http|https|ftp):\/\/)?(?:((?:[^\W\s]|\.|-|[:]{1})+)@{1})?((?:www.)?(?:[^\W\s]|\.|-)+[\.][^\W\s]{2,4}|localhost(?=\/)|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?::(\d*))?([\/]?[^\s\?]*[\/]{1})*(?:\/?([^\s\n\?\[\]\{\}\#]*(?:(?=\.)){1}|[^\s\n\?\[\]\{\}\.\#]*)?([\.]{1}[^\s\?\#]*)?)?(?:\?{1}([^\s\n\#\[\]]*))?([\#][^\s\n]*)?\)?

dvingo12:04:28

looks like all \ are getting escaped again

chpill12:04:37

@juhoteperi note that in JS you do not always need to escape a / character in a regex (for example, /[/ab]/ will work)

juhoteperi12:04:41

Cljs escapes / even if they are already escaped

dvingo13:04:47

very curious

chpill13:04:49

allright this is way out of my league, I'll try to use my nasty js regex as a foreign lib

dvingo13:04:17

looks like you could just undo what the compiler is doing by removing all \\ with \

qqq13:04:26

or ... use a context free grammar 🙂

dvingo13:04:28

looks like it may be a bug

dvingo13:04:25

perhaps just a single escape : (.replaceAll (re-matcher #"/" pattern) "\\/") to deal with the java pattern

dnolen13:04:20

@chpill you don’t need foreign libs for this btw

dnolen13:04:44

ClojureScript fully supports Google Closure JS namespaces that follow classpath conventions for some time now

dnolen13:04:57

just add a JS file to your project, done

dvingo13:04:22

seems like the core of the issue is that in a JS regex literal you need to escape internal / but in CLJS you don't, so you can't just copy and paste all JS regex literals

chpill13:04:37

@dnolen thanks! But then, will I not get issues with advanced compilation?

dnolen13:04:45

goog.provide("my.utils"); my.utils.regex = ....;

dnolen13:04:53

and just require my.utils in your ClojureScript

dnolen13:04:23

@chpill Google Closure JS means no issues with advanced compilation

chpill13:04:55

Okay, i'll try to do it that way

dnolen13:04:59

and you don’t need any additional compiler config for this

dvingo13:04:30

@chpill got it to work by just not escaping any /

dvingo13:04:32

(re-seq #"\(?(?:(http|https|ftp)://)?(?:((?:[^\W\s]|\.|-|[:]{1})+)@{1})?((?:www.)?(?:[^\W\s]|\.|-)+[\.][^\W\s]{2,4}|localhost(?=/)|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?::(\d*))?([/]?[^\s\?][/]{1})(?:/?([^\s\n\?\[\]\{\}\#](?:(?=\.)){1}|[^\s\n\?\[\]\{\}\.\#])?([\.]{1}[^\s\?\#])?)?(?:\?{1}([^\s\n\#\[\]]))?([\#][^\s\n]*)?\)?" "URLs within text: * Create Share Links to send your expressions to co-workers or link to them on Twitter or your blog [ex. http://RegExr.com/?2rjl6].")

john13:04:55

I ran into the double backquote problem recently trying to round trip some structures between pr-str and read-string

kommen13:04:11

I’m having a problem with my build as soon as I enable the :static-fns true compiler option together with :optimizations :simple. Getting ReferenceError: self__ is not defined errors which is triggered by this code: https://github.com/reagent-project/reagent/blob/master/src/reagent/impl/util.cljs#L61-L70

kommen13:04:19

can this be a ClojureScript compiler bug?

chpill13:04:13

@danvingo that's amazing! I tried it against a more meaty string "plop plop" and every matching group seems to be doing its job perfectly. Many thanks!

dvingo13:04:20

sweeet! no prob - i wasn't aware of that escaping behaviour before - learned something new 🙂

thheller14:04:11

@kommen hard to tell without actual code. that snippet looks ok although I can't tell its purpose

dvingo15:04:35

anyone know if namespaces support "wrapping" other required namespaces - something like export * from …; in js

dvingo15:04:02

use case would be to provide one namespace that exposes implementation namespaces

dvingo15:04:16

cool, thanks

kommen16:04:51

@thheller thanks, I will write up a more thorough description with hopefully an example to compile

john17:04:00

is it possible to extract the last update to a persistent structure from its internal tree? I'd like to implement distributed objects efficiently by pushing out only the diff of the shared structure in persistent collections.

john17:04:10

or is there another way to efficiently get the diff using an add-watch?

kanwei17:04:13

anyone know why I always get these warnings? code still seems to work but shouldn't the clojure.string namespace be native?

kanwei17:04:17

WARNING: Use of undeclared Var clojure.string/replace at line 300 src-cljc/xxx.cljc

anmonteiro17:04:36

@kanwei well did you require clojure.string?

kanwei17:04:15

well, in clojure, the require isn't necessary, and the warnings only seem to be showing the first time (recompiling gives no errors)

jr17:04:20

clojure.string is not "native" but sometimes happens to be required by other code

owen17:04:18

does anyone have a good clojurescript pretty printer that will print html or ideally hiccup?

andrewboltachev21:04:37

Hello. Can anyone suggest where this package is coming from? https://clojars.org/cljsjs/react-with-addons Can't find it's source anywhere in https://github.com/cljsjs/packages

rgdelato21:04:05

Aside (just in case this is why you were asking): http://unpkg.com was having some issues yesterday, but it seems to be resolved today: https://twitter.com/unpkg/status/852655106562564098

andrewboltachev22:04:35

@rgdelato thanks for info, and I'm rather looking now how to install this thing via NPM

andrewboltachev22:04:08

(having bare JS file I can include it anyway, but it's not quite exciting)

rgdelato22:04:04

I think you might have to install react, react-dom, and whatever addons you're using separately: https://facebook.github.io/react/docs/addons.html

andrewboltachev22:04:39

yep, seems much like that, especially 'cause of deprecation

andrewboltachev22:04:19

Now I realize: "Version changes and you're screwed" as Rich Hickey has said 😄

rgdelato22:04:43

> "We're discontinuing active maintenance of React Addons packages. In truth, most of these packages haven't been actively maintained in a long time. They will continue to work indefinitely, but we recommend migrating away as soon as you can to prevent future breakages." > - https://facebook.github.io/react/blog/2017/04/07/react-v15.5.0.html#discontinuing-support-for-react-addons

hagmonk22:04:48

I was just about to ask whether :npm-deps is supposed to pull in transitive dependencies like react and react-dom … now I see one has to include those manually?

andrewboltachev22:04:39

react and react-dom should be fine I think in many cases

hagmonk22:04:21

I'm using {:antd "2.9.1"} and it barfed during build, wanting react and react-dom

andrewboltachev22:04:55

@hagmonk btw also a little aside here: do you plan to use JS React components from NPM in your project?

hagmonk22:04:57

I'm hoping so, I just started with a team that uses React and I've not done CLJS before, although I've done a ton of JVM Clojure … I figured now is a good time to try!

andrewboltachev22:04:29

did it ask for cljsjs.react and cljsjs.react-dom?

hagmonk22:04:30

I'm using boot-cljs, and the error it threw was during build of main.js

hagmonk22:04:52

And I'm just passing npm-opts through as a compiler option for the cljs task

andrewboltachev22:04:03

aha, well just feel free to add these there

andrewboltachev22:04:31

@hagmonk are you using Reagent, Rum, or Om.Next btw?

hagmonk22:04:56

I have another colleague who recommended Om.Next, so was going to start there

andrewboltachev22:04:12

aha so I'm not quite sure, but at least in case of reagent you'll need also (as long as you're installing react via NPM) to add empty react.cljs and dom.cljs files: http://blob.tomerweller.com/reagent-import-react-components-from-npm

hagmonk22:04:31

oh very interesting

hagmonk22:04:07

feels like an opportunity for a template to get people going - I'm surprised there aren't more of these, I thought that central to the appeal of using react would be pulling in all these component libraries

andrewboltachev22:04:04

yes, the template it's most wanted thing there I'd say

hagmonk22:04:23

hmm now I do hit an error

hagmonk22:04:51

clojure.lang.ExceptionInfo: Cannot build without root node being specified data: {:from :boot-cljs}

andrewboltachev22:04:27

root node... may be you may check boot cljs's docs?

hagmonk22:04:33

yeah, that's where I'm off to now. All the github repos using npm-deps are building with leiningen, it seems

andrewboltachev22:04:14

make sure you have all leiningen plugins in place as well

andrewboltachev22:04:31

'cause might be that you need lein-npm or sth

hagmonk22:04:06

humph, so what's the alternative? use the cljsjs versions? I recall you still have to npm install the libraries anyway to get the rest of the library resources?

andrewboltachev22:04:34

@hagmonk cljsjs versions of which libraries do you mean?

hagmonk22:04:46

antd in this case

andrewboltachev22:04:01

I think cljsjs itself isn't farsighted solution. You'll anyway reach the limit and need some library from NPM

andrewboltachev22:04:02

so, the solution: 1. Add to src/ (or src/cljs, what you have) files react.cljs and react/dom.cljs with only ns declarations to make your CLJS libraries happy (thinking that React actually exists) 2. Init NPM package and install via npm (or I might recommend via yarn) your required packages 3. Add Webpack (config file and entry file) and to entry file add:

window.React = require('react');
window.ReactDOM = require('react-dom');
window.antd = require('antd'); 
// and so on
4. Include webpack bundle into index.html via <script ...> tag before the CLJS compiled bundle 5. In your CLJS files refer to that libraries as js/antd etc

andrewboltachev22:04:52

that's what I'm using

hagmonk22:04:16

cool, that's very helpful!

andrewboltachev22:04:43

@hagmonk glad to help, especially if this would actually work for you also, this might be not advanced optimizations-fiendly, which you might not like, but IMO 1st comes the functionality, then perofrmance and so on

hagmonk22:04:57

I completely agree there