This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-05-13
Channels
- # admin-announcements (17)
- # aleph (1)
- # arachne (2)
- # boot (152)
- # braveandtrue (8)
- # cljs-dev (12)
- # cljsjs (3)
- # cljsrn (1)
- # clojure (105)
- # clojure-austin (1)
- # clojure-belgium (5)
- # clojure-berlin (1)
- # clojure-brasil (5)
- # clojure-canada (2)
- # clojure-dev (6)
- # clojure-gamedev (1)
- # clojure-greece (9)
- # clojure-russia (39)
- # clojure-uk (9)
- # clojurescript (106)
- # component (4)
- # cursive (1)
- # data-science (3)
- # datascript (1)
- # datomic (9)
- # emacs (6)
- # hoplon (92)
- # jobs (1)
- # ldnproclodo (2)
- # lein-figwheel (1)
- # off-topic (19)
- # om (47)
- # om-next (1)
- # onyx (10)
- # other-languages (1)
- # proton (1)
- # re-frame (5)
- # reagent (36)
- # rethinkdb (1)
- # ring (2)
- # rum (1)
- # yada (14)
Is there any way to have core.async
fetch things in paralell but still maintain the given order?
You can synchronize things by keeping a vector of recieving chans and park/process them in order
Hi, I have a problem with html encoding this text: encoded <script>alert(1);<script> is rendered fine by react https://jsfiddle.net/pufhzme5/ but not by reagent http://cljsfiddle.com/#gist=1d66d8b98e0d0f5c09b7c1d8eec5d97e
@danbunea: that’s because JSX processor modifies the code
the string literal
var n = "encoded <script>alert(1);<script>" ReactDOM.render( <Hello name={n} />, document.getElementById('container')
does not unescape, for example
in reagent it’s perfectly safe to do [:h1 "<script>alert(1);<script>”]
@jooeltavares: I load the escaped values from the database. They;re put there by someone else. So I want to see <script>alert(1);<script> on the screen, but somehow I still see <script>alert(1);<script>
then you should decode the html yourself, first.
it would be the same in plain react with JSX (see snippet above) - since the > conversion only happens in JSX literals
clojure.string/replace should work fine assuming the only things that are escaped are < and >
and &, obviously 🙂
in general, it’s a bad idea to put escaped values in your data store.
(-> input (string/replace #”>” “>”) (string/replace #”<” “<”) (string/replace #”&” “&”))
yes, I was hoping to avoid decoding myself all the values. And for the server, there's nothing I can do...
you might work with [:div {:dangerouslySetInnerHTML {:__html "<b>I am bold</b>"}}]
but as the name implies that’s dangerous
the question then becomes: how much do you trust that the encoded string is “correctly” encoded ?
dangerouslySetInnerHTML has a lot of downsides, mainly in the lifecycle of a component, so I'd avoid it
@pat @jr Am I missing something? I'm not just trying to synchronize things, I want them to be fetched in parallel but retain their order, like [this](https://github.com/caolan/async#paralleltasks-callback)
So the snippet I just posted definitely waits for the first request to finish before going to the second, and so on. So it's definitely not parallel.
The third request fetches it from the remote server, so it's substantially slower. But request 4 waits for the lag before even starting
I think you just want to create those channels, wait for them all to close, then process the results
@risto <!
definitely blocks, so that's not surprising. Edit: hmm, re-reading the docs, it "parks" if nothing is available.
Create a single channel for your responses, have have your GET
function put the result of each web request on that channel. Then use a go-loop
to chew thru the responses as they come in.
Anyone used the sente component in system? I'm trying to figure out how the sente-routes
are meant to be wired into the compojure handler.
I'm assuming this is not possible because of Javascript's single threaded nature, but is there a way to pause a function and return to it later, without the function being called needing to setup a setTimeout, or polling the time and scheduling itself later?
@taylor.sando: it is not possible, but it can be emulated, via core.async library, this library auto-magically rewrites your seemingly linear code into “setTimeouts” with callbacks
Can it return to the function after the timeout though? I know you can set a function for execution with a timeout, but will it return to where it was before?
you can write code which looks linear, keeps its context and lives in the same function, so I would answer “yes"
For example, running a datascript query that you don't want to hog the cpu that might get ran every X milliseconds until it is complete
@taylor.sando: if in browser, that sounds like a great webworker candidate
I'm just wondering what the limits are of serializing a large datascript database each time, or copying it to something like indexedDB, which I believe can be accessed by any web worker
@risto you can doseq <! Channels and it will park on each in order... Useful in alot of places
@pat That won't fetch the channels in parallel, that's what I was originally doing. @fasiha rightfully mentioned that <!
will block, and take!
isn't useful in this case bc it needs a callback. @darwin found a solution though ^^
You can make multiple request in order and then process them in order, but all parallelism is an illusion
The solution @darwin gave is definitely parallel, and sorts it in the order that it was executed
@pat: core.async is not a loop, and parallelism is doable with callbacks, core.async rewrites your linear code to callbacks and properly handles context saving/restoration using a state machine
You're just arguing semantics though. Non-blocking I guess would be a more accurate term.
you are right, but selected API functions can run in parallel behind the scenes, but you have to use callbacks with them
Well, in any case, @darwin found a non-blocking solution, so in a sequence of requests each request doesn't have to wait for the previous one to finish
@dnolen: FYI bruce hauman had a switch: ':websocket-host' which allows the browser to work with figwheel when the browser is not local. So now can REPL around any device that connects into the server! Yay Bruce!
has anyone seen
NoSuchMethodError: com.google.common.base.CharMatcher.javaUpperCase()Lcom/google/common/base/CharMatcher
when using :optimizations
in cljsbuild? happens for any setting except :none
mitchelkuijpers was having that error on May 11th in the #C06DT2YSY channel, said it might have been related to having the wrong/outdated version of guava somewhere?
I pasted com.google.common.base.CharMatcher.javaUpperCase()Lcom/google/common/base/CharMatcher
string in the search box in slack and that came up with a “jump” link if you’d like to review the conversation — I don’t know anything about it except I recognized that weird message
Yes you need to have guava 19 if i recall correctly. It has todo with the newest clojurescript
Maybe you have a conflict
And 18.0 probably wins
It is pulling it in
ok you're right. (i was looking at deps with 1.8.40
). excluding guava from datomic dep appears to work (hopefully datomic still works!).
It does for us 👍
@pataprogramming: Did you sort it out? In system
we have a Sente component where the compojure routes are already configured, so you don't have to. You just plug in them when composing the System map.
@danielsz: That was the bit I have been trying to figure out. I've got system.components.sente
added to the system map, and I've seen that sente-routes
is in there. This is probably pretty basic, but I then can't figure out how they should be composed with the other compojure handlers.
Just adding the component doesn't seem to activate the /chsk
endpoints.
It seems like there should be a dependency declared, but that's not in the usage examples.
@pataprogramming: Yes, the wiring is always the hardest part 🙂 I think I have an example to show you, let me check.
Oh , awesome. Thanks!
@pataprogramming: Here's something to start with. https://www.refheap.com/119049
@danielsz: Super useful! Thanks! I'll dive back in later today.
@pataprogramming: Here's a working example: https://github.com/danielsz/system-websockets
just got cider connect working too....so am in heavenly bliss for cljs development on mobile devices... if anyone wants tips for that let me know...
@danielsz: That looks like exactly what I need to get unstuck. Thanks! I'll let you know how it goes.
when you turn on :optimizations and the resulting file is nearly empty – that indicates cljsbuild/google closure doesn't know enough about your code and it's optimizing it all away?