diff --git a/README.md b/README.md index 8760adc87..8183ef1c4 100755 --- a/README.md +++ b/README.md @@ -32,12 +32,14 @@ List of Definitions * [AmCharts](http://www.amcharts.com/) (by [Covobonomo](https://github.com/covobonomo/)) * [AngularJS](http://angularjs.org) (by [Diego Vilar](https://github.com/diegovilar)) ([wiki](https://github.com/borisyankov/DefinitelyTyped/wiki/AngularJS-Definitions-Usage-Notes)) * [AngularUI](http://angular-ui.github.io/) (by [Michel Salib](https://github.com/michelsalib)) +* [Angular Translate](http://pascalprecht.github.io/angular-translate/) (by [Michel Salib](https://github.com/michelsalib)) * [Angular UI Bootstrap](http://angular-ui.github.io/bootstrap) (by [Brian Surowiec](https://github.com/xt0rted)) * [AppFramework](http://app-framework-software.intel.com/) (by [Kyo Ago](https://github.com/kyo-ago)) * [Arbiter](http://arbiterjs.com/) (by [Arash Shakery](https://github.com/arash16)) * [async](https://github.com/caolan/async) (by [Boris Yankov](https://github.com/borisyankov)) * [Backbone.js](http://backbonejs.org/) (by [Boris Yankov](https://github.com/borisyankov)) * [Backbone Relational](http://backbonerelational.org/) (by [Eirik Hoem](https://github.com/eirikhm)) +* [Bluebird](https://github.com/petkaantonov/bluebird) (by [Bart van der Schoor](https://github.com/Bartvds)) * [Bootbox](https://github.com/makeusabrew/bootbox) (by [Vincent Bortone](https://github.com/vbortone/)) * [Bootstrap](http://twitter.github.com/bootstrap/) (by [Boris Yankov](https://github.com/borisyankov)) * [bootstrap-notify](https://github.com/Nijikokun/bootstrap-notify) (by [Blake Niemyjski](https://github.com/niemyjski)) @@ -64,6 +66,7 @@ List of Definitions * [EaselJS](http://www.createjs.com/#!/EaselJS) (by [Pedro Ferreira](https://bitbucket.org/drk4)) * [ember.js](http://emberjs.com/) (by [Boris Yankov](https://github.com/borisyankov)) * [EpicEditor](http://epiceditor.com/) (by [Boris Yankov](https://github.com/borisyankov)) +* [ES6-Promises](https://github.com/jakearchibald/ES6-Promises) (by [François de Campredon](https://github.com/fdecampredon/)) * [expect.js](https://github.com/LearnBoost/expect.js) (by [Teppei Sato](https://github.com/teppeis)) * [expectations](https://github.com/spmason/expectations) (by [vvakame](https://github.com/vvakame)) * [Express](http://expressjs.com/) (by [Boris Yankov](https://github.com/borisyankov)) @@ -149,6 +152,7 @@ List of Definitions * [jQuery.Validation](http://bassistance.de/jquery-plugins/jquery-plugin-validation/) (by [Boris Yankov](https://github.com/borisyankov)) * [jQuery.Watermark](http://jquery-watermark.googlecode.com) (by [Anwar Javed](https://github.com/anwarjaved)) * [jQuery.base64](https://github.com/yatt/jquery.base64) (by [Shinya Mochizuki](https://github.com/enrapt-mochizuki)) +* [js-git](https://github.com/creationix/js-git) (by [Bart van der Schoor](https://github.com/Bartvds)) * [jScrollPane](http://jscrollpane.kelvinluck.com) (by [Dániel Tar](https://github.com/qcz)) * [JSDeferred](http://cho45.stfuawsc.com/jsdeferred/) (by [Daisuke Mino](https://github.com/minodisk)) * [JSONEditorOnline](https://github.com/josdejong/jsoneditoronline) (by [Vincent Bortone](https://github.com/vbortone/)) diff --git a/angular-translate/angular-translate-tests.ts b/angular-translate/angular-translate-tests.ts new file mode 100644 index 000000000..7cb6c89c3 --- /dev/null +++ b/angular-translate/angular-translate-tests.ts @@ -0,0 +1,25 @@ +/// + +var app = angular.module('at', ['pascalprecht.translate']); + +app.config(($translateProvider: ng.translate.ITranslateProvider) => { + $translateProvider.translations('en', { + TITLE: 'Hello', + FOO: 'This is a paragraph.', + BUTTON_LANG_EN: 'english', + BUTTON_LANG_DE: 'german' + }); + $translateProvider.translations('de', { + TITLE: 'Hallo', + FOO: 'Dies ist ein Paragraph.', + BUTTON_LANG_EN: 'englisch', + BUTTON_LANG_DE: 'deutsch' + }); + $translateProvider.preferredLanguage('en'); +}); + +app.controller('Ctrl', ($scope: ng.IScope, $translate: ng.translate.ITranslateService) => { + $scope['changeLanguage'] = function (key: any) { + $translate.uses(key); + }; +}); diff --git a/angular-translate/angular-translate.d.ts b/angular-translate/angular-translate.d.ts new file mode 100644 index 000000000..aac4a7412 --- /dev/null +++ b/angular-translate/angular-translate.d.ts @@ -0,0 +1,63 @@ +// Type definitions for Angular Translate (pascalprecht.translate module) +// Project: https://github.com/PascalPrecht/angular-translate +// Definitions by: Michel Salib +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module ng.translate { + interface ITranslationTable { + [key: string]: string; + } + + interface IStorage { + get(name: string): string; + set(name: string, value: string): void; + } + + interface ISTaticFilesLoaderOptions { + prefix: string; + suffix: string; + key?: string; + } + + interface ITranslateService { + (key: string, ...params: string[]): string; + fallbackLanguage(): string; + preferredLanguage(): string; + proposedLanguage(): string; + refresh(lankKey: string): ng.IPromise; + storage(): IStorage; + storageKey(): string; + uses(): string; + uses(key: string): ng.IPromise; + } + + interface ITranslateProvider extends ng.IServiceProvider { + translations(key: string, translationTable: ITranslationTable): ITranslateProvider; + addInterpolation(factory: any): ITranslateProvider; + useMessageFormatInterpolation(): ITranslateProvider; + useInterpolation(factory: string): ITranslateProvider; + preferredLanguage(): string; + preferredLanguage(language: string): ITranslateProvider; + translationNotFoundIndicator(indicator: string): ITranslateProvider; + translationNotFoundIndicatorLeft(): string; + translationNotFoundIndicatorLeft(indicator: string): ITranslateProvider; + translationNotFoundIndicatorRight(): string; + translationNotFoundIndicatorRight(indicator: string): ITranslateProvider; + fallbackLanguage(): string; + fallbackLanguage(language: string): ITranslateProvider; + uses(): string; + uses(key: string): ITranslateProvider; + useUrlLoader(url: string): ITranslateProvider; + useStaticFilesLoader(options: ISTaticFilesLoaderOptions): ITranslateProvider; + useLoader(loaderFactory: string, options: any): ITranslateProvider; + useLocalStorage(): ITranslateProvider; + useCookieStorage(): ITranslateProvider; + useStorage(storageFactory: any): ITranslateProvider; + storagePrefix(): string; + storagePrefix(prefix: string): ITranslateProvider; + useMissingTranslationHandlerLog(): ITranslateProvider; + useMissingTranslationHandler(factory: string): ITranslateProvider; + } +} diff --git a/angularjs/angular.d.ts b/angularjs/angular.d.ts index 962818ad7..6a656b00b 100755 --- a/angularjs/angular.d.ts +++ b/angularjs/angular.d.ts @@ -105,6 +105,7 @@ declare module ng { filter(object: Object): IModule; provider(name: string, serviceProviderConstructor: Function): IModule; provider(name: string, inlineAnnotadedConstructor: any[]): IModule; + provider(name: string, providerObject: auto.IProvider): IModule; provider(object: Object): IModule; run(initializationFunction: Function): IModule; run(inlineAnnotadedFunction: any[]): IModule; @@ -806,6 +807,9 @@ declare module ng { // AUTO module (angular.js) /////////////////////////////////////////////////////////////////////////// export module auto { + interface IProvider { + $get: any; + } /////////////////////////////////////////////////////////////////////// // InjectorService diff --git a/bluebird/bluebird-test.ts b/bluebird/bluebird-test.ts new file mode 100644 index 000000000..92e5e7b6b --- /dev/null +++ b/bluebird/bluebird-test.ts @@ -0,0 +1,327 @@ +/// + +var obj:Object; +var bool:boolean; +var num:number; +var str:string; +var x:any = null; +var f:Function; +var arr:any[]; +var exp:RegExp; +var strArr:string[]; +var numArr:string[]; + + +var value:any = null; +var reason:any = null; + +var Promise:Bluebird.PromiseStatic; + +var promise:Bluebird.Promise; +var p:Bluebird.Promise; + +var resolver:Bluebird.PromiseResolver; +var inspection:Bluebird.PromiseInspection; +var arrLike:Bluebird.ArrayLike; + +// - - - - - - - - - - - - - - - - - - - - - - - - + +var promise = new Promise((resolve:(value:any) => void, reject:(reason:any) => void) => { + if(true) { + resolve(123); + } + else { + reject(new Error('nope')); + } +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - + +num = arrLike.length; + +// - - - - - - - - - - - - - - - - - - - - - - - - + +resolver.resolve(x); + +resolver.reject(x); + +resolver.progress(x); + +resolver.callback = () => { + +}; + +// - - - - - - - - - - - - - - - - - - - - - - - - + +bool = inspection.isFulfilled(); + +bool = inspection.isRejected(); + +bool = inspection.isPending(); + +x = inspection.value(); + +x = inspection.error(); + +// - - - - - - - - - - - - - - - - - - - - - - - - + +p = promise.then((value:any) => { + +}, (reason:any) => { + +}, (note:any) => { + +}); +p = promise.then((value:any) => { + +}, (reason:any) => { + +}); +p = promise.then((value:any) => { + +}); + + +p = promise.catch((reason:any) => { + +}); +p = promise.caught((reason:any) => { + +}); +p = promise.catch((reason:any) => { + return true; +}, (reason:any) => { + +}); +p = promise.caught((reason:any) => { + return true; +}, (reason:any) => { + +}); + +p = promise.catch(Error, (reason:any) => { + +}); +p = promise.caught(Error, (reason:any) => { + +}); + +p = promise.error((reason:any) => { + +}); + +p = promise.finally((value:any) => { + +}); +p = promise.lastly((value:any) => { + +}); + +p = promise.bind(x); + +p = promise.done((value:any) => { + +}, (reason:any) => { + +}, (note:any) => { + +}); +p = promise.done((value:any) => { + +}, (reason:any) => { + +}); +p = promise.done((value:any) => { + +}); + +p = promise.progressed((note:any) => { + +}); + +p = promise.delay(x); + +p = promise.timeout(x); +p = promise.timeout(x, str); + +p = promise.nodeify(); +p = promise.nodeify(function(err:any) { + +}); + +p = promise.cancellable(); + +p = promise.cancel(); + +p = promise.fork((value:any) => { + +}, (reason:any) => { + +}, (note:any) => { + +}); +p = promise.fork((value:any) => { + +}, (reason:any) => { + +}); +p = promise.fork((value:any) => { + +}); + +p = promise.uncancellable(); + +bool = promise.isCancellable(); + +bool = promise.isFulfilled(); + +bool = promise.isRejected(); + +bool = promise.isPending(); + +bool = promise.isResolved(); + +inspection = promise.inspect(); + +p = promise.call(str, 1, 2, 3); + +p = promise.get(str); + +p = promise.return(value); +p = promise.thenReturn(); + +p = promise.throw(x); +p = promise.thenThrow(); + +str = promise.toString(); + +obj = promise.toJSON(); + +p = promise.all(); + +p = promise.props(); + +p = promise.settle(); + +p = promise.any(); + +p = promise.some(x); + +p = promise.race(); + +p = promise.spread((value:any) => { + +}, (reason:any) => { + +}); +p = promise.spread((value:any) => { + +}); + +p = promise.map((item:any, index:number, arrayLength:number) => { + return x; +}); + +p = promise.reduce((total:number, memo:any, index:number, arrayLength:number) => { + return memo; +}); +p = promise.reduce((total:number, memo:any, index:number, arrayLength:number) => { + return memo; +}, x); + +p = promise.filter((item:any, index?:number, arrayLength?:number) => { + return true; +}); + +// - - - - - - - - - - - - - - - - - - - - - - - - + +p = new Promise((resolve:(value:any) => any, reject:(reason:any) => any) => { + if(true) { + resolve(value); + } + else { + reject(new Error('xyz')); + } +}); + +p = Promise.try(() => {}); +p = Promise.try(() => {}, arr); +p = Promise.try(() => {}, arr, x); +p = Promise.try(() => {}, arrLike); +p = Promise.try(() => {}, arrLike, x); + + +p = Promise.attempt(() => {}); +p = Promise.attempt(() => {}, arr); +p = Promise.attempt(() => {}, arr, x); +p = Promise.attempt(() => {}, arrLike); +p = Promise.attempt(() => {}, arrLike, x); + +f = Promise.method(function() { + +}); + +p = Promise.resolve(value); + +p = Promise.reject(reason); + +resolver = Promise.defer(); + +p = Promise.cast(value); + +p = Promise.bind(x); + +bool = Promise.is(value); + +Promise.longStackTraces(); + +p = Promise.delay(p, x); +p = Promise.delay(value, x); +p = Promise.delay(x); + +f = Promise.promisify(f); +f = Promise.promisify(f, x); + +obj = Promise.promisify(obj); + +obj = Promise.promisifyAll(obj); + +f = Promise.coroutine(f); + +p = Promise.spawn(f); + +obj = Promise.noConflict(); + +Promise.onPossiblyUnhandledRejection((reason:any) => { + +}); + +p = Promise.all(arr); + +p = Promise.props(p); +p = Promise.props(obj); + +p = Promise.settle(arr); + +p = Promise.any(arr); + +p = Promise.race(arr); + +p = Promise.some(arr, x); + +p = Promise.join(1, 2, 3); + +p = Promise.map(arr, (item:any, index:number, arrayLength:number) => { + return x; +}); + +p = Promise.reduce(arr, (total:number, memo:any, index:number, arrayLength:number) => { + return memo; +}); +p = Promise.reduce(arr, (total:number, memo:any, index:number, arrayLength:number) => { + return memo; +}, x); + +p = Promise.filter(arr, (item:any, index?:number, arrayLength?:number) => { + return true; +}); diff --git a/bluebird/bluebird.d.ts b/bluebird/bluebird.d.ts new file mode 100644 index 000000000..c05f8b02b --- /dev/null +++ b/bluebird/bluebird.d.ts @@ -0,0 +1,498 @@ +// Type definitions for bluebird 1.0.0 +// Project: https://github.com/petkaantonov/bluebird +// Definitions by: Bart van der Schoor +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module Bluebird { + + interface ArrayLike { + length:number; + } + + interface Promise { + /** + * Promises/A+ `.then()` with progress handler. Returns a new promise chained from this promise. The new promise will be rejected or resolved dedefer on the passed `fulfilledHandler`, `rejectedHandler` and the state of this promise. + */ + then(fulfilledHandler?:(value:any) => any, rejectedHandler?:(reason:any) => any, progressHandler?:(note:any) => any):Promise; + + /** + * This is a catch-all exception handler, shortcut for calling `.then(null, handler)` on this promise. Any exception happening in a `.then`-chain will propagate to nearest `.catch` handler. + * + * Alias `.caught();` for compatibility with earlier ECMAScript version. + */ + catch(handler:(reason:any) => any):Promise; + caught(handler:(reason:any) => any):Promise; + + /** + * This extends `.catch` to work more like catch-clauses in languages like Java or C#. Instead of manually checking `instanceof` or `.name === "SomeError"`, you may specify a number of error constructors which are eligible for this catch handler. The catch handler that is first met that has eligible constructors specified, is the one that will be called. + * + * This method also supports predicate-based filters. If you pass a predicate function instead of an error constructor, the predicate will receive the error as an argument. The return result of the predicate will be used determine whether the error handler should be called. + * + * Alias `.caught();` for compatibility with earlier ECMAScript version. + */ + //TODO expand this complex overload (weird) + catch(predicate:(reason:any) => boolean, handler:(reason:any) => any):Promise; + caught(predicate:(reason:any) => boolean, handler:(reason:any) => any):Promise; + + catch(ErrorClass:Function, handler:(reason:any) => any):Promise; + caught(ErrorClass:Function, handler:(reason:any) => any):Promise; + + /** + * Like `.catch` but instead of catching all types of exceptions, it only catches those that don't originate from thrown errors but rather from explicit rejections. + */ + error(rejectedHandler:(reason:any) => any):Promise; + + /** + * Pass a handler that will be called regardless of this promise's fate. Returns a new promise chained from this promise. There are special semantics for `.finally()` in that the final value cannot be modified from the handler. + * + * Alias `.lastly();` for compatibility with earlier ECMAScript version. + */ + finally(handler:(value:any) => any):Promise; + lastly(handler:(value:any) => any):Promise; + + /** + * Create a promise that follows this promise, but is bound to the given `thisArg` value. A bound promise will call its handlers with the bound value set to `this`. Additionally promises derived from a bound promise will also be bound promises with the same `thisArg` binding as the original promise. + */ + bind(thisArg:any):Promise; + + /** + * Like `.then()`, but any unhandled rejection that ends up here will be thrown as an error. + */ + done(fulfilledHandler?:(value:any) => any, rejectedHandler?:(reason:any) => any, progressHandler?:(note:any) => any):Promise; + + /** + * Shorthand for `.then(null, null, handler);`. Attach a progress handler that will be called if this promise is progressed. Returns a new promise chained from this promise. + */ + progressed(handler:(note:any) => any):Promise; + + /** + * Same as calling `Promise.delay(this, ms)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + delay(ms:number):Promise; + + /** + * Returns a promise that will be fulfilled with this promise's fulfillment value or rejection reason. However, if this promise is not fulfilled or rejected within `ms` milliseconds, the returned promise is rejected with a `Promise.TimeoutError` instance. + * + * You may specify a custom error message with the `message` parameter. + */ + + timeout(ms:number, message?:string):Promise; + + /** + * Register a node-style callback on this promise. When this promise is is either fulfilled or rejected, the node callback will be called back with the node.js convention where error reason is the first argument and success value is the second argument. The error argument will be `null` in case of success. + * Returns back this promise instead of creating a new one. If the `callback` argument is not a function, this method does not do anything. + */ + nodeify(callback?:Function):Promise; + + /** + * Marks this promise as cancellable. Promises by default are not cancellable after v0.11 and must be marked as such for `.cancel()` to have any effect. Marking a promise as cancellable is infectious and you don't need to remark any descendant promise. + */ + cancellable():Promise; + + /** + * Cancel this promise. The cancellation will propagate to farthest cancellable ancestor promise which is still pending. + * + * That ancestor will then be rejected with a `CancellationError` (get a reference from `Promise.CancellationError`) object as the rejection reason. + * + * In a promise rejection handler you may check for a cancellation by seeing if the reason object has `.name === "Cancel"`. + * + * Promises are by default not cancellable. Use `.cancellable()` to mark a promise as cancellable. + */ + cancel():Promise; + + /** + * Like `.then()`, but cancellation of the the returned promise or any of its descendant will not propagate cancellation to this promise or this promise's ancestors. + */ + fork(fulfilledHandler?:(value:any) => any, rejectedHandler?:(reason:any) => any, progressHandler?:(note:any) => any):Promise; + + /** + * Create an uncancellable promise based on this promise. + */ + uncancellable():Promise; + + /** + * See if this promise can be cancelled. + */ + isCancellable():boolean; + + /** + * See if this `promise` has been fulfilled. + */ + isFulfilled():boolean; + + /** + * See if this `promise` has been rejected. + */ + isRejected():boolean; + + /** + * See if this `promise` is still defer. + */ + isPending():boolean; + + /** + * See if this `promise` is resolved -> either fulfilled or rejected. + */ + isResolved():boolean; + + /** + * Synchronously inspect the state of this `promise`. The `PromiseInspection` will represent the state of the promise as snapshotted at the time of calling `.inspect()`. + */ + inspect():PromiseInspection; + + /** + * This is a convenience method for doing: + * + * + * promise.then(function(obj){ + * return obj[propertyName].call(obj, arg...); + * }); + * + */ + call(propertyName:string, ...args:any[]):Promise; + + /** + * This is a convenience method for doing: + * + * + * promise.then(function(obj){ + * return obj[propertyName]; + * }); + * + */ + get(propertyName:string):Promise; + + /** + * Convenience method for: + * + * + * .then(function() { + * return value; + * }); + * + * + * in the case where `value` doesn't change its value. That means `value` is bound at the time of calling `.return()` + * + * Alias `.thenReturn();` for compatibility with earlier ECMAScript version. + */ + return(value:any):Promise; + thenReturn():Promise; + + /** + * Convenience method for: + * + * + * .then(function() { + * throw reason; + * }); + * + * Same limitations apply as with `.return()`. + * + * Alias `.thenThrow();` for compatibility with earlier ECMAScript version. + */ + throw(reason:any):Promise; + thenThrow():Promise; + + /** + * Convert to String. + */ + toString():string; + + /** + * This is implicitly called by `JSON.stringify` when serializing the object. Returns a serialized representation of the `Promise`. + */ + toJSON():Object; + + /** + * Same as calling `Promise.all(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + all():Promise; + + /** + * Same as calling `Promise.props(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + props():Promise; + + /** + * Same as calling `Promise.settle(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + settle():Promise; + + /** + * Same as calling `Promise.any(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + any():Promise; + + /** + * Same as calling `Promise.race(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + some(count:number):Promise; + + /** + * Same as calling `Promise.some(thisPromise, count)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + race():Promise; + + /** + * Like calling `.then`, but the fulfillment value or rejection reason is assumed to be an array, which is flattened to the formal parameters of the handlers. + */ + spread(fulfilledHandler?:(value:any) => any, rejectedHandler?:(reason:any) => any):Promise; + + /** + * Same as calling `Promise.map(thisPromise, mapper)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + map(mapper:(item:any, index:number, arrayLength:number) => any):Promise; + + /** + * Same as calling `Promise.reduce(thisPromise, Function reducer, initialValue)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + reduce(reducer:(total:number, current:any, index:number, arrayLength:number) => any, initialValue?:any):Promise; + + /** + * Same as calling ``Promise.filter(thisPromise, filterer)``. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. + */ + filter(filterer:(item:any, index:number, arrayLength:number) => any):Promise; + } + + interface PromiseResolver { + /** + * Resolve the underlying promise with `value` as the resolution value. If `value` is a thenable or a promise, the underlying promise will assume its state. + */ + resolve(value:any):void; + + /** + * Reject the underlying promise with `reason` as the rejection reason. + */ + reject(reason:any):void; + + /** + * Progress the underlying promise with `value` as the progression value. + */ + progress(value:any):void; + + /** + * Gives you a callback representation of the `PromiseResolver`. Note that this is not a method but a property. The callback accepts error object in first argument and success values on the 2nd parameter and the rest, I.E. node js conventions. + * + * If the the callback is called with multiple success values, the resolver fullfills its promise with an array of the values. + */ + callback:Function; + } + + interface PromiseInspection { + /** + * See if the underlying promise was fulfilled at the creation time of this inspection object. + */ + isFulfilled():boolean; + + /** + * See if the underlying promise was rejected at the creation time of this inspection object. + */ + isRejected():boolean; + + /** + * See if the underlying promise was defer at the creation time of this inspection object. + */ + isPending():boolean; + + /** + * Get the fulfillment value of the underlying promise. Throws if the promise wasn't fulfilled at the creation time of this inspection object. + * + * throws `TypeError` + */ + value():any; + + /** + * Get the rejection reason for the underlying promise. Throws if the promise wasn't rejected at the creation time of this inspection object. + * + * throws `TypeError` + */ + error():any; + } + + interface PromiseStatic { + /** + * Create a new promise. The passed in function will receive functions `resolve` and `reject` as its arguments which can be called to seal the fate of the created promise. + */ + new(resolver:(resolve:(value:any) => void, reject:(reason:any) => any) => void):Promise; + + /** + * Start the chain of promises with `Promise.try`. Any synchronous exceptions will be turned into rejections on the returned promise. + * + * Note about second argument: if it's specifically a true array, its values become respective arguments for the function call. Otherwise it is passed as is as the first argument for the function call. + * + * Alias for `attempt();` for compatibility with earlier ECMAScript version. + */ + try(fn:() => any, args?:any[], ctx?:any):Promise; + try(fn:() => any, args?:ArrayLike, ctx?:any):Promise; + attempt(fn:() => any, args?:any[], ctx?:any):Promise; + attempt(fn:() => any, args?:ArrayLike, ctx?:any):Promise; + + /** + * Returns a new function that wraps the given function `fn`. The new function will always return a promise that is fulfilled with the original functions return values or rejected with thrown exceptions from the original function. + * This method is convenient when a function can sometimes return synchronously or throw synchronously. + */ + method(fn:Function):Function; + + /** + * Create a promise that is resolved with the given `value`. If `value` is a thenable or promise, the returned promise will assume its state. + */ + resolve(value:any):Promise; + + /** + * Create a promise that is rejected with the given `reason`. + */ + reject(reason:any):Promise; + + /** + * Create a promise with undecided fate and return a `PromiseResolver` to control it. See resolution?:Promise(#promise-resolution). + */ + defer():PromiseResolver; + + /** + * Cast the given `value` to a trusted promise. If `value` is already a trusted `Promise`, it is returned as is. If `value` is not a thenable, a fulfilled is:Promise returned with `value` as its fulfillment value. If `value` is a thenable (Promise-like object, like those returned by jQuery's `$.ajax`), returns a trusted that:Promise assimilates the state of the thenable. + */ + cast(value:any):Promise; + + /** + * Sugar for `Promise.resolve(undefined).bind(thisArg);`. See `.bind()`. + */ + bind(thisArg:any):Promise; + + /** + * See if `value` is a trusted Promise. + */ + is(value:any):boolean; + + /** + * Call this right after the library is loaded to enabled long stack traces. Long stack traces cannot be disabled after being enabled, and cannot be enabled after promises have alread been created. Long stack traces imply a substantial performance penalty, around 4-5x for throughput and 0.5x for latency. + */ + longStackTraces():void; + + /** + * Returns a promise that will be fulfilled with `value` (or `undefined`) after given `ms` milliseconds. If `value` is a promise, the delay will start counting down when it is fulfilled and the returned promise will be fulfilled with the fulfillment value of the `value` promise. + */ + delay(value:Promise, ms:number):Promise; + delay(value:any, ms:number):Promise; + delay(ms:number):Promise; + + /** + * Returns a function that will wrap the given `nodeFunction`. Instead of taking a callback, the returned function will return a promise whose fate is decided by the callback behavior of the given node function. The node function should conform to node.js convention of accepting a callback as last argument and calling that callback with error as the first argument and success value on the second argument. + * + * If the `nodeFunction` calls its callback with multiple success values, the fulfillment value will be an array of them. + * + * If you pass a `receiver`, the `nodeFunction` will be called as a method on the `receiver`. + */ + promisify(nodeFunction:Function, receiver?:any):Function; + + /** + * This overload has been **deprecated**. The overload will continue working for now. The recommended method for promisifying multiple methods at once is ``Promise.promisifyAll(Object target)`` + */ + promisify(target:Object):Object; + + /** + * Promisifies the entire object by going through the object's properties and creating an async equivalent of each function on the object and its prototype chain. The promisified method name will be the original method name postfixed with `Async`. Returns the input object. + * + * Note that the original methods on the object are not overwritten but new methods are created with the `Async`-postfix. For example, if you `promisifyAll()` the node.js `fs` object use `fs.statAsync()` to call the promisified `stat` method. + */ + promisifyAll(target:Object):Object; + + /** + * Returns a function that can use `yield` to run asynchronous code synchronously. This feature requires the support of generators which are drafted in the next version of the language. Node version greater than `0.11.2` is required and needs to be executed with the `--harmony-generators` (or `--harmony`) command-line switch. + */ + coroutine(generatorFunction:Function):Function; + + /** + * Spawn a coroutine which may yield promises to run asynchronous code synchronously. This feature requires the support of generators which are drafted in the next version of the language. Node version greater than `0.11.2` is required and needs to be executed with the `--harmony-generators` (or `--harmony`) command-line switch. + */ + spawn(generatorFunction:Function):Promise; + + /** + * This is relevant to browser environments with no module loader. + * + * Release control of the `Promise` namespace to whatever it was before this library was loaded. Returns a reference to the library namespace so you can attach it to something else. + */ + noConflict():Object; + + /** + * Add `handler` as the handler to call when there is a possibly unhandled rejection. The default handler logs the error stack to stderr or `console.error` in browsers. + * + * Passing no value or a non-function will have the effect of removing any kind of handling for possibly unhandled rejections. + */ + onPossiblyUnhandledRejection(handler:(reason:any) => any):void; + + /** + * Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled when all the items in the array are fulfilled. The promise's fulfillment value is an array with fulfillment values at respective positions to the original array. If any promise in the array rejects, the returned promise is rejected with the rejection reason. + */ + all(values:any[]):Promise; + + /** + * Like ``Promise.all`` but for object properties instead of array items. Returns a promise that is fulfilled when all the properties of the object are fulfilled. The promise's fulfillment value is an object with fulfillment values at respective keys to the original object. If any promise in the object rejects, the returned promise is rejected with the rejection reason. + * + * If `object` is a trusted `Promise`, then it will be treated as a promise for object rather than for its properties. All other objects are treated for their properties as is returned by `Object.keys` - the object's own enumerable properties. + * + * *The original object is not modified.* + */ + props(object:Promise):Promise; + props(object:Object):Promise; + + /** + * Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled when all the items in the array are either fulfilled or rejected. The fulfillment value is an array of ``PromiseInspection`` instances at respective positions in relation to the input array. + * + * *original:The array is not modified. The input array sparsity is retained in the resulting array.* + */ + settle(values:any[]):Promise; + + /** + * Like `Promise.some()`, with 1 as `count`. However, if the promise fulfills, the fulfillment value is not an array of 1 but the value directly. + */ + any(values:any[]):Promise; + + /** + * Given an array, or a promise of an array, which contains promises (or a mix of promises and values) return a promise that is fulfilled or rejected as soon as a promise in the array is fulfilled or rejected with the respective rejection reason or fulfillment value. + * + * **Note** If you pass empty array or a sparse array with no values, or a promise/thenable for such, it will be forever pending. + */ + race(values:any[]):Promise; + + /** + * Initiate a competetive race between multiple promises or values (values will become immediately fulfilled promises). When `count` amount of promises have been fulfilled, the returned promise is fulfilled with an array that contains the fulfillment values of the winners in order of resolution. + * + * If too many promises are rejected so that the promise can never become fulfilled, it will be immediately rejected with an array of rejection reasons in the order they were thrown in. + * + * *The original array is not modified.* + */ + some(values:any[], count:number):Promise; + + /** + * Like `Promise.all()` but instead of having to pass an array, the array is generated from the passed variadic arguments. + */ + join(...values:any[]):Promise; + + /** + * Map an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `mapper` function with the signature `(item, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well. + * + * If the `mapper` function returns promises or thenables, the returned promise will wait for all the mapped results to be resolved as well. + * + * *The original array is not modified.* + */ + map(values:any[], mapper:(item:any, index:number, arrayLength:number) => any):Promise; + + /** + * Reduce an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `reducer` function with the signature `(total, current, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well. + * + * If the reducer function returns a promise or a thenable, the result for the promise is awaited for before continuing with next iteration. + * + * *The original array is not modified. If no `intialValue` is given and the array doesn't contain at least 2 items, the callback will not be called and `undefined` is returned. If `initialValue` is given and the array doesn't have at least 1 item, `initialValue` is returned.* + */ + reduce(values:any[], reducer:(total:number, current:any, index:number, arrayLength:number) => any, initialValue?:any):Promise; + + /** + * Filter an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given `filterer` function with the signature `(item, index, arrayLength)` where `item` is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well. + * + * The return values from the filtered functions are coerced to booleans, with the exception of promises and thenables which are awaited for their eventual result. + * + * *The original array is not modified. + */ + filter(values:any[], filterer:(item:any, index?:number, arrayLength?:number) => any):Promise; + } +} diff --git a/createjs/createjs.d.ts b/createjs/createjs.d.ts index 20f2a7574..3ebfd11bf 100644 --- a/createjs/createjs.d.ts +++ b/createjs/createjs.d.ts @@ -1,6 +1,6 @@ -// Type definitions for EaselJS 0.7.0, TweenJS 0.5.0, SoundJS 0.5.0, PreloadJS 0.4.0 +// Type definitions for EaselJS 0.7.1, TweenJS 0.5.1, SoundJS 0.5.2, PreloadJS 0.4.1 // Project: http://www.createjs.com/#!/EaselJS -// Definitions by: Pedro Ferreira +// Definitions by: Pedro Ferreira , Chris Smith , Satoru Kimura // Definitions: https://github.com/borisyankov/DefinitelyTyped /* @@ -23,13 +23,13 @@ declare module createjs { // properties bubbles: boolean; cancelable: boolean; - currentTarget: Object; + currentTarget: any; // It is 'Object' type officially, but 'any' is easier to use. defaultPrevented: boolean; eventPhase: number; immediatePropagationStopped: boolean; propagationStopped: boolean; removed: boolean; - target: Object; + target: any; // It is 'Object' type officially, but 'any' is easier to use. timeStamp: number; type: string; @@ -38,15 +38,15 @@ declare module createjs { delta: number; error: string; id: string; - item: any; - loaded: number; + item: any; + loaded: number; name: string; next: string; - params: any[]; + params: any; paused: boolean; progress: number; - rawResult: Object; - result: Object; + rawResult: any; + result: any; runTime: number; src: string; time: number; @@ -78,16 +78,19 @@ declare module createjs { off(type: string, listener: (eventObj: Object) => void, useCapture?: boolean): void; off(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, useCapture?: boolean): void; off(type: string, listener: { handleEvent: (eventObj: Object) => void; }, useCapture?: boolean): void; - on(type: string, listener: (eventObj: Object) => boolean, useCapture?: boolean): Function; - on(type: string, listener: (eventObj: Object) => void, useCapture?: boolean): Function; - on(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, useCapture?: boolean): Object; - on(type: string, listener: { handleEvent: (eventObj: Object) => void; }, useCapture?: boolean): Object; + off(type: string, listener: Function, useCapture?: boolean): void; // It is necessary for "arguments.callee" + on(type: string, listener: (eventObj: Object) => boolean, scope?: Object, once?: boolean, data?: any, useCapture?: boolean): Function; + on(type: string, listener: (eventObj: Object) => void, scope?: Object, once?: boolean, data?: any, useCapture?: boolean): Function; + on(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, scope?: Object, once?: boolean, data?: any, useCapture?: boolean): Object; + on(type: string, listener: { handleEvent: (eventObj: Object) => void; }, scope?: Object, once?: boolean, data?: any, useCapture?: boolean): Object; removeAllEventListeners(type?: string): void; removeEventListener(type: string, listener: (eventObj: Object) => boolean, useCapture?: boolean): void; removeEventListener(type: string, listener: (eventObj: Object) => void, useCapture?: boolean): void; removeEventListener(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, useCapture?: boolean): void; removeEventListener(type: string, listener: { handleEvent: (eventObj: Object) => void; }, useCapture?: boolean): void; + removeEventListener(type: string, listener: Function, useCapture?: boolean): void; // It is necessary for "arguments.callee" toString(): string; + willTrigger(type: string): boolean; } export function indexOf(array: any[], searchElement: Object): number; diff --git a/d3/d3.d.ts b/d3/d3.d.ts index 126f2d95b..fe8887b7e 100644 --- a/d3/d3.d.ts +++ b/d3/d3.d.ts @@ -88,42 +88,78 @@ declare module D3 { * @param arr Array to search * @param map Accsessor function */ - min(arr: T[], map?: (v: T) => U): U; + min(arr: T[], map: (v: T) => U): U; + /** + * Find the minimum value in an array + * + * @param arr Array to search + */ + min(arr: T[]): T; /** * Find the maximum value in an array * * @param arr Array to search * @param map Accsessor function */ - max(arr: T[], map?: (v: T) => U): U; + max(arr: T[], map: (v: T) => U): U; + /** + * Find the maximum value in an array + * + * @param arr Array to search + */ + max(arr: T[]): T; /** * Find the minimum and maximum value in an array * * @param arr Array to search * @param map Accsessor function */ - extent(arr: T[], map?: (v: T) => U): U[]; + extent(arr: T[], map: (v: T) => U): U[]; + /** + * Find the minimum and maximum value in an array + * + * @param arr Array to search + */ + extent(arr: T[]): T[]; /** * Compute the sum of an array of numbers * * @param arr Array to search * @param map Accsessor function */ - sum(arr: T[], map?: (v: T) => number): number; + sum(arr: T[], map: (v: T) => number): number; + /** + * Compute the sum of an array of numbers + * + * @param arr Array to search + */ + sum(arr: number[]): number; /** * Compute the arithmetic mean of an array of numbers * * @param arr Array to search * @param map Accsessor function */ - mean(arr: T[], map?: (v: T) => number): number; + mean(arr: T[], map: (v: T) => number): number; + /** + * Compute the arithmetic mean of an array of numbers + * + * @param arr Array to search + */ + mean(arr: number[]): number; /** * Compute the median of an array of numbers (the 0.5-quantile). * * @param arr Array to search * @param map Accsessor function */ - median(arr: T[], map?: (v: T) => number): number; + median(arr: T[], map: (v: T) => number): number; + /** + * Compute the median of an array of numbers (the 0.5-quantile). + * + * @param arr Array to search + */ + median(arr: number[]): number; /** * Compute a quantile for a sorted array of numbers. * @@ -135,7 +171,7 @@ declare module D3 { * Locate the insertion point for x in array to maintain sorted order * * @param arr Array to search - * @param x Value to serch for insertion point + * @param x Value to search for insertion point * @param low Minimum value of array subset * @param hihg Maximum value of array subset */ diff --git a/easeljs/easeljs-tests.ts b/easeljs/easeljs-tests.ts index 6c083da5c..ff68b79d6 100644 --- a/easeljs/easeljs-tests.ts +++ b/easeljs/easeljs-tests.ts @@ -53,4 +53,16 @@ function test_graphics() { var myGraphics: createjs.Graphics; myGraphics.beginStroke("#F00").beginFill("#00F").drawRect(20, 20, 100, 50).draw(myContext2D); +} + +function colorMatrixTest() { + var shape = new createjs.Shape().set({ x: 100, y: 100 }); + shape.graphics.beginFill("#ff0000").drawCircle(0, 0, 50); + + var matrix = new createjs.ColorMatrix().adjustHue(180).adjustSaturation(100); + shape.filters = [ + new createjs.ColorMatrixFilter(matrix) + ]; + + shape.cache(-50, -50, 100, 100); } \ No newline at end of file diff --git a/easeljs/easeljs.d.ts b/easeljs/easeljs.d.ts index dd1563083..2c5be3aa3 100644 --- a/easeljs/easeljs.d.ts +++ b/easeljs/easeljs.d.ts @@ -1,4 +1,4 @@ -// Type definitions for EaselJS 0.7.0 +// Type definitions for EaselJS 0.7.1 // Project: http://www.createjs.com/#!/EaselJS // Definitions by: Pedro Ferreira , Chris Smith // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -55,6 +55,8 @@ declare module createjs { // methods clone(): Bitmap; + set(props: Object): Bitmap; + setTransform(x?: number, y?: number, scaleX?: number, scaleY?: number, rotation?: number, skewX?: number, skewY?: number, regX?: number, regY?: number): Bitmap; } /** @@ -73,6 +75,9 @@ declare module createjs { spriteSheet: SpriteSheet; text: string; + // methods + set(props: Object): BitmapText; + setTransform(x?: number, y?: number, scaleX?: number, scaleY?: number, rotation?: number, skewX?: number, skewY?: number, regX?: number, regY?: number): BitmapText; } export class BlurFilter extends Filter { @@ -120,12 +125,8 @@ declare module createjs { clone(): ColorFilter; } - export class ColorMatrix implements Array { - constructor(brightness: number, contrast: number, saturation: number, hue: number); - - static DELTA_INDEX: number[]; - static IDENTITY_MATRIX: number[]; - static LENGTH: number; + export class ColorMatrix { + constructor(brightness?: number, contrast?: number, saturation?: number, hue?: number); // methods adjustBrightness(value: number): ColorMatrix; @@ -135,41 +136,17 @@ declare module createjs { adjustSaturation(value: number): ColorMatrix; clone(): ColorMatrix; concat(...matrix: number[]): ColorMatrix; - copyMatrix(...matrix: ColorMatrix[]): ColorMatrix; + concat(matrix: ColorMatrix): ColorMatrix; + copyMatrix(...matrix: number[]): ColorMatrix; + copyMatrix(matrix: ColorMatrix): ColorMatrix; reset(): ColorMatrix; toArray(): number[]; - - // implements Array interface start - concat(...items: ColorMatrix[]): number[]; - join(separator?: string): string; - pop(): number; - push(...items: number[]): number; - reverse(): number[]; - shift(): number; - slice(start: number, end?: number): number[]; - sort(compareFn?: (a: number, b: number) => number): number[]; - splice(start: number): number[]; - unshift(...items: number[]): number; - indexOf(searchElement: number, fromIndex?: number): number; - - lastIndexOf(searchElement: number, fromIndex?: number): number; - every(callbackfn: (value: number, index: number, array: number[]) => boolean, thisArg?: any): boolean; - some(callbackfn: (value: number, index: number, array: number[]) => boolean, thisArg?: any): boolean; - forEach(callbackfn: (value: number, index: number, array: number[]) => void, thisArg?: any): void; - map(callbackfn: (value: number, index: number, array: number[]) => ColorMatrix, thisArg?: any): ColorMatrix[]; - - filter(callbackfn: (value: number, index: number, array: number[]) => boolean, thisArg?: any): number[]; - reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue?: number): number; - reduce(callbackfn: (previousValue: ColorMatrix, currentValue: number, currentIndex: number, array: number[]) => ColorMatrix, initialValue: ColorMatrix): ColorMatrix; - reduceRight(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue?: number): number; - reduceRight(callbackfn: (previousValue: ColorMatrix, currentValue: number, currentIndex: number, array: number[]) => ColorMatrix, initialValue: ColorMatrix): ColorMatrix; - length: number; - [n: number]: number; - // implements Array interface end + toString(): string; } export class ColorMatrixFilter extends Filter { constructor(matrix: number[]); + constructor(matrix: ColorMatrix); // methods clone(): ColorMatrixFilter; @@ -177,7 +154,7 @@ declare module createjs { export class Command { // methods - constructor(f: any, params: any, path: any); + constructor(f: any, params: any, path?: any); exec(scope: any): void; } @@ -187,6 +164,7 @@ declare module createjs { // properties children: DisplayObject[]; mouseChildren: boolean; + tickChildren: boolean; // methods addChild(...child: DisplayObject[]): DisplayObject; @@ -203,7 +181,9 @@ declare module createjs { removeAllChildren(): void; removeChild(...child: DisplayObject[]): boolean; removeChildAt(...index: number[]): boolean; + set(props: Object): Container; setChildIndex(child: DisplayObject, index: number): void; + setTransform(x?: number, y?: number, scaleX?: number, scaleY?: number, rotation?: number, skewX?: number, skewY?: number, regX?: number, regY?: number): Container; sortChildren(sortFunction: (a: DisplayObject, b: DisplayObject) => number): void; swapChildren(child1: DisplayObject, child2: DisplayObject): void; swapChildrenAt(index1: number, index2: number): void; @@ -214,7 +194,7 @@ declare module createjs { // properties alpha: number; - cacheCanvas: HTMLCanvasElement; // HTMLCanvasElement or Object + cacheCanvas: any; // HTMLCanvasElement or Object cacheID: number; compositeOperation: string; cursor: string; @@ -238,6 +218,7 @@ declare module createjs { */ snapToPixel: boolean; static suppressCrossDomainErrors: boolean; + tickEnabled: boolean; visible: boolean; x: number; y: number; @@ -274,7 +255,8 @@ declare module createjs { // methods clone(): DisplayObject; // throw error - + set(props: Object): DOMElement; + setTransform(x?: number, y?: number, scaleX?: number, scaleY?: number, rotation?: number, skewX?: number, skewY?: number, regX?: number, regY?: number): DOMElement; } @@ -425,6 +407,8 @@ declare module createjs { constructor(type: string, bubbles: boolean, cancelable: boolean, stageX: number, stageY: number, nativeEvent: NativeMouseEvent, pointerID: number, primary: boolean, rawX: number, rawY: number); // properties + localX: number; + localY: number; nativeEvent: NativeMouseEvent; pointerID: number; primary: boolean; @@ -432,7 +416,6 @@ declare module createjs { rawY: number; stageX: number; stageY: number; - target: DisplayObject; // methods clone(): MouseEvent; @@ -442,23 +425,27 @@ declare module createjs { addEventListener(type: string, listener: (eventObj: Object) => void, useCapture?: boolean): Function; addEventListener(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, useCapture?: boolean): Object; addEventListener(type: string, listener: { handleEvent: (eventObj: Object) => void; }, useCapture?: boolean): Object; - on(type: string, listener: (eventObj: Object) => boolean, useCapture?: boolean): Function; - on(type: string, listener: (eventObj: Object) => void, useCapture?: boolean): Function; - on(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, useCapture?: boolean): Object; - on(type: string, listener: { handleEvent: (eventObj: Object) => void; }, useCapture?: boolean): Object; - removeEventListener(type: string, listener: (eventObj: Object) => boolean, useCapture?: boolean): void; - removeEventListener(type: string, listener: (eventObj: Object) => void, useCapture?: boolean): void; - removeEventListener(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, useCapture?: boolean): void; - removeEventListener(type: string, listener: { handleEvent: (eventObj: Object) => void; }, useCapture?: boolean): void; + dispatchEvent(eventObj: Object, target?: Object): boolean; + dispatchEvent(eventObj: string, target?: Object): boolean; + dispatchEvent(eventObj: Event, target?: Object): boolean; + hasEventListener(type: string): boolean; off(type: string, listener: (eventObj: Object) => boolean, useCapture?: boolean): void; off(type: string, listener: (eventObj: Object) => void, useCapture?: boolean): void; off(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, useCapture?: boolean): void; off(type: string, listener: { handleEvent: (eventObj: Object) => void; }, useCapture?: boolean): void; + off(type: string, listener: Function, useCapture?: boolean): void; // It is necessary for "arguments.callee" + on(type: string, listener: (eventObj: Object) => boolean, scope?: Object, once?: boolean, data?: any, useCapture?: boolean): Function; + on(type: string, listener: (eventObj: Object) => void, scope?: Object, once?: boolean, data?: any, useCapture?: boolean): Function; + on(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, scope?: Object, once?: boolean, data?: any, useCapture?: boolean): Object; + on(type: string, listener: { handleEvent: (eventObj: Object) => void; }, scope?: Object, once?: boolean, data?: any, useCapture?: boolean): Object; removeAllEventListeners(type?: string): void; - dispatchEvent(eventObj: string, target?: Object): boolean; - dispatchEvent(eventObj: Object, target?: Object): boolean; - dispatchEvent(eventObj: Event, target?: Object): boolean; - hasEventListener(type: string): boolean; + removeEventListener(type: string, listener: (eventObj: Object) => boolean, useCapture?: boolean): void; + removeEventListener(type: string, listener: (eventObj: Object) => void, useCapture?: boolean): void; + removeEventListener(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, useCapture?: boolean): void; + removeEventListener(type: string, listener: { handleEvent: (eventObj: Object) => void; }, useCapture?: boolean): void; + removeEventListener(type: string, listener: Function, useCapture?: boolean): void; // It is necessary for "arguments.callee" + toString(): string; + willTrigger(type: string): boolean; } @@ -555,6 +542,8 @@ declare module createjs { // methods clone(recursive?: boolean): Shape; + set(props: Object): Shape; + setTransform(x?: number, y?: number, scaleX?: number, scaleY?: number, rotation?: number, skewX?: number, skewY?: number, regX?: number, regY?: number): Shape; } @@ -583,6 +572,8 @@ declare module createjs { gotoAndStop(frameOrAnimation: string): void; gotoAndStop(frameOrAnimation: number): void; play(): void; + set(props: Object): Sprite; + setTransform(x?: number, y?: number, scaleX?: number, scaleY?: number, rotation?: number, skewX?: number, skewY?: number, regX?: number, regY?: number): Sprite; stop(): void; } @@ -619,6 +610,8 @@ declare module createjs { export class SpriteSheetBuilder extends EventDispatcher { + constructor(); + // properties maxHeight: number; maxWidth: number; @@ -634,9 +627,9 @@ declare module createjs { addMovieClip(source: MovieClip, sourceRect?: Rectangle, scale?: number): void; build(): SpriteSheet; buildAsync(timeSlice?: number): void; - clone(): DisplayObject; // throw error + clone(): void; // throw error stopAsync(): void; - toString(): string; + } @@ -660,7 +653,8 @@ declare module createjs { // properties autoClear: boolean; - canvas: HTMLCanvasElement; + canvas: any; // HTMLCanvasElement or Object + handleEvent: Function; mouseInBounds: boolean; mouseMoveOutside: boolean; mouseX: number; @@ -677,7 +671,6 @@ declare module createjs { clone(): Stage; enableDOMEvents(enable?: boolean): void; enableMouseOver(frequency?: number): void; - handleEvent(evt: Object): void; toDataURL(backgroundColor: string, mimeType: string): string; update(...arg: any[]): void; @@ -703,6 +696,8 @@ declare module createjs { getMeasuredHeight(): number; getMeasuredLineHeight(): number; getMeasuredWidth(): number; + set(props: Object): Text; + setTransform(x?: number, y?: number, scaleX?: number, scaleY?: number, rotation?: number, skewX?: number, skewY?: number, regX?: number, regY?: number): Text; } export class Ticker { @@ -731,7 +726,6 @@ declare module createjs { static setFPS(value: number): void; static setInterval(interval: number): void; static setPaused(value: boolean): void; - static toString(): string; // EventDispatcher mixins static addEventListener(type: string, listener: (eventObj: Object) => boolean, useCapture?: boolean): Function; @@ -746,16 +740,19 @@ declare module createjs { static off(type: string, listener: (eventObj: Object) => void, useCapture?: boolean): void; static off(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, useCapture?: boolean): void; static off(type: string, listener: { handleEvent: (eventObj: Object) => void; }, useCapture?: boolean): void; - static on(type: string, listener: (eventObj: Object) => boolean, useCapture?: boolean): Function; - static on(type: string, listener: (eventObj: Object) => void, useCapture?: boolean): Function; - static on(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, useCapture?: boolean): Object; - static on(type: string, listener: { handleEvent: (eventObj: Object) => void; }, useCapture?: boolean): Object; + static off(type: string, listener: Function, useCapture?: boolean): void; // It is necessary for "arguments.callee" + static on(type: string, listener: (eventObj: Object) => boolean, scope?: Object, once?: boolean, data?: any, useCapture?: boolean): Function; + static on(type: string, listener: (eventObj: Object) => void, scope?: Object, once?: boolean, data?: any, useCapture?: boolean): Function; + static on(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, scope?: Object, once?: boolean, data?: any, useCapture?: boolean): Object; + static on(type: string, listener: { handleEvent: (eventObj: Object) => void; }, scope?: Object, once?: boolean, data?: any, useCapture?: boolean): Object; static removeAllEventListeners(type?: string): void; static removeEventListener(type: string, listener: (eventObj: Object) => boolean, useCapture?: boolean): void; static removeEventListener(type: string, listener: (eventObj: Object) => void, useCapture?: boolean): void; static removeEventListener(type: string, listener: { handleEvent: (eventObj: Object) => boolean; }, useCapture?: boolean): void; static removeEventListener(type: string, listener: { handleEvent: (eventObj: Object) => void; }, useCapture?: boolean): void; - + static removeEventListener(type: string, listener: Function, useCapture?: boolean): void; // It is necessary for "arguments.callee" + static toString(): string; + static willTrigger(type: string): boolean; } export class TickerEvent { diff --git a/es6-promises/es6-promises-tests.ts b/es6-promises/es6-promises-tests.ts new file mode 100644 index 000000000..774d3763e --- /dev/null +++ b/es6-promises/es6-promises-tests.ts @@ -0,0 +1,162 @@ +/// + + +var promiseString: Promise, + promiseStringArr: Promise, + arrayOfPromise: Promise[], + promiseNumber: Promise, + promiseAny: Promise, + thenable: Thenable; + +// constructor test +var constructResult = new Promise((resolve, reject) => { + resolve('a string'); +}); +promiseString = constructResult; + + +var constructResult1 = new Promise((resolve:(promise: Thenable) => void) => { + resolve(Promise.resolve('a string')); +}); +promiseString = constructResult1; + +//cast test +var castResult = Promise.cast('a string'); +promiseString = castResult; +var castResult1 = Promise.cast(Promise.resolve('a string')); +promiseString = castResult1; + +//resolve test +var resolveResult = Promise.resolve('a string'); +promiseString = resolveResult; + +var resolveResult1 = Promise.resolve(thenable); +promiseString = resolveResult1; + +//reject test +var rejectResult = Promise.reject('there is an error'); +promiseAny = rejectResult; + +//all test +var allResult = Promise.all(arrayOfPromise); +promiseStringArr = allResult; + +//race test +var raceResult = Promise.race(arrayOfPromise); +promiseString = raceResult; + + +//then test +var thenWithPromiseResult = promiseString.then(word => Promise.resolve(word.length)); +promiseNumber = thenWithPromiseResult; + +var thenWithPromiseResultAndPromiseReject = promiseString.then(word => Promise.resolve(word.length), error => Promise.resolve(10)); +promiseNumber = thenWithPromiseResultAndPromiseReject; + +var thenWithPromiseResultAndSimpleReject = promiseString.then(word => Promise.resolve(word.length), error => 10); +promiseNumber = thenWithPromiseResultAndSimpleReject; + +var thenWithSimpleResult = promiseString.then(word => word.length); +promiseNumber = thenWithSimpleResult; + +var thenWithSimpleResultAndPromiseReject = promiseString.then(word => word.length, error => Promise.resolve(10)); +promiseNumber = thenWithSimpleResultAndPromiseReject; + +var thenWithSimpleResultAndSimpleReject = promiseString.then(word => word.length, error => 10); +promiseNumber = thenWithSimpleResultAndSimpleReject; + +var thenWithUndefinedFullFillAndSimpleReject = promiseString.then(undefined, error => 10); +promiseNumber = thenWithUndefinedFullFillAndSimpleReject; + +var thenWithUndefinedFullFillAndPromiseReject = promiseString.then(undefined, error => Promise.resolve(10)); +promiseNumber = thenWithUndefinedFullFillAndPromiseReject; + +var thenWithNoResultAndNoReject = promiseString.then(); +promiseNumber = thenWithNoResultAndNoReject; + +//catch test +var catchWithSimpleResult = promiseString.catch(error => 10); +promiseNumber = catchWithSimpleResult; + +var catchWithPromiseResult = promiseString.catch(error => Promise.resolve(10)); +promiseNumber = catchWithPromiseResult; + + +//examples coming from http://www.html5rocks.com/en/tutorials/es6/promises/ + +function get(url: string) { + // Return a new promise. + return new Promise(function(resolve, reject) { + // Do the usual XHR stuff + var req = new XMLHttpRequest(); + req.open('GET', url); + + req.onload = function() { + // This is called even on 404 etc + // so check the status + if (req.status == 200) { + // Resolve the promise with the response text + resolve(req.response); + } + else { + // Otherwise reject with the status text + // which will hopefully be a meaningful error + reject(Error(req.statusText)); + } + }; + + // Handle network errors + req.onerror = function() { + reject(Error("Network Error")); + }; + + // Make the request + req.send(); + }); +} + + + +function getJSON(url: string) { + return get(url).then(JSON.parse); +} + +function addHtmlToPage(html: string) { + +} + +function addTextToPage(text: string) { + +} + +interface Story { + heading: string; + chapterUrls: string[] +} + +getJSON('story.json').then(function(story: Story) { + addHtmlToPage(story.heading); + + // Map our array of chapter urls to + // an array of chapter json promises. + // This makes sure they all download parallel. + return story.chapterUrls.map(getJSON) + .reduce(function(sequence, chapterPromise) { + // Use reduce to chain the promises together, + // adding content to the page for each chapter + return sequence.then(function() { + // Wait for everything in the sequence so far, + // then wait for this chapter to arrive. + return chapterPromise; + }).then(function(chapter) { + addHtmlToPage(chapter.html); + }); + }, Promise.resolve()); +}).then(function() { + addTextToPage("All done"); +}).catch(function(err) { + // catch any error that happened along the way + addTextToPage("Argh, broken: " + err.message); +}).then(function() { + (document.querySelector('.spinner')).style.display = 'none'; +}); diff --git a/es6-promises/es6-promises-tests.ts.tscparams b/es6-promises/es6-promises-tests.ts.tscparams new file mode 100644 index 000000000..3cc762b55 --- /dev/null +++ b/es6-promises/es6-promises-tests.ts.tscparams @@ -0,0 +1 @@ +"" \ No newline at end of file diff --git a/es6-promises/es6-promises.d.ts b/es6-promises/es6-promises.d.ts new file mode 100644 index 000000000..a44355233 --- /dev/null +++ b/es6-promises/es6-promises.d.ts @@ -0,0 +1,133 @@ +// Type definitions for es6-promises +// Project: https://github.com/jakearchibald/ES6-Promises +// Definitions by: François de Campredon +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +interface Thenable { + then(onFulfill: (value: R) => Thenable, onReject: (error: any) => Thenable): Thenable; + then(onFulfill: (value: R) => Thenable, onReject?: (error: any) => U): Thenable; + then(onFulfill: (value: R) => U, onReject: (error: any) => Thenable): Thenable; + then(onFulfill?: (value: R) => U, onReject?: (error: any) => U): Thenable; + +} + +declare class Promise implements Thenable { + /** + * If you call resolve in the body of the callback passed to the constructor, + * your promise is fulfilled with result object passed to resolve. + * If you call reject your promise is rejected with the object passed to resolve. + * For consistency and debugging (eg stack traces), obj should be an instanceof Error. + * Any errors thrown in the constructor callback will be implicitly passed to reject(). + */ + constructor(callback: (resolve : (result: R) => void, reject: (error: any) => void) => void); + /** + * If you call resolve in the body of the callback passed to the constructor, + * your promise will be fulfilled/rejected with the outcome of thenable passed to resolve. + * If you call reject your promise is rejected with the object passed to resolve. + * For consistency and debugging (eg stack traces), obj should be an instanceof Error. + * Any errors thrown in the constructor callback will be implicitly passed to reject(). + */ + constructor(callback: (resolve : (thenable: Thenable) => void, reject: (error: any) => void) => void); + + + /** + * onFulFill is called when/if "promise" resolves. onRejected is called when/if "promise" rejects. + * Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called. + * Both callbacks have a single parameter , the fulfillment value or rejection reason. + * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. + * If an error is thrown in the callback, the returned promise rejects with that error. + * + * @param onFulFill called when/if "promise" resolves + * @param onReject called when/if "promise" rejects + */ + then(onFulfill: (value: R) => Thenable, onReject: (error: any) => Thenable): Promise; + /** + * onFulFill is called when/if "promise" resolves. onRejected is called when/if "promise" rejects. + * Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called. + * Both callbacks have a single parameter , the fulfillment value or rejection reason. + * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. + * If an error is thrown in the callback, the returned promise rejects with that error. + * + * @param onFulFill called when/if "promise" resolves + * @param onReject called when/if "promise" rejects + */ + then(onFulfill: (value: R) => Thenable, onReject?: (error: any) => U): Promise; + /** + * onFulFill is called when/if "promise" resolves. onRejected is called when/if "promise" rejects. + * Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called. + * Both callbacks have a single parameter , the fulfillment value or rejection reason. + * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. + * If an error is thrown in the callback, the returned promise rejects with that error. + * + * @param onFulFill called when/if "promise" resolves + * @param onReject called when/if "promise" rejects + */ + then(onFulfill: (value: R) => U, onReject: (error: any) => Thenable): Promise; + /** + * onFulFill is called when/if "promise" resolves. onRejected is called when/if "promise" rejects. + * Both are optional, if either/both are omitted the next onFulfilled/onRejected in the chain is called. + * Both callbacks have a single parameter , the fulfillment value or rejection reason. + * "then" returns a new promise equivalent to the value you return from onFulfilled/onRejected after being passed through Promise.resolve. + * If an error is thrown in the callback, the returned promise rejects with that error. + * + * @param onFulFill called when/if "promise" resolves + * @param onReject called when/if "promise" rejects + */ + then(onFulfill?: (value: R) => U, onReject?: (error: any) => U): Promise; + + + /** + * Sugar for promise.then(undefined, onRejected) + * + * @param onReject called when/if "promise" rejects + */ + catch(onReject?: (error: any) => Thenable): Promise; + /** + * Sugar for promise.then(undefined, onRejected) + * + * @param onReject called when/if "promise" rejects + */ + catch(onReject?: (error: any) => U): Promise; +} + +declare module Promise { + + /** + * Returns promise (only if promise.constructor == Promise) + */ + function cast(promise: Promise): Promise; + /** + * Make a promise that fulfills to obj. + */ + function cast(object?: R): Promise; + + + /** + * Make a new promise from the thenable. + * A thenable is promise-like in as far as it has a "then" method. + * This also creates a new promise if you pass it a genuine JavaScript promise, making it less efficient for casting than Promise.cast. + */ + function resolve(thenable: Thenable): Promise; + /** + * Make a promise that fulfills to obj. Same as Promise.cast(obj) in this situation. + */ + function resolve(object?: R): Promise; + + /** + * Make a promise that rejects to obj. For consistency and debugging (eg stack traces), obj should be an instanceof Error + */ + function reject(error?: any): Promise; + + /** + * Make a promise that fulfills when every item in the array fulfills, and rejects if (and when) any item rejects. + * the array passed to all can be a mixture of promise-like objects and other objects. + * The fulfillment value is an array (in order) of fulfillment values. The rejection value is the first rejection value. + */ + function all(promises: Promise[]): Promise; + + /** + * Make a Promise that fulfills when any item fulfills, and rejects if any item rejects. + */ + function race(promises: Promise[]): Promise; +} \ No newline at end of file diff --git a/jquery/jquery-tests.ts b/jquery/jquery-tests.ts index a6cb92ee0..95fed2635 100644 --- a/jquery/jquery-tests.ts +++ b/jquery/jquery-tests.ts @@ -946,6 +946,17 @@ function test_removeData() { $("span:eq(3)").text("" + $("div").data("test2")); } +function test_jQuery_removeData() { + var div = $("div")[0]; + $("span:eq(0)").text("" + $("div").data("test1")); + jQuery.data(div, "test1", "VALUE-1"); + jQuery.data(div, "test2", "VALUE-2"); + $("span:eq(1)").text("" + jQuery.data(div, "test1")); + jQuery.removeData(div, "test1"); + $("span:eq(2)").text("" + jQuery.data(div, "test1")); + $("span:eq(3)").text("" + jQuery.data(div, "test2")); +} + function test_dblclick() { $('#target').dblclick(function () { alert('Handler for .dblclick() called.'); @@ -1095,6 +1106,68 @@ function test_dequeue() { }); } +function test_queue() { + + $("#show").click(function () { + var n = jQuery.queue($("div")[0], "fx"); + $("span").text("Queue length is: " + n.length); + }); + + function runIt() { + $("div") + .show("slow") + .animate({ + left: "+=200" + }, 2000) + .slideToggle(1000) + .slideToggle("fast") + .animate({ + left: "-=200" + }, 1500) + .hide("slow") + .show(1200) + .slideUp("normal", runIt); + } + + runIt(); + + $(document.body).click(function () { + var divs = $("div") + .show("slow") + .animate({ left: "+=200" }, 2000); + jQuery.queue(divs[0], "fx", function () { + $(this).addClass("newcolor"); + jQuery.dequeue(this); + }); + divs.animate({ left: "-=200" }, 500); + jQuery.queue(divs[0], "fx", function () { + $(this).removeClass("newcolor"); + jQuery.dequeue(this); + }); + divs.slideUp(); + }); + + $("#start").click(function () { + var divs = $("div") + .show("slow") + .animate({ left: "+=200" }, 5000); + jQuery.queue(divs[0], "fx", function () { + $(this).addClass("newcolor"); + jQuery.dequeue(this); + }); + divs.animate({ left: "-=200" }, 1500); + jQuery.queue(divs[0], "fx", function () { + $(this).removeClass("newcolor"); + jQuery.dequeue(this); + }); + divs.slideUp(); + }); + $("#stop").click(function () { + jQuery.queue($("div")[0], "fx", []); + $("div").stop(); + }); +} + function test_detach() { $("p").click(function () { $(this).toggleClass("off"); @@ -1669,6 +1742,104 @@ function test_hasData() { $p.append(jQuery.hasData(p) + " "); } +function test_jQuery_proxy() { + + function test1() { + var me = { + type: "zombie", + test: function (event?) { + // Without proxy, `this` would refer to the event target + // use event.target to reference that element. + var element = event.target; + $(element).css("background-color", "red"); + + // With proxy, `this` refers to the me object encapsulating + // this function. + $("#log").append("Hello " + this.type + "
"); + $("#test").off("click", this.test); + } + }; + + var you = { + type: "person", + test: function (event?) { + $("#log").append(this.type + " "); + } + }; + + // Execute you.test() in the context of the `you` object + // no matter where it is called + // i.e. the `this` keyword will refer to `you` + var youClick = $.proxy(you.test, you); + + // attach click handlers to #test + $("#test") + // this === "zombie"; handler unbound after first click + .on("click", $.proxy(me.test, me)) + + // this === "person" + .on("click", youClick) + + // this === "zombie" + .on("click", $.proxy(you.test, me)) + + // this === "