Building an efficient subscription for knockout computed observables

Subscribing to a ko.computed isn’t the same thing as subscribing to a ko.observable. Ryan Niemeyer has written on the topic and I’ll admit, it took me a while to wrap my head around it. I’ll go over the problem and how we bypass it, but the end result is really handy and reusable: a new ‘efficientlySubscribe’ method that is a part of all ko.computed’s.

[Continue Reading...]

3 Responses to Building an efficient subscription for knockout computed observables

Extending Ryan Niemeyer’s protectedComputed

Ryan Niemeyer has a great article on the protectedComputed that he came up with, but I needed a little more functionality out of it. I ended up adding a few things and wanted to get it online for public consumption if anyone found the new functionality useful, so here it is!

[Continue Reading...]

0 Responses to Extending Ryan Niemeyer’s protectedComputed

Changing an observableArray in 1 notification

I was just reading Ryan Niemeyer’s 2nd post about performance in knockout.js and I saw arrayPushAll. We ended up needing to use it for reasons other than performance, but performance does benefit greatly from its use.

We just had a problem (4/6/2012) where we were adding an array of items, one at a time in a loop, to an observable array. We wanted that notification of the array changing to trigger an ajax request, but we couldn’t because we were getting {n} notifications and we only wanted one request.

Initially I had to wire up the event in an odd way and that approach didn’t feel right since it seemed that we should be able to use the arrays changed notification. I should have thought to look up if ko had a slice or an equivalent, but I didn’t at the time. Now we just use arrayPushAll and this gives us a single notification because its a single change to the array. This is a much better solution and the added performance is great too!

0 Responses to Changing an observableArray in 1 notification

How to Use Knockouts Computed Observables with the Mapping Plugin

This is a blurb on using knockout‘s computed observables on a collection of items that are made observable via the mapping plugin. If you haven’t seen KnockoutJS then immediately go and watch all the demo / intro videos you can. You’ll be extremely impressed!

[Continue Reading...]

7 Responses to How to Use Knockouts Computed Observables with the Mapping Plugin

Handling Server Side Exceptions During Ajax Requests

When developing typical server side functionality in ASP.NET we don’t usually worry about the users experience with errors or authentication issues. We don’t worry about that much because we know our custom error pages and forms auth will redirect our clients to the appropriate content. Its not great that our client gets redirected to an error page, but its better than the YSOD, etc.

When we’re working with ajax requests, we don’t have any of this built in functionality. Everything is up to us and the callbacks that we setup. All of our clients will eventually encounter unhandled exceptions during their ajax requests and without the proper handling, the users experience could be awful. Nowadays, the more we can control the users experience, especially in the event of a failure, the better. This article is all about building a way to easily handle the common types of failures and ensuring predictable results for our clients. This stuff isn’t that hard, and we should be able to do it in a way that “just works” for all ajax requests that we make.

[Continue Reading...]

2 Responses to Handling Server Side Exceptions During Ajax Requests