clojurescriptboot-cljhoplon

Conditional statements in Clojurescript with Hoplon and cells not working


I have a question regarding conditionals and Hoplon. When I try:

(defn mouse-enter
  [temp stuff]
  (reset! temp @stuff)
  (if (= "y" "y")
      (reset! mon-width {:width "0%"})))

It changes the CSS width property to 0, but, if I try using a cell in any way it doesn't seem to work. IE.

(def week-view (cell "y"))
(def mon-width (cell {:width "50.333%"}))

(defn mouse-enter
  [temp stuff]
  (reset! temp @stuff)
  (if (= "y" (cell= week-view))
      (reset! mon-width {:width "0%"})))

Or:

(defn mouse-enter
  [temp stuff]
  (reset! temp @stuff)
  (if (= "y" (str (cell= week-view)))
      (reset! mon-width {:width "0%"})))

Or:

 (defn mouse-enter
   [temp stuff]
   (reset! temp @stuff)
   (when (= "y" (str (cell= week-view)))
         (reset! mon-width {:width "0%"})))

Or:

 (defn mouse-enter
   [temp stuff]
   (reset! temp @stuff)
   (when (= (cell= "y") (cell= week-view))
         (reset! mon-width {:width "0%"})))

And this one works even though the value of week-view has changed.

(def week-view (cell "n"))
(def mon-width (cell {:width "50.333%"}))

(defn mouse-enter
  [temp stuff]
  (reset! temp @stuff)
  (when (= (str (cell= "y")) (str (cell= week-view)))
        (reset! mon-width {:width "0%"})))

I don't really know what is going on but I am just trying to get the true conditional active when 'week-view' is set to "y". I tried booleans, that didn't seem to work and a lot of other stuff.

Cheers, Matt


Solution

  • I think I figured it out. You can use the @ symbol to get the value of the cell. Here is the new code that works.

    (def week-view (cell nil))
    (def mon-width (cell {:width "8.333%"}))
    
    (defn mouse-enter
      [temp stuff]
      (reset! temp @stuff)
      (when (= nil @week-view)
            (reset! mon-width {:width "30%"})))
    

    Cheers, Matt