if (count > 100) {
$el.removeClass('low-value');
$el.addClass('high-value');
} else if (count < 50) {
$el.removeClass('high-value');
$el.addClass('low-value');
} else {
$el.removeClass('high-value');
$el.removeClass('low-value');
}
Compare to how this would normally be written: $el.toggleClass('high-value', count > 100);
$el.toggleClass('low-value', count < 50);In a perfect world, you're able to bind changes in the data to changes in the view at the level of granularity at which your app needs to update. Most of the time, atomic chunks of HTML will be the most performant. Rarely, but sometimes, attributes.
A long-winded way of saying -- Great stuff! But be wary when starting to do it this way by default.
We actually had a special case of a UI that needed to have many many things updating via push events, and have profiled it a few different ways. Turned out that with the frequency of updates we were making, larger chunks of HTML ended up being multiple times more expensive than adding a class here, or changing the text in a tag over there. This method actually _was_ the optimization.