Today’s the day we wrap up our countdown timer and deploy it to Heroku. But before we launch this puppy we need to clean house a little and spice up the visual appeal.
While the Stopwatch from our last post worked OK there are a spots that can be improved. For starters I’d like to separate the formatting of the time from the onTick method. Mainly because I want to be able to pull the current time out whenever someone hits reset or a new connection is made. Here’s how I updated Stopwatch to accomodate these changes:
I also namespaced the events so they would be easier to read when mixed in with the socket.io events. During the refactoring I noticed there were a lot of actors listening to, emitting or calling something like start. I’m not sure if there are common socket.io namespacing patterns but I based what I did on Backbone events and I think it works out well enough.
Cleaning up app.js
These changes to Stopwatch also require us to update the app.js that uses it.
I’ve made it so whenever a user resets or connects to the page they get the latest time. And of course whenever the stopwatch ticks they’ll get an update as well. I think it might also be nice if pressing start dispatched the latest time, I should probably add that… ;)
Tweaking the views
Lastly I’ve updated the view by adding some more buttons to correspond to the start/stop and reset methods. I’ve also wrapped everything in a container to make it easier to position:
Also notice that the socket events coming from the view have been namespaced as well.
Improving the type
Next up I want to enhance the type using one of Google’s webfonts. I chose a font called Black Ops One which seemed appropriately militaristic. Setting it up was as easy as adding one line to my layout.ejs
and my main.css file:
Finally I chose to use some funky buttons from Chad Mazzola’s CSS3 Buttons project. I went with the Thoughtbot buttons since they were red and awesome. The styles are pretty long so I’m just going to post my entire main.css for you to see:
SWEEEEEEET! I’ll go ahead and host it on Heroku but first I have to find out what the cost of leaving Node.js/Socket.io running indefinitely would be. Till then you should be able to get a local version of all this working or just clone the Github repo and now you too can have your very own Defcon stopwatch. enjoy! - Rob