Fork me on GitHub
#clojurescript
<
2018-02-23
>
benzap05:02:03

I'm having a hard time wrapping my head around how to implement SPI routes using something like secretary. I have compojure suck up all urls from /app/* and get sent to the same handler, which is a page containing my react rendered app. For my client-side route handler, i'm using secretary, and I have two test routes "/app" and "app/home". So I load my webpage at "/app", and i'm in a situation where i'm switching to another url within the app ie. "/app/" --> "/app/home", how do I go about doing this without triggering a webpage navigation and page load? Setting window.location.pathname = "/app/home" results in the page reloading, and i've noticed that sites like twitter and facebook get away with changing the url without causing the page to reload. What am I missing here?

Wilson Velez14:02:12

@U0670BDCH If you are doing this manually i think should use the hash character (#) in your URL, that indicates that the resources you are looking for is relative to the current page

benzap14:02:33

Ya, I did some more research, and came to the conclusion that it is limited to the hash method, and so far it's been fitting my needs

grounded_sage08:02:37

Is there a good library for doing headless browser testing with CLJS?

nenadalm18:02:20

Hi. I am not aware of any cljs library, but here's good clj library: https://github.com/igrishaev/etaoin.

grounded_sage11:02:32

It seems the best thing is doing Lumo with Puppeteer

bbss12:02:36

I'm trying to build a clojurescript chrome extension using @darwin's wonderful chromex extension but I'm hitting a problem with loading cljsjs dependencies. I expect this is because the foreign library file can not get required properly because of content-script using a different api to load scripts. But I'm not sure how to debug further 😔. Chrome extensions aren't exactly the most informative when things go wrong.

darwin12:02:24

@bbss content-script must be a single file, I think you should use :whitespacecompilation mode for development of content scripts

bbss12:02:00

I am using a single file approach but didn't check whitespace, I did see that in the example project, let me try.

bbss12:02:07

Thanks for responding 🙂

darwin12:02:04

I’m not exactly aware how cljsjs is adding its “foreign” libraries, I was under impression they use :foreign-libsand those should get concatenated with compiled js file in :advanced mode, not sure how this works under other modes

bbss12:02:30

Ah, that doesn't seem to work with figwheel, which requires :optimizations to be none or nil.

darwin12:02:04

yes, under normal cimrcumstances you cannot have figwheel for content-scripts

bbss12:02:12

I know the example doesn't recommend to reload the content script, but I need to do quite a bit of dom manipulation so could really use figwheel. It works so far, just the cljsjs libraries.

darwin12:02:15

some people had workarounds

darwin12:02:24

but that requires quite some effort

bbss12:02:41

I've followed a medium post and done it before (maybe a year or two ago).

bbss12:02:51

It can work (although it felt really hacky).

darwin12:02:50

I don’t have a good solution, I didn’t need to build heavy content scripts myself

bbss12:02:42

I've tried to manually require the script from the cdn, and had to add the url to the content_security_policy for the request to succeed. And even required the react file manually, it ran (I checked with console.log). But somehow React doesn't get put in the scope.

darwin12:02:28

are you aware of “isolated worlds” concept of content scripts?

bbss12:02:09

Yes, I've read about it. All the rest of the clojurescript gets put on the window though, it's really just the cljsjs external deps.

bbss12:02:08

goog.dependencies_.nameToPath.react
"../cljsjs/react/development/react.inc.js"
They are there, and they're requested too. Just no effect..

darwin12:02:50

I’m sorry I have no ideas, this is really tricky part of extension development

darwin12:02:55

you will have to dig deeper maybe using chrome devtools

bbss12:02:13

Anyway I'll try to figure something out. Yea, using the devtools a lot.

darwin12:02:52

both execution contexts should be accessible in the devtools (page’s and your content-script’s)

darwin12:02:13

you should be able to switch them via that “iframe context” combo box

bbss12:02:17

Thanks again, your libs and devtools plugin are great ❤️

bbss12:02:30

Ah, okay I'll look into it.

erwinrooijakkers12:02:01

How do I turn a vector into a JavaScript object (on which forEach works)? And how do I turn a map into a JavaScript object (on which forEach works)? I tried (goog.array/toArray [1 2 3]) but it returns #js [].

rauh12:02:13

@erwinrooijakkers to-array or into-array

erwinrooijakkers12:02:03

Thanks I will check

erwinrooijakkers12:02:28

Also in the ClojureScript cheatsheet http://cljs.info/cheatsheet/

erwinrooijakkers13:02:09

It seems like a map does implement forEach

erwinrooijakkers13:02:37

But in a different way than a JavaScript object. JavaScript object has the signature: obj.forEach(fn [entry index]) And ClojureScript map has: m.forEach(fn [key val])

erwinrooijakkers13:02:35

Well turned out I need to pass a vector of vectors, than it worked out of the box, without conversions to JavaScript

bbss12:02:25

Have you tried clj->js?

rauh12:02:36

FWIW, Vector should probably implement forEach like other CLJS data structures. Feel free to file a ticket.

erwinrooijakkers12:02:42

I tried clj->js but that gives:

#object[TypeError TypeError: xxxx.forEach is not a function

darwin13:02:27

ad 2) maybe someone called Object.freeze() on the js-props object?

darwin13:02:49

I would assume react defensively protects its stuff from people

darwin13:02:42

I don’t know, I have never used freeze myself

bbss13:02:12

@erwinrooijakkers on vectors that should work, forEach is not on JavaScript objects it looks like? You can however iterate objects key-value in JS with iterators in new EcmaScript. It's ugly though.

erwinrooijakkers13:02:30

Hmm what I try to do is convert a vector of maps to a JavaScript object that is accepted by: https://github.com/iotaledger/iota.lib.js/blob/6d9ae54fccc168d9ed757b06e5ea3d284715034c/lib/utils/utils.js#L301

erwinrooijakkers13:02:11

So I have transfers: (def transfers [{:address "1}]) and this needs to be passed to:

transfers.forEach(function(bundle) {

bundle.forEach(function(bundleEntry, bundleIndex) {

bbss13:02:42

it looks like they expect (def transfers [[{:address "1"}]])

bbss13:02:39

Werkte dat? 😄

bbss13:02:49

:thumbsup:

erwinrooijakkers13:02:53

Het staat zelfs in de docstring

erwinrooijakkers13:02:56

transfers: coll A coll of bundles. Basically is an array, of arrays (bundles),
                  as is returned from `get-transfers` or `get-account-data`

bbss13:02:07

Makkelijk over het hoofd te zien 🙂

erwinrooijakkers13:02:27

Ja ik zat op het verkeerde spoor

erwinrooijakkers13:02:33

Nu werkt het gewoon zonder #js ofzo

erwinrooijakkers13:02:46

Twee uur op het verkeerde spoor

erwinrooijakkers13:02:32

Nederlander? 😉

bbss13:02:35

Ik ken het. Vast zitten en uiteindelijk in zo'n klein dingetje de oplossing vinden.

bbss13:02:48

Yeh, woon in Korea nu though.

bbss13:02:30

Veel succes met de crypto!

erwinrooijakkers13:02:29

Aha 🙂 Waarom Korea als ik vragen mag en hoe is het daar? Thx

bbss13:02:19

Stage voor afstuderen in Shanghai, daarna daar blijven werken, Zuid Koreaanse vriendin ontmoet en daar nu naar verhuisd. Het is een erg fijn land en fijn volk. Momenteel met m'n vriendin vrouwen curling aan het kijken Japan vs Zuid Korea, rivalry tussen Korea en Japan is sterk dus intens, hahah. Op TV helaas, niet naar PyeongChang zelf gegaan.

erwinrooijakkers13:02:01

Ha mooi verhaal. Veel plezier 🙂

darwin13:02:09

I should probably add this check into dev-time validations in cljs-oops

donmullen13:02:29

indeed - that would be helpful.

donmullen13:02:09

@darwin - there is also Object.isSealed() and Object.seal()

darwin13:02:06

ah ok, thanks

donmullen13:02:05

@darwin - turns out the js-props object was both sealed and frozen - seemed strange at first that it is both - but evidently by definition a frozen object is sealed.

koala punch16:02:06

hi, i’m having trouble getting nvim-parinfer working

koala punch16:02:19

which plugin do people use for parinfer like behaviour?

koala punch16:02:36

basically looking for osmething that will append closing brackets for me

Jacob Haag21:02:50

Has anyone gotten this message when using re-frisk "java.lang.IllegalArgumentException: <filepath>\react.inc.js is not a relative path"?

shaun-mahood21:02:09

I haven't, but you're more likely to find someone else who has in #re-frame (assuming it's a re-frisk specific problem)

scaturr21:02:33

Is it bad form to use extend-protocol in library code? I feel like I remember some conversation about a performance hit

joelv22:02:02

what's a good way to install bootstrap or other libs into cljs project. I'm using leiningen.

joelv22:02:32

nevermind I just had to read the docs 😀