Fork me on GitHub
#clojurescript
<
2016-03-09
>
hlolli10:03:09

Does this look like a valid cljsjs code using jquery. I get returned an object, but the html page Im trying to embed wont show up in the targeted div. (js/jQuery (fn [] (.load (js/jQuery "main-content") (js/jQuery "about_en.html"))))

thheller10:03:05

@hlolli: no that does look correct, let me check my jquery-fu

thheller10:03:09

(js/jQuery #(js/jQuery.load "#main-content" "about_en.html")) that should do it?

thheller10:03:48

(defn load-main-content [page-url]
  (-> (js/jQuery "#main-content")
      (.load page-url)))

(js/jQuery #(load-main-content "about_en.html"))

thheller10:03:54

less confusing this way 😛

hlolli10:03:18

ok 1 sec...

hlolli11:03:12

BINGO!!! Wow, I've been spending last 2 hours trying to find cleaver way to use handlebarish partials without using mustache and iframe.

thheller11:03:05

(js/jQuery (fn [] (.load (js/jQuery "#main-content") "about_en.html")))

hlolli11:03:15

If someone haas time, would be nice to include more examples of jquery and cljsjs or in general documentation. Thanks so much for this.

thheller11:03:24

this would be the correct way you tried I think

thheller11:03:57

first step should be to remove jQuery 😛

thheller11:03:11

there are better ways

hlolli11:03:22

I would have thougt so, I was trying to interop the javascript I already knew to write.

thheller11:03:30

although even less documented than jQuery

hlolli11:03:17

ok, but I was getting carried in google closure documentation, you know of any function that does the same as jquery load in google closure?

thheller11:03:42

(defn load-main-content [page-url]
  (let [container (js/document.getElementById "main-content")]
    (xhr/send page-url
      (fn [content]
        (set! (.-innerHTML container) content)
        ))))

(load-main-content "about_en.html")

thheller11:03:53

without jquery

thheller11:03:23

xhr is [goog.net.XhrIo :as xhr] in the ns

thheller11:03:03

didn't test is but pretty sure that is correct

thheller11:03:46

what is missing is the "onload" event handler since "onload" is sort of an anti pattern in closure

thheller11:03:05

or DocumentReady not onload

hlolli11:03:15

ok Im getting app.cljs:209 Uncaught TypeError: Cannot set property 'innerHTML' of null

thheller11:03:53

you probably have <div id="main-content></div> somewhere

thheller11:03:01

and the javascript is included BEFORE that

thheller11:03:05

since there is no onload handler

thheller11:03:11

it doesn't exist yet

hlolli11:03:27

yes, but it's in om react, but in a lifecycle of object render

thheller11:03:29

moving the javascript to just before the </body> tag would fix that

hlolli11:03:15

well, thanks for this, I think I could hack this, didnt think about xhr, forgot that Im not doing cross domain so it should run without problems.

nxqd11:03:28

hi guys how to cons a map to a vector of map ? I have tried cons and concat, but it doesn't work as expected

(def ttt
  [{:label "Total", :price 900}]
  )
(cons ttt {:a :b})
;; expected result
;; [{:label "Total", :price 900} {:a :b}]

thheller11:03:31

(update ttt 0 merge {:a :b})

nxqd11:03:02

@thheller: thanks ! that's hell of a trick there 😄

nxqd11:03:02

hmm, thanks for the trick. But it's not my case, I will update my post shortly

thheller11:03:34

then it is just conj

thheller11:03:46

instead cons

thheller11:03:04

thought you wanted [{:label "Total", :price 900 :a :b}]

nxqd11:03:12

but the point is it seems to update the first map, what I want is another map in the vector instead.

nxqd11:03:21

[{:label "Total", :price 900} {:a :b}]

thheller11:03:59

(conj ttt {:a :b}) should do just that

nxqd11:03:05

yeah, it's true. I have tried that one but change list to vector and didn't notice it

thheller11:03:50

for cons you'd swap argument order

nxqd11:03:00

problem solved. Btw, your solution above with map is pretty nice though.

thheller11:03:01

update and update-in are pretty great simple_smile

nxqd11:03:42

yeah, I don't use it much outside swap!

mitchelkuijpers12:03:15

Is anyone aware of a clojurescript reveal.js alternative?

triss12:03:11

hey all... I don't know a lot about databases....

triss12:03:29

but I need one to store a lot of s-expressions in. I'll be checking whether or not sexp are already present with in it, filtering them based on predicates and randomly selecting from these.

triss12:03:49

can anyone recommend a good free one to get started with?

triss12:03:26

free space online would be marvellous. Would datomic be a good fit?

triss12:03:42

If I've got to learn db's might as well go with this super trendy one right?

chrisn13:03:08

Is there a way to extend ring middleware declaratively to add new types to all encoders?

chrisn13:03:40

Aside from recursively going through and converting something like the response to base clojure types?

chrisn13:03:21

I have a deep stack trace where authorization is calling middleware.format_response which is then throwing due to something that is actually easily converted to a persistent vector.

urbanslug14:03:24

An easy way to learn Om if I’m not good at JS and don’t know react?

dm314:03:39

wouldn't suggest learning Om then simple_smile

theqabalist15:03:23

specifically the main ad on the homepage “ClojureScript and Om"

urbanslug15:03:42

@theqabalist: Thanks simple_smile

urbanslug15:03:47

Why is owner always passed in Om?

chrisoakman16:03:26

@urbanslug: You might have better luck in the #C06DT2YSY channel

mattyulrich16:03:12

Has anyone seen cljsbuild silently fail on error and copy a cached version of cljs/js to destination before?

michaellopez16:03:01

@urbanslug start with #C09GR9UJC? it’s like a gateway drug

currentoor17:03:23

How should I get the current route in cljs? I could use js/location.pathname but is there a better way? Using the google closure lib perhaps?

dnolen17:03:22

@currentoor: that’s fine if that’s a cross browser way - I don’t know myself

currentoor17:03:05

cool thanks!

base69818:03:09

Someone people on my team are about to use react for a small project and got excited about the immutability stuff. I decided now was the time to drop the clojure bomb. They've now seen the talk @dnolen gave in reference to the Dream Machine, the Figwheel demo, Simple made easy, etc. Any other must see talks to keep the fire going?

base69818:03:20

Is there a way to build universal apps in clojurescript?

dnolen18:03:39

@base698: what do you mean by universal?

dnolen18:03:50

if you mean back/front, then it’s more typical to do Clojure + ClojureScript

base69818:03:11

Basically hitting a url: http://app/users/1 -> render that page with the html

base69818:03:28

So you don't have to use phantomjs or something for web crawlers

base69818:03:28

Right now our app works by renderings a single page on the server for every url, so /users, /users/123 and / are all identical. In order for the page to catch up Angular knows the routes and renders the proper pages by loading the controllers for those routes. This is problematic for Google SEO, so in that case we render a full page with phantom js.

base69818:03:20

@dnolen: ^

hlolli20:03:58

What would be a good way to watch over a height of div element like this (.-height (style/getSize (gdom/getElement "main-content"))) so that when it changes it will update the app-state? Because in om componentDidMount doesn't seem to catch the changes on the first page load, despite the main content will spit out html into the div inside the render part of the defui

val_waeselynck20:03:42

@hlolli: from a quick search on SO there doesn't seem to be any easy way

val_waeselynck20:03:03

I would watch window resize events and register subscriptions to see how it impacts the div's height

val_waeselynck20:03:36

or just use setInterval, but that seems unclean

hlolli20:03:14

Yes, I already have events on window resize, so I load the page, and the svg's Im trying to resize start incorrect, as soon as I resize the browser, they jump into right position.

hlolli20:03:31

I see that om has a clock counter when I transact, I could just tap into that and check for resizes for the first say 20 seconds and stop it after that (given that you are not using g3 signal on the antartica).

hlolli20:03:55

Maybe this clock won't start until the browser had fully rendered, then it wont be a problem anywhere?

chrisoakman20:03:04

a hack might work best here

chrisoakman20:03:34

I assume you're using a throttled or debounced function for the window resize?

chrisoakman20:03:02

Just call that function every few 100ms when the page loads

chrisoakman20:03:31

and make it so that "extra" calls of that function are safe if there is nothing to change

chrisoakman20:03:25

ugly hack; works great simple_smile

hlolli20:03:32

ok nice, yes, sometimes we need ugly hacks to solve things. I'm just surprised why componentDidMount is actually being called when in fact the component was not fully mounted.

hlolli20:03:06

nice @chrisiokman you saved my evening!

chrisoakman20:03:41

glad to help simple_smile

bensu21:03:08

Any vi users having problems with cljs.build.api/watch? It seems to trigger double recompile when saving due to the .swp files

juhoteperi21:03:21

@bensu: set noswapfile

bensu21:03:02

thanks! I don't use vi but one of doo's users does.

bensu21:03:21

@juhoteperi: have you encountered that problem with watch?

juhoteperi21:03:40

No, because I have always used noswapfile

juhoteperi21:03:30

It is not realistic for tools to ignore all strange temp files editors might create so best solution is to configure editors to not write temp files

bensu21:03:35

ok, thanks!

juhoteperi22:03:37

Option to set ignore pattern could still be okay, but I prefer configuring the editor once instead of configuring multiple tools simple_smile

thheller23:03:04

@bensu @juhoteperi in shadow-build we fixed this by ignoring hidden files, that at least worked for emacs tmp files. should work for vim stuff as well. should be a simple patch for cljs.