From 7197351c94cd863f96fcf28abe6d09a3bd6e0b54 Mon Sep 17 00:00:00 2001 From: Jaco Erasmus Date: Wed, 4 Jun 2014 15:44:48 +0200 Subject: [PATCH 1/2] Added - KoliteAsyncCommand interface (makes "isExecuting" public) --- kolite/kolite.d.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kolite/kolite.d.ts b/kolite/kolite.d.ts index 42efda4a9..4aa55fd81 100644 --- a/kolite/kolite.d.ts +++ b/kolite/kolite.d.ts @@ -58,6 +58,10 @@ interface KoliteCommand { execute(...args: any[]): any; } +interface KoliteAsyncCommand extends KoliteCommand { + isExecuting: KnockoutObservable; +} + interface KoLiteCommandOptions { execute?: any; canExecute?: (isExecuting: boolean) => any; @@ -65,7 +69,7 @@ interface KoLiteCommandOptions { interface KnockoutStatic { command(options: KoLiteCommandOptions): KoliteCommand; - asyncCommand(optons: KoLiteCommandOptions): KoliteCommand; + asyncCommand(optons: KoLiteCommandOptions): KoliteAsyncCommand; } interface KnockoutUtils { From e4426f902b38582f86c04cecb6cf2821affe5f87 Mon Sep 17 00:00:00 2001 From: Jaco Erasmus Date: Wed, 4 Jun 2014 16:44:50 +0200 Subject: [PATCH 2/2] Kolite - Added asyncCommand.isExecuting() unit test --- kolite/kolite-tests.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/kolite/kolite-tests.ts b/kolite/kolite-tests.ts index f2013241d..4306ede53 100644 --- a/kolite/kolite-tests.ts +++ b/kolite/kolite-tests.ts @@ -30,6 +30,22 @@ function test_asyncCommand() { }); } +function test_asyncCommand_isExecuting() { + var primaryCommand = ko.asyncCommand({ + execute: (complete) => { + $.when().always(complete); + }, + canExecute: (isExecuting) => { + return !isExecuting; + } + }); + + var firstRun = true; + var canCancel = ko.computed(() => { + return firstRun && !primaryCommand.isExecuting(); + }); +} + function test_dirtyFlag() { var viewModel; viewModel.dirtyFlag = new ko.DirtyFlag(viewModel.model);