CodeSeven/KoLite — pull request #10 by CraigCav (2012-12-16 19:47:07+00:00)
Title: Added support for deferreds/promises with async commands

I've added a couple of features I've found useful in one of our projects.

1) Transparent execution of commands (as if the were normal functions)

Suppose you have the following model:

var model = {
someCommand: ko.asyncCommand({
execute: function() {
//do something interesting
}
})
}

You can now invoke this command as if the function was directly on the model (rather than nested inside a command object), like this:

model.someCommand();

This makes it easier to add the command functionality to existing models, without breaking the existing consumers of the model.

2) Support for deferred/promise implementations (such as jquery.deferred)

This allows consumers of asyncCommands to chain additional behavior using the deferred/promise api:

model.doSomeWork().then(function() {
//do some additional work
}).

I've additionally added jasmine/phantom and some very basic tests for the above.

To run the tests, open a command line in the test directory and run "phantomjs spec.js".