Check out redux-supermodel v0.15.0!

If you ever lurk in the reactjs subreddit, you will probably have noticed that questions about how to organize AJAX requests within your react application is a near-daily occurrence. A lot of people are enthusiastic to try and build a React application, and almost every one of them is going to want to render some AJAX data in their components eventually.

A lot of people will mention writing reducers and action creators, but I feel like those answers leave you in a place where you are basically copy/pasting the same reducers and fetch calls all over your app. Why does it have to be so hard?

I will save the story of my personal thoughts and revelations about successfully managing data in React applications for another time, but I will say that designing a easy-to-use and scale-able way to interact with a RESTful API was one of the first things my team struggled with when we first started using React. Having just come off of a BackboneJS application, I really wanted to interact with an API in React the way I was used to with Backbone.

Hmmm, has it really been 2 years since then?

redux-supermodel evolved from my original internal solution. The idea was that all you needed to provide was a URL and it would generate all of the reducers and action creators you needed based on that. From there, you can interact with it via the connect() higher-order component in react-redux. Since then I’ve dressed up the interface a lot, wrote unit tests, and of course published it on the internet so that other React enthusiasts can share it.

As I mentioned, I took a lot of inspiration from BackboneJS models and collections with the original implementation, possibly too much. I didn’t really appreciate Unidirectional data flow and ended up coming up with something that was a rip-off of Backbone, including event dispatcher wire-up, before realizing that it didn’t work in a React context.

I’m not the only person to make this kind of mistake, a lot of people start out by trying to use jQuery in their React applications, because those are the tools they are used to in their previous apps.

I digress, redux-supermodel represents my journey to understanding, transitioning from what I thought I knew based on my last web app, and learning how to organize RESTful data in React. It’s something I’m proud of, and I think you should check it out.

Blissfully Reactive Bootstrap3 Tooltips with Meteor Templates

It’s been a long time since I wrote something here. I thought I would break the silence with a new post about Meteor.

Meteor makes it pretty easy to start prototyping a new project very quickly.
When you want your ol’ familiar Bootstrap for CSS, you just meteor add bootstrap and there it is, including the stylish $el.tooltip() component.

So while building templates in Meteor, I thought I had tooltips figured out. I’d write them something like this:


Template.my_awesome_template.rendered = ->

Template.my_awesome_template.tooltip_label = ->
  "It has #{Likes.find({}).count()} like(s)!"

Which looked great, but I quickly came to realize that when my Likes Collection changed, the bootstrap tooltip wasn’t getting refreshed, even though the underlying title attribute was. I tried using several event binding techniques like observe to try and refresh the tooltip whenever the collection changed, but those strategies weren’t panning out. I wasn’t interested in squirreling away a lot of tooltip code into my subscription callbacks, either.

It turns out, I was way over-complicating this. You see, I already have a function that was executing every time the label changed, it was just a tiny bit too fast. I wanted to refresh the tooltip AFTER the tooltip_label function ran, so this is what I did:

Template.my_awesome_template.tooltip_label = ->
  setTimeout (->
    ), 0
  "It has #{Likes.find().count()} like(s)!"

By calling setTimeout with a zero delay, I queued up the code to refresh the tooltip immediately after the function returns. A simple no cruft way to include reactive Bootstrap Tooltips in your Meteor Templates.

If you prefer to be educated through interactive media, here is a link to an example on Meteor Pad.

Updated August 10, 2014:
Turns out you can use the Meteor.defer function to do the same thing as setTimeout in an even cleaner way. Now my CoffeeScript looks like this:

Template.my_awesome_template.tooltip_label = ->
  Meteor.defer -> $('#link').tooltip('fixTitle')
  "It has #{Likes.find().count()} like(s)!"

Receiving Email Notifications for Report Processing Exceptions in SSRS

Seeing this error crop up in place of a graph or chart in an SSRS report always irked me.

Error: Subreport could not be shown

It means there is a problem, but it’s been swept under the rug. The calling application can’t process the error, because SSRS already has. It makes a note and replaces the report with a plain text label. And until recently, as the developer I wouldn’t know anything was wrong, because that same rug-sweep prevented anything amiss from showing up in the application’s logging system.

While going over the logs to find the source of an issue I was investigating, I noticed several other report processing errors that were unreported. I want to be proactive on issues where reports are broken, even if nobody reports a problem.

In SSRS, the Service Trace Log is the most complete source of information about errors running reports. I wanted to receive an email notification any time an error was logged by the Service Trace Log.

It seemed like a common enough request, and I was surprised to see no notes about setting up email notifications in the documentation for SSRS. In fact, the Microsoft recommendation is to just read the logs using a text editor, preferably before they expire in 14 days (default configuration).

There might be existing solutions that do something like this already, and there are a lot of improvements that can still be made, but my simple solution was to write a PowerShell Script that would watch the most recent SSRS Log File and generate an email when it found the text “ERROR:”. That script looks a bit like this:

$dir = 'C:\Program Files\Microsoft SQL Server\MSSQLSERVER\Reporting Services\LogFiles\';

$logFile = ls $dir | sort LastWriteTime | select -last 1

cat $logFile.FullName -Wait | where {$_ -match "ERROR:"} | % {

  Send-MailMessage `
    -To '' `
    -From '' `
    -Subject 'SSRS ERROR in Trace Log' `
    -Body "An error was detected in the SSRS Trace Log $($logFile.FullName): $_" `
    -SmtpServer 'localhost';


A few things of note: SSRS’ LogFiles are timestamped and a new one is created in 24 hours or when the last one gets too large. This means the script will eventually start watching the wrong file after SSRS has started the next one. Luckily for me, the log files on our servers tend to get replaced only once each day at around 10:00 PM, which is outside office hours so nobody is running reports.

At 4:00 AM I have a Windows Scheduled Task that refreshes the script, or starts it if for whatever reason it stopped running.

The “-Wait” switch on Get-Content (PowerShell Alias: cat) is a cheap way to get a tail -f style log watcher in a PowerShell script.