One of the interesting features of Meteor is that when you update a source file, the update is pushed down to clients immediately. I made some minor changes to the template and was pleased to see the changes getting pushed down as advertised. Very cool.
The leaderboard example page suggested some changes to get familiar with Meteor. The first was to add a button which would toggle sorting by score or by name. I felt confident that this should be a straightforward task, and started in with changes. First I added a button to the template. Meteor uses handlebars as its template engine (with more engine support promised), so I was able to dynamically change the button’s caption:
Saving this broke the front-end when it auto-reloaded because the template doesn’t have a sort_by_name yet. This was easily corrected:
I then followed the pattern of the existing click handler for adding points to create my click handler:
Finally I updated the players function to return a list sorted in accordance with this new session setting:
With the run of successes to this point, and the fact that this seemed like a trivial update I hit save, switched to my browser, was greeted with the new Sort button. I clicked it expecting a complete success.
So I took a desperate leap of desperation and consulted the documentation. There it was in glorious bold red lettering – a documented bug in event handling: “If an event is filtered by a selector, then it will never be delivered to a top-level node in a template.”
My button was a top level node in its template. I wrapped that sucker in a <div> tag, hit save, switched to my browser window, clicked it and was rewarded with a sorted list! Ecstasy.
As I attempt the other challenges suggested for the leaderboard example, I won’t be so slow to consult the excellent documentation. As frustrating as this was, the fact that the bug was so clearly documented, and the fact that everything else went so smoothly makes me confident that the Meteor project will be very successful. I’ll let you know how it goes.