Fork me on GitHub
#clojurescript
<
2016-04-22
>
mfikes00:04:36

@telent: In your -equiv impl above, consider = instead of ==. (The later is for nums.)

mfikes00:04:43

@telent: Also, if (= a b) then (= (hash a) (hash b))

mfikes00:04:14

In other words, consider IHash for Uri to make the implication true

telent08:04:05

mfikes: ah, ok, yes thanks. Forgot about hash

trgoodwin10:04:25

anyone have much experience with using http://cljsjs.github.io/ to managing including javascript packages?

meme310:04:27

Can you not just use npm for clojurescript?

trgoodwin10:04:39

specifically, i add the [cljsjs/google-platformjs-extern "1.0.0-0”] as a dependency, and require it like (:require cljsjs.google-platformjs-extern) but get a

No such namespace: cljsjs.google-platformjs-extern

pastafari10:04:31

@trgoodwin: "This package only contains the externs file. You need to provide the read code yourself."

pastafari10:04:14

@trgoodwin: my guess is that you need to include the platform.js file in your source path somewhere. @juhoteperi can probably answer this best.

juhoteperi10:04:16

@trgoodwin: @pastafari: The readme is incorrect, extern is always used and no require is needed.

trgoodwin11:04:32

thanks @juhoteperi. is there a reason the google-platform is just the extern, and not including the actual dependency

trgoodwin11:04:51

i thought that was part of the value of https://cljsjs.github.io

juhoteperi11:04:28

@trgoodwin: The code is only available from google cdn and is not versioned. Google might change the code any time.

juhoteperi11:04:40

And I presume that Google assumes that everyone is using the latest code. Even if the package was updated daily, apps would depend on old version and might break.

trgoodwin11:04:44

@juhoteperi: ah. i see. think that makes sense. so basically unless you can pin, you don’t include.

trgoodwin11:04:30

@juhoteperi: couldn’t the cljsjs/packages pin based on date when building jar.

trgoodwin11:04:58

get the latest from the cdn, and the matching extern

juhoteperi11:04:00

Yes, but then app would use certain version which might break.

juhoteperi11:04:55

I don't think Google promises that the version from today would work in two months

juhoteperi11:04:03

They might change some APIs the code is calling etc.

trgoodwin11:04:47

so if i understand it right. its more there is no way to know when change happens, therefore no way to know when to create a new jar

juhoteperi11:04:23

Not exactly. We could easily package the code each night if it has changed.

juhoteperi11:04:08

But if we package version 2016-04-22 and an application uses that version, it might be that in one week Google updates the code and old code will stop working.

juhoteperi11:04:20

Then the application has to be updated.

juhoteperi11:04:40

But if you just use the script tag with url pointing to google url, your application doesn't need to be updated.

trgoodwin11:04:48

right. so thats where i got confused. because i expected the cljsjs/package to bring the dependency down with it so that i wouldn’t need to use the script tag to include

trgoodwin11:04:30

i think i understand. the current setup is trying to respect more of the existing google stand of always use our latest

juhoteperi11:04:43

Google Maps package is the same

trgoodwin11:04:05

and if they actually changed their api, you’d have to update the externs and create a new package

trgoodwin11:04:52

got it now. thank you for taking the time to discuss.

dimiter11:04:19

Anyone have any good tips for Isomorphic OM CLJS rending on the server. Found the following, but thought I would see if anything else is out there: https://github.com/pupeno/prerenderer

dimiter11:04:03

Thanks, I will take a look.

dimiter12:04:13

Speaking of OM Next. Can I use OM Next and The legacy OM syntax in the same app, or do I have to stick to OM-next defui components.

lwhorton12:04:37

is it possible to define an app-util file that requires macros from another library and exposes them?

lwhorton12:04:06

for example, with cljs.test …

(ns testing-util.core
  (:require [cljs.test :as t :include-macros true]))

(defn deftest [& args]
  (apply t/deftest args))

anmonteiro12:04:27

@lwhorton: it is, but you can’t use apply with macros

lwhorton12:04:22

hm.. so what’s the combination I need to make this work?

anmonteiro12:04:59

@lwhorton: if you want to “apply” to a macro you’ll need another macro

jstew12:04:12

That seems like a code smell to me.

anmonteiro12:04:31

(defmacro deftest’ [& args]
  `(t/deftest ~@args))

lwhorton12:04:33

all I really want to do is house the exposed cljs.test macros with my functions that are just better-named

lwhorton12:04:37

(ns testing-util.core
  (:require [cljs.test :as t])
  (:require-macros [cljs.test :as tm :refer [deftest testing is are]]))

(def deftest deftest)

(def testing testing)

(def is is)

(def are are)

(defn when- [desc body]
  (testing desc body))

(defn given- [desc body]
  (testing desc body))

(defn it- [desc body]
  (testing desc body))

lwhorton12:04:17

so I can require a single [testing-util.core] and be on my merry way with given- when- it-

lwhorton12:04:23

but i’ve never been able to figure out how/if this is possible in cljs

anmonteiro12:04:02

so what’s the problem you’re having?

lwhorton12:04:53

i can never get the macro vs function importing to line up

lwhorton12:04:10

for example, with the above ^ and an implementation test:

(deftest test-test
  (given- "something is truthy"
          (when- "the first arg is true"
                 (it- "should also be true"
                      (is (= true true))))))

lwhorton12:04:45

i’ll just get use of undeclared var "test-test”, which seems like a macro problem

manutter5112:04:36

What if you don’t refer the cljs.test stuff, and just use namespaced symbols like (def deftest tm/deftest)? Does that work?

lwhorton12:04:54

i would assume this is because the call in test-test to deftest is reaching to testing-util.deftest, which is 1) proabably circular reference via (def deftest deftest)?

manutter5112:04:58

or can you do that with macros?

lwhorton12:04:10

I dont think you can do that with macros, tm/some-macro complains

lwhorton12:04:27

No such namespace: tm, could not locate tm.cljs, tm.cljc, or Closure namespace "" at line 8 test/cljs/testing_util/core.cljs

lwhorton12:04:02

so unless there’s a way to rename macros on import, then (def deftest renamed-deftest) i’m not sure what to do

manutter5112:04:12

Hmm, what about (def deftest t/deftest)? I don’t know nuthin about cljs macros really, but I’d give that a try just to see what happened

lwhorton13:04:28

hm, even with :require [cljs.test :as t :include-macros true] the def deftest t/deftest complains: Can't take value of macro cljs.test/deftest at line 7 test/cljs/testing_util/core.cljs`

manutter5113:04:20

I guess that makes sense

anmonteiro13:04:27

(defmacro deftest' [name & args]
  `(cljs.test/deftest ~name ~@args))

anmonteiro13:04:44

put that in a .clj file

anmonteiro13:04:54

in your .cljs file, do: (:require [cljs.test :refer-macros [is run-tests]])

anmonteiro13:04:11

(deftest' my-test (is true))
(run-tests)

anmonteiro13:04:27

Ran 1 tests containing 1 assertions.
0 failures, 0 errors.

anmonteiro13:04:11

FWIW, so does this:

(defmacro deftest' [& args]
  `(cljs.test/deftest ~@args))

lwhorton13:04:37

but how do I then have a some_other_test.cljs which pulls in deftest’?

lwhorton13:04:49

oh wait, give me a sec 😕

leontalbot20:04:20

Hello! Are these the same?

leontalbot20:04:16

JS: m.dragging.disable(); CLJS : (.disable (.dragging m))

jr20:04:45

(.disable (.-dragging m))
is probably what you are looking for

jr20:04:56

where .- denotes a property accessor and not a function call

leontalbot20:04:44

Excellent, thank you!

leontalbot21:04:01

I am sure there is a better way than to repeat (when). Any ideas? Thanks guys!

...
(let [m (.map js/L $e)]
  ...
  ;;Disable drag and zoom handlers
  (when (false? dragging) (.disable (.-dragging m)))
  (when (false? scroll-wheel-zoom) (.disable (.-scrollWheelZoom m)))
  (when (false? touch-zoom) (.disable (.-touchZoom m)))
  (when (false? double-click-zoom) (.disable (.-doubleClickZoom m))))

leontalbot21:04:48

I though of (cond false? dragging ... scroll-wheel-zoom ... ...) but then when the first condition is met it'll stop doing side effects, which I don't want...

dnolen21:04:43

@leontalbot: I don’t really see a problem with a bunch of whens if you need them. (when (false? …)) could be written (when-not …)in this case it seems to me.

leontalbot21:04:11

@dnolen: Thank you! Regarding when-not I don't use it so that if one arg like dragging is not explicitly set to false (in other words, if nil) the according side effect won't happen...

dpsutton22:04:15

can you call the functions .-doubleClickZoom and the like with apply?

tom22:04:50

Trying to figure out the proper interop to reconstruct this JS. Does (set! js/player (.Player js/YT "player", (clj->js {...}))) Work the same?

// YT is a global scope variable
  player = new YT.Player('player', {
    height: '390',
    width: '640',
    videoId: 'M7lc1UVf-VE',
    events: {
      'onReady': onPlayerReady,
      'onStateChange': onPlayerStateChange
    }
  });

taylor.sando22:04:47

You should be able to do

(js/YT.Player. "player", (clj->js {...}))

tom22:04:30

That did it, thanks @taylor.sando!

lich23:04:01

hey! I’d like to ask some recommendation about Clojure - ClojureScript interop. Now I’m using REST API, but it gets a bit hard to implement it, i need at least understand async.