Fork me on GitHub
#clojurescript
<
2016-07-15
>
cdine00:07:04

A newbie question.. Can a JS function be passed as an arg to a cljs function.. ?

cdine00:07:47

for example, a function that takes a fn as an arg and applies in on js/document..

ag00:07:22

Guys, can someone help… If I have a date parsed into unix, e.g.:

(:require [cljs-time.coerce :as time-coerce]
            [cljs-time.format :as time-format])

(-> "2016-05-10" time-format/parse time-coerce/to-long)

ag00:07:42

how do I unparse it back to date string?

ag00:07:54

Ignoring timezone

ag02:07:45

nvmd: I have figured that out

jjunior13002:07:28

@ag: show solution plz

ag02:07:14

(->> d-parsed time-coerce/from-long
    (time-format/unparse-local-date (time-format/formatter "YYYY-MM-dd")))

ag02:07:43

now I can’t figure out how to do ‘startOfDay’ ‘endOfDay’ kind of thing

ag02:07:54

I am now thinking if it’s worth of using cljs-time. clj-time for clojure is great, but I feel cljs-time is somewhat limited. Maybe I should just use moment packaged in CLJSJS?

tap06:07:23

I posted this question on #C08H80CUR channel. But thought there’s more people here at the moment. Maybe you all can help me too >I’m playing with Rum’s Server-side rendering(https://github.com/tonsky/rum#server-side-rendering). What’s the approach for sharing data between server and client? >For example, I render a collection which queried from database on server-side. How do I get an access to manipulate this collection on client-side? Should I make a separate ajax call to retrieve similar data? Is there a better way to do this?

rohit07:07:09

@cdine: Its certainly possible

schmandle07:07:46

@dnolen Ok thanks, I'll do that

martinklepsch11:07:20

@tap: the server side rendering in Rum does not help you with transporting the data you rendered to the client. I guess one approach would be to serialize app-db and put it somewhere into your HTML

dominicm12:07:10

^ Yahoo refer to this as dehydrating/rehydrating your state.

dominicm12:07:42

They had some interesting ideas about that a few years ago. They had the most complete isomorphic documentation for React when I was looking many years ago.

dominicm12:07:18

http://fluxible.io/ ah, this was their thing. And I'm pretty sure it was one of the early, if not the earliest, flux implementation with good isomorphic support.

dominicm12:07:24

I'm way OT now anyway.

dnolen12:07:58

@cdine yes, ClojureScript functions are just JS functions, you can pass these either way without issue

cdine13:07:08

thanks @dnolen . I know that, but my q was about passing JS functions around to a cljs func.. for example a cljs func that can take js/document.getElementById

cdine13:07:26

Or may be its a dumb q to ask...as its not just a func in the global scope but getElementById is a method of dom obj...

dnolen13:07:07

@cdine yes I answered that, it doesn’t matter

dnolen13:07:23

ClojureScript functions are JavaScript functions they interoperate completely

dnolen13:07:23

the main friction around CLJS/JS interop is data structures not functions

dnolen13:07:20

@cdine you may be asking a different question which is whether you can pass Object methods around as values and wether that will work

dnolen13:07:32

but that isn’t a ClojureScript question at all. That’s just about JavaScript.

cdine13:07:57

Makes sense... Cheers. I should try out stuff and may be comeback with specific questions..but thanks.

cdine13:07:05

( def f #(js/document.getElementsByTagName %)) (defn f-app [fe a] (fe a)) (f-app f "body")

dnolen13:07:17

@cdine in general you have to be careful about passing methods, they need to bound so they don’t lose the context of the object they are a method of

dnolen13:07:35

again this a JavaScript thing

cdine13:07:43

I just tried this on klipse... so yeah this was what I pictured...

cdine13:07:51

Yeah I realize that 😞

dnolen13:07:37

(def f (.bind js/document.getElementsByTagName js/document))

dnolen13:07:49

or something like that

cdine13:07:18

Will check it out.

dnolen13:07:43

@cdine this is one of the many cases where you cannot escape knowing something about JavaScript 🙂

christianromney20:07:44

what's the idiomatic cljs equivalent of clojure's inst? predicate?

mfikes21:07:18

@christianromney: ClojureScript gained inst? with the 1.9.76 release

krchia22:07:02

i’m using the d3 cljsjs package and can’t seem to access d3.event

krchia22:07:54

i’m not sure what to make of this (how to use js/d3.event)