This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-14
Channels
- # beginners (53)
- # boot (93)
- # cider (13)
- # cljs-dev (17)
- # cljsrn (20)
- # clojars (1)
- # clojure (349)
- # clojure-austin (1)
- # clojure-gamedev (5)
- # clojure-italy (1)
- # clojure-nl (16)
- # clojure-poland (1)
- # clojure-russia (26)
- # clojure-spec (57)
- # clojure-uk (6)
- # clojurebridge (5)
- # clojurescript (145)
- # code-reviews (2)
- # core-async (88)
- # cursive (1)
- # datomic (3)
- # defnpodcast (10)
- # events (7)
- # hoplon (20)
- # instaparse (1)
- # jobs-discuss (15)
- # keechma (26)
- # lein-figwheel (2)
- # leiningen (1)
- # liberator (11)
- # lumo (40)
- # off-topic (54)
- # om (32)
- # onyx (11)
- # pedestal (6)
- # perun (4)
- # planck (6)
- # re-frame (4)
- # reagent (12)
- # ring (3)
- # ring-swagger (10)
- # rum (1)
- # testing (4)
- # timbre (1)
- # unrepl (20)
- # untangled (111)
- # vim (1)
@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.
granted, I think you're right that certain things might get clobbered here and there. Need to explore.
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.
it would help if there was actual code one could look at ... I have no idea what your goal is still.
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.
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.
I'd actually like to discuss some of the architectual questinos with some folks, but I don't to clutter up the slack
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.
true shared memory between workers is coming as well https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
@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.
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.
@mikeb you might want to ask your questions in the #reagent channel, or perhaps #re-frame
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.
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?
In a re-frame app ALL application state is held in app-db
. We actively resist "distributing state" around the components.
If you have an OO mindset, which encourages partitioning, this can seem very wrong
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.
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?
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.
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
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.
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)?
It's a bit infuriating when I know exactly the regex I want to get generated (and yes, I tried using (js* ...)
)
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]*)?\)?")
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
if you can get the regex to execute in JS then you should be able to just do a (js/RegExp. "regex-here")
If you use string, you need to escape \ and such
Use regex literal instead #"..."
, no escaping needed
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]*)?\)?/
yea @juhoteperi is right
@danvingo @juhoteperi sadly no. The thing generated is not even a valid js regex
(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. ].")
verified in klipse: http://app.klipse.tech/
@danvingo can you try that in a non self hosted cljs repl? I really need to check my sanity 😞
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.
I'm getting Uncaught SyntaxError: Invalid regular expression flags
@juhoteperi yes exactly!
@juhoteperi if you look at the generated js regex, you will see there is a closing /
that appears in the middle
this might be related to /
needing escaping in JS regex literal but not in Cljs
(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)
Yeah, /
is escaped in JS literal format because that uses /
for start and end, but Cljs doesn't
Not sure if this is bug or not
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]*)?\)?
@juhoteperi note that in JS you do not always need to escape a /
character in a regex (for example, /[/ab]/
will work)
Cljs escapes /
even if they are already escaped
https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/compiler.cljc#L249
allright this is way out of my league, I'll try to use my nasty js regex as a foreign lib
perhaps just a single escape : (.replaceAll (re-matcher #"/" pattern) "\\/")
to deal with the java pattern
ClojureScript fully supports Google Closure JS namespaces that follow classpath conventions for some time now
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
(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].")
I ran into the double backquote problem recently trying to round trip some structures between pr-str
and read-string
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
@danvingo that's amazing! I tried it against a more meaty string "plop
and every matching group seems to be doing its job perfectly. Many thanks!
sweeet! no prob - i wasn't aware of that escaping behaviour before - learned something new 🙂
@kommen hard to tell without actual code. that snippet looks ok although I can't tell its purpose
anyone know if namespaces support "wrapping" other required namespaces - something like export * from …;
in js
@thheller thanks, I will write up a more thorough description with hopefully an example to compile
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.
ah looks like there's a lead here: https://gist.github.com/danjohansson/add5515b2067b3036044d450cbec08f3
anyone know why I always get these warnings? code still seems to work but shouldn't the clojure.string namespace be native?
@kanwei well did you require
clojure.string
?
well, in clojure, the require isn't necessary, and the warnings only seem to be showing the first time (recompiling gives no errors)
does anyone have a good clojurescript pretty printer that will print html or ideally hiccup?
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
@andrewboltachev It seems to be pulling the library from http://unpkg.com https://github.com/cljsjs/packages/blob/master/react/build.boot#L58-L61
gotcha! thanks a lot @rgdelato
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
@rgdelato thanks for info, and I'm rather looking now how to install this thing via NPM
(having bare JS file I can include it anyway, but it's not quite exciting)
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
yep, seems much like that, especially 'cause of deprecation
Now I realize: "Version changes and you're screwed" as Rich Hickey has said 😄
> "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
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?
react and react-dom should be fine I think in many cases
@hagmonk btw also a little aside here: do you plan to use JS React components from NPM in your project?
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!
did it ask for cljsjs.react
and cljsjs.react-dom
?
aha, well just feel free to add these there
@hagmonk are you using Reagent, Rum, or Om.Next btw?
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
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
yes, the template it's most wanted thing there I'd say
clojure.lang.ExceptionInfo: Cannot build without root node being specified data: {:from :boot-cljs}
root node... may be you may check boot cljs's docs?
yeah, that's where I'm off to now. All the github repos using npm-deps are building with leiningen, it seems
make sure you have all leiningen plugins in place as well
'cause might be that you need lein-npm
or sth
seems it could be an ES6 / Closure incompatibility: https://clojurians-log.clojureverse.org/cljs-dev/2017-02-17.html
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?
@hagmonk cljsjs versions of which libraries do you mean?
I think cljsjs itself isn't farsighted solution. You'll anyway reach the limit and need some library from NPM
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
etcthat's what I'm using
@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