Fork me on GitHub
#beginners
<
2017-08-11
>
stvnmllr202:08:53

anyone have pointers on where to look for having clojurescript set the browser url? Prob just plain js, but not obvious. maybe just .location?

noisesmith02:08:16

@stvnmllr2 (set! (.-location js/window) s)

stvnmllr202:08:57

@noisesmith ok, thanks for the code even. Didn't know if anyone had a better way. Guess I'll just pass in my secretary generated URL and i'll be good.

nathansmutz06:08:04

Anybody ever see a situation where you have code like

(apply merge-with some-collection)

nathansmutz06:08:18

oops hit return too early

nathansmutz06:08:26

Anybody see a situation where you have code like

(defn merge-function [a b] ...)
(apply merge-with merge-function some-collection-of-maps)
and you get an ArityException for merge-function getting only one arg?

seancorfield06:08:32

Can you provide a concrete example?

nathansmutz06:08:42

Here's the whole function I'm dealing with:

(defn merge-ratings [col]
  (let [merge-function (fn [a b]
                         (let [a-ratings      (:ratings      a)
                               a-must-take    (:must-take    a-ratings)
                               a-student-path (:student-path a-ratings)
                               a-demand       (:demand       a-ratings)
                               b-ratings      (:ratings      b)
                               b-must-take    (:must-take    b-ratings)
                               b-student-path (:student-path b-ratings)
                               b-demand       (:demand       b-ratings)]
                           (update-in a [:ratings] #(do {:must-take (or a-must-take
                                                                        b-must-take)
                                                         :student-path (or a-student-path
                                                                           b-student-path)
                                                         :demand       (max (or a-demand 0)
                                                                            (or b-demand 0))}))))]                                                                       
      (->> col
           (map #(do {(:course-key %) %}))
           (apply merge-with merge-function)
           (apply merge-with merge-function)
           vals)))
It breaks on this:
(def merge-rating-test
    [{:prefix "PSY",
      :number "201",
      :credits 4.0,
      :title "Gen Psychology*SSC",
      :course-key :PSY201,
      :ratings {:must-take nil, :student-path true, :demand 1.0}}
     
     {:prefix "PSY",
      :number "201",
      :credits 4.0,
      :title "Gen Psychology*SSC",
      :course-key :PSY201,
      :ratings {:must-take true, :student-path nil, :demand 2.0}}
     
     {:prefix "PSY",
      :number "201",
      :credits 4.0,
      :title "Gen Psychology*SSC",
      :course-key :PSY201,
      :ratings {:must-take nil, :student-path nil, :demand 3.0}}])

(merge-ratings merge-ratings-test)

nathansmutz06:08:20

Hmm... didn't see that second merge line... I don't think that was always there. Let me fix that and try again.

nathansmutz06:08:06

Fixed it. Still breaks.

(defn merge-ratings [col]
  (let [merge-function (fn [a b]
                         (let [a-ratings      (:ratings      a)
                               a-must-take    (:must-take    a-ratings)
                               a-student-path (:student-path a-ratings)
                               a-demand       (:demand       a-ratings)
                               b-ratings      (:ratings      b)
                               b-must-take    (:must-take    b-ratings)
                               b-student-path (:student-path b-ratings)
                               b-demand       (:demand       b-ratings)]
                           (update-in a [:ratings] #(do {:must-take (or a-must-take
                                                                        b-must-take)
                                                         :student-path (or a-student-path
                                                                           b-student-path)
                                                         :demand       (max (or a-demand 0)
                                                                            (or b-demand 0))}))))]                                                                       
      (->> col
           (map #(do {(:course-key %) %}))
           (apply merge-with merge-function)
           vals)))

nathansmutz06:08:57

The weird thing is, when I changed (apply merge-with merge-function) with (apply merge-with list) it did exactly what I'd expect and output a list of the two values.

nathansmutz07:08:21

I think it's that #(do ... lambda. it expects parameters.

nathansmutz07:08:29

That was it. Fixed it. Sorry for the trouble

lepistane12:08:45

what am i doing wrong?

stvnmllr214:08:23

what does your app-db look like?

athomasoriginal22:08:58

I have a form in my clojurescript that looks like this:

(.remove this/classList  "playing")

sundarj22:08:20

/ is only used to get vars from a namespace, like cljs.core/map

sundarj22:08:40

to do what you are asking, you need to do (.remove (.-classList this) "playing")

sundarj23:08:09

ie, it's .method but .-prop

athomasoriginal22:08:48

in javascript it would be this.classList.remove(//...)

athomasoriginal22:08:55

When I write it like this, it works, but the clojurescript setup I have yells at me when I save, and it auot-reloads, saying "No such namespace: this, could not locate this.cljs, this.cljc, or JavaScript source providing ""

athomasoriginal22:08:35

perhaps I am accessing the remove method incorrectly?

adambard23:08:51

Use the this-as macro: (this-as this (.remove (.-classList this) "playing")) (I may not have nailed the .-classList part)

athomasoriginal23:08:43

sorry, I was using that...this is the whole code block:

(defn handle-remove-transition [e]
  (this-as this
    (when (= (.-propertyName e) "transform")
      (.remove this/classList  "playing"))))

sundarj23:08:15

@tkjone read my replies in the thread

athomasoriginal23:08:48

sorry, let me give that a try

sundarj23:08:30

you can also use the .. macro like so:

sundarj23:08:43

(.. this -classList (remove "playing"))

athomasoriginal23:08:22

true, I feel that one is more readable

sundarj23:08:32

🙂

athomasoriginal23:08:58

it ends up being about preference, yes?

sundarj23:08:40

the macro expands to the same code, so code-wise there's no difference

sundarj23:08:42

just whichever is preferred

sundarj23:08:45

it's basically the equivalent of the ->/`->>` macros for prototypes

noisesmith23:08:53

actually -> works in place of .. there

+cljs.user=> (-> #js{:a 0} .-a inc)
1

noisesmith23:08:11

oh, the difference is the .

sundarj23:08:25

ah, i didn't know the dot stuff worked with the threading macro, guess it does make sense