Fork me on GitHub
#clojurescript
<
2017-10-10
>
Bravi11:10:10

having trouble ending the interval here 😞

(defonce interval-handler
  (fn [{:keys [action id frequency event]}]
    (let [live-intervals (atom {})]
      (condp = action
        :start (swap! live-intervals assoc id (js/setInterval #(re-frame/dispatch event) frequency))
        :end (do (js/clearInterval (get live-intervals id))
                 (js/console.log "clearing interval")
                 (swap! live-intervals dissoc id))))))

(re-frame/reg-fx
  :interval
  interval-handler)

(defn start-game [db]
  {:interval {:action :start
              :id :time-checker
              :frequency 1000
              :event [:tick]}
   :db (-> db
           (assoc :is-playing? true)
           (refresh-colors))})

(defn end-game [db]
  {:interval {:action :end
              :id :time-checker}
   :db (assoc db :has-ended? true)})

(re-frame/reg-event-fx
  :tick
  (fn [{:keys [db]}]
    (if (> (:time-left db) 1)
      {:db (update db :time-left dec)}
      (end-game db))))
whenever I call end-game, it updates the db but doesn’t end that interval

Bravi11:10:40

figured it out

Bravi12:10:29

looks like I needed to deref live-intervals and actually there’s that mistake on this page:

Bravi12:10:52

should be (js/clearInterval (get @live-intervals id))

mikethompson12:10:14

@bravilogy thank you, I'll correct that mistake. Remember there is a #re-frame channel

Bravi12:10:29

yeah, but this channel is more active haha 😄

Bravi12:10:40

ok cool, I’ll stick with that one I promise

Bravi16:10:30

I was reading this: https://www.braveclojure.com/quests/deploy/ and was wondering if I can connect my repo to Travis CI and deploy JUST the html bit instead, to surge for example? Instead of having a full nginx setup, as my app is just front end

Bravi16:10:44

so basically it’s just clojurescript

madstap16:10:19

Can anyone recommend any guides on how to figure out problems with advanced compilation? I'm having a Cannot read property 'c' of null moment and I don't really know where to start

madstap16:10:40

Thanks so much for :pseudo-names. I still have no idea what's going on, but now I know which component in my app 🙂

sundarj16:10:59

you're welcome 🙂

emccue16:10:58

You should also run the compiler in verbose mode and set warn-on-reflection to true depending on how you go about interop

madstap16:10:26

I thought warn-on-reflection was just for java stuff?

Bravi18:10:16

so.. my first ClojureScript app: https://frequent-scarecrow.surge.sh/ and the code: https://github.com/Bravilogy/colours-game-clojure thanks everyone for helping out! 😄

lovuikeng22:10:40

Suggestions (1) since you're using jumbotron as entrance, you might want to jumbo your game look 'n feel too, for the sake of UX, (2) better to reward user for winning the game at some point, like a jumbo You Won of some sort, again, for the sake of UX

lovuikeng22:10:12

also don't forget the re-frame channel

Bravi22:10:04

Good suggestions, thank you!

yury.solovyov18:10:51

Any suggestions for a storage solution in the browser? Storing collections of mostly flat objects

nenadalm20:10:06

I was using LocalStorage for my app via https://github.com/alandipert/storage-atom. All interesting parts of state were serialized under single key. Now I am migrating to IndexedDB because of performance.

rbertrand23:10:16

@U662GKS3F how do you like IndexedDB?

yury.solovyov17:10:59

@U662GKS3F did you use any library?

nenadalm17:10:53

@U0HJ8KMH7 only thing I don't like so far is that you cannot write something like WHERE field1 = 3 OR field2 = 5. You need to make 2 queries and merge them.

nenadalm17:10:29

@U297WCSHK I didn't. I used the api directly via cljs interop. It looks very ugly and doesn't take into account failures - at least for now. (I am using it only on some project nobody uses and it's main purpose is to play with clj[s]...)

yury.solovyov09:10:17

I wonder if https://github.com/dfahlander/Dexie.js is directly consumable with latest compiler improvements, version on cljsjs is pretty dated

noisesmith18:10:07

I’ve had good luck with using transit to encode objects, and storing the resulting string as LocalStorage

mseddon21:10:37

Hi all, I wonder but am not at a computer right now, does hash under clojurescript produce the same result as clojure for the basic types? If so is this supposed to be a guarantee under some condition? Thanks!

noisesmith21:10:10

no, it’s not portable between clj and cljs

noisesmith21:10:26

iirc someone made a library to do portable hashes of data that is portable between clj and cljs… I’m not recalling the name though

mseddon21:10:16

It's not an issue for me, was just curious, but now I know that will keep me out of trouble later :)

dnolen21:10:17

@mseddon the only guarantee is that we should produce the same hash values regardless of JS VM

mseddon21:10:42

That is also good to know. Also, I am blown away how far clojurescript has come in such a short time, great work all.