I really wanted to make progress on the RSS Reader project but it looks like that's not going to be happening anytime soon. I ran into a ton of issues with CORS. Even using a proxy didn't allow me to download RSS feeds. So I don't think there's any point to continue working on this project.
I pivoted to working on a nice Pomodoro timer web application. I don't want it to just be a normal "Material" design-y website. I want it to be weird, funky and busy.
Escaping CORS issues on the frontend is a doomed proposition. And beyond that, trying to work with ClojureScript and Clojure inconsistencies seriously demotivated me from continuing to work on the project. I might re-visit the project but as a full-stack application so I don't have to deal with CORS bullshit.
I moved on to the Pomodoro app which I'm calling Pomato (portmanteau of Potato and Tomato).
I started off by defining some simple Hiccup components for the start, stop and reset buttons. There was a question of how to store the state of the current time left. The easiest option for that was to store it in the re-frame db as raw number of seconds and then convert that into a nice readable time format in the view layer.
Handling the button clicks to create intervals was easy. I modified the code for creating an effects handler from the re-frame docs to handle this -
(re-frame.core/reg-fx ;; the re-frame API for registering effect handlers
:interval ;; the effect id
(let [live-intervals (atom {})] ;; storage for live intervals
(fn [{:keys [action id frequency event]}] ;; the handler
(if (= action :start)
(swap! live-intervals assoc id (js/setInterval #(dispatch event) frequency))
(do (js/clearInterval (get @live-intervals id))
(swap! live-intervals dissoc id))))))
Calling this effect is pretty easy. All we have to do is return the effect map from our button event handlers. I also added another key to the rfdb that stores state of whether there is a timer already in use. We can use this to prevent the start button from being used to create multiple concurrent setIntervals that decrements the time in the db.
I also solved one 4Clojure problem today -
- Flipping out
Write a higher-order function which flips the order of the arguments of an input function.
(defn flip-out
[i]
(fn [x y] (i y x)))
It's a very simple problem so i was surprised to see it under Medium problems. Maybe anything that has to do with Higher Order Functions automatically qualifies as a hard problem?
It's almost the last day of ClojureFam and I'm finally starting to build a real web application with Clojure. There's definitely something different about hacking together solutions on a codebase you didn't write vs writing the event and effect handlers yourself.
Today's tally -
- 1 4Clojure Problem
- Started re-frame project