TSD file for angular-q-spread module

This commit is contained in:
Rafal Witczak
2015-11-29 12:08:33 -08:00
committed by raf_w87@wp.pl
parent f8af639bf2
commit f1dfef3733
2 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
///<reference path="angular-q-spread.d.ts"/>
interface IMyService {
getFirstname(): ng.IPromise<string>;
getLastname(): ng.IPromise<string>;
}
interface IScope {
name: string;
}
function TestCtrl($scope: IScope, $q: ng.IQService, MyService: IMyService) {
$scope.name = null;
function firstCallback(firstname: string, lastname: string)
{
return firstname + ' ' + lastname;
}
function anotherCallback(fullname: string)
{
$scope.name = fullname;
}
function failureCallback(reason: any)
{
alert('Could not load data: ' + reason);
}
$q
.all([
MyService.getFirstname(),
MyService.getLastname()
])
.spread(firstCallback)
.then(anotherCallback)
.catch(failureCallback);
};
TestCtrl.$inject = ['$scope', '$q', 'MyService'];
angular.module('test').controller('TestCtrl', TestCtrl);

17
angular-q-spread/angular-q-spread.d.ts vendored Normal file
View File

@@ -0,0 +1,17 @@
// Type definitions for angular-q-spread module
// Project: https://www.npmjs.com/package/angular-q-spread
// Definitions by: rafw87 <https://github.com/rafw87>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../angularjs/angular.d.ts" />
declare module angular {
interface IPromise<T> {
/**
This method can be used as a replacement for then. Similarly, it takes two parameters, a callback when all promises are resolved and a callback for failure. The resolve callback is going to be called with the result of the list of promises passed to $q.all as separate parameters instead of one parameters which is an array.
* @param successCallback Callback for resolved promise, similar to then's one, but takes multiple parameters instead of single array parameter
* @param errorCallback Callback for error, the same as for then
*/
spread<TResult>(successCallback: (...promiseValues: any[]) => IPromise<TResult>|TResult, errorCallback?: (reason: any) => any): IPromise<TResult>;
}
}