CodeSeven/KoLite — pull request #15 by CraigCav (2013-01-12 18:10:55+00:00)
Title: Feature/transparent commanding

(This is a re-submission of https://github.com/CodeSeven/KoLite/pull/10 with consistent line endings).

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".