From 746b3fc46359a7cab852937eb432509146cc6a0d Mon Sep 17 00:00:00 2001 From: "stephen.lautier" Date: Sun, 26 Jul 2015 19:30:46 +0200 Subject: [PATCH 1/2] Added definitions for ng-command --- ng-command/ng-command-tests.ts | 25 +++++++++++++++++ ng-command/ng-command.d.ts | 49 ++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 ng-command/ng-command-tests.ts create mode 100644 ng-command/ng-command.d.ts diff --git a/ng-command/ng-command-tests.ts b/ng-command/ng-command-tests.ts new file mode 100644 index 000000000..77fea7b40 --- /dev/null +++ b/ng-command/ng-command-tests.ts @@ -0,0 +1,25 @@ +/// +/// + +var app = angular.module('testModule', ['ng-command']); + +class CommandTestController { + + constructor($command: ngCommand.ICommandFactory, $scope: ng.IScope, $timeout: ng.ITimeoutService) { + + var cmd = $command($scope, () => { + return $timeout(() => {}, 0) + }) + + var cmdWithCanExecute = $command($scope, () => { + return $timeout(() => {}, 0) + }, () => false); + + cmd.isExecuting === false; + cmd.canExecute === false; + cmd.execute(); + } + +} + +app.controller('TestController', CommandTestController); diff --git a/ng-command/ng-command.d.ts b/ng-command/ng-command.d.ts new file mode 100644 index 000000000..f840ebea0 --- /dev/null +++ b/ng-command/ng-command.d.ts @@ -0,0 +1,49 @@ +// Type definitions for ng-command 0.2.0 +// Project: https://github.com/stephenlautier/ng-command +// Definitions by: Stephen Lautier +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module ngCommand { + + var ModuleName: string; + + /** + * Command proxy object. + */ + interface ICommand { + /** + * Determines whether the command is currently executing. + */ + isExecuting: boolean; + /** + * Determines whether the command can execute or not. + */ + canExecute: boolean; + /** + * Executes the command function. + */ + execute: () => angular.IPromise; + } + + class Command implements ICommand { + static id: string; + + isExecuting: boolean; + canExecute: boolean; + constructor($scope: angular.IScope, execute: () => angular.IPromise, canExecute?: () => boolean); + execute(): angular.IPromise; + } + + /** + * Command factory which creates instances of @see ICommand. + */ + interface ICommandFactory { + /** + * Factory instance creator method. + * @param $scope Scope which will keep track of the command. + * @param execute The execute function when the command is executed. + * @param canExecute Additional function which determines whether the command can executes. + */ + ($scope: angular.IScope, execute: () => angular.IPromise, canExecute?: () => boolean): ICommand; + } +} From 5d169679051319ca438834f7468dee3ea5103094 Mon Sep 17 00:00:00 2001 From: "stephen.lautier" Date: Sun, 26 Jul 2015 20:15:28 +0200 Subject: [PATCH 2/2] added angularjs reference --- ng-command/ng-command.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ng-command/ng-command.d.ts b/ng-command/ng-command.d.ts index f840ebea0..1a2cd6bd2 100644 --- a/ng-command/ng-command.d.ts +++ b/ng-command/ng-command.d.ts @@ -3,6 +3,8 @@ // Definitions by: Stephen Lautier // Definitions: https://github.com/borisyankov/DefinitelyTyped +/// + declare module ngCommand { var ModuleName: string;