Browse Source

Move Promise to js package, care of @fponticelli.

Closes #3998, closes #3999.
Bruno Garcia 10 years ago
parent
commit
4288a90619
1 changed files with 25 additions and 11 deletions
  1. 25 11
      std/js/Promise.hx

+ 25 - 11
std/js/html/Promise.hx → std/js/Promise.hx

@@ -20,20 +20,34 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-// This file is generated from mozilla/Promise.webidl line 22:0. Do not edit!
+package js;
 
-package js.html;
+import haxe.extern.EitherType;
 
 @:native("Promise")
-extern class Promise
+extern class Promise<T>
 {
-	static function resolve( ?value : Dynamic ) : Promise/*<Any>*/;
-	static function reject( ?value : Dynamic ) : Promise/*<Void>*/;
-	static function all( iterable : Array<Dynamic> ) : Promise/*<Any>*/;
-	static function race( iterable : Array<Dynamic> ) : Promise/*<Any>*/;
+	@:overload(function<T>(promise : Promise<T>) : Promise<T> {})
+	@:overload(function<T>(thenable : Thenable<T>) : Promise<T> {})
+	static function resolve<T>( value : T ) : Promise<T>;
+
+	static function reject<T>( ?value : Dynamic ) : Promise<T>;
+
+	static function all( iterable : Array<Dynamic> ) : Promise<Array<Dynamic>>;
+
+	static function race( iterable : Array<Dynamic> ) : Promise<Dynamic>;
+
 	/** @throws DOMError */
-	function new( init : Dynamic -> Dynamic -> Void ) : Void;
-	function then( ?fulfillCallback : haxe.Constraints.Function, ?rejectCallback : haxe.Constraints.Function ) : Promise/*<Any>*/;
+	function new( init : (T -> Void) -> (Dynamic -> Void) -> Void ) : Void;
+
+	function then<TOut>( ?fulfillCallback : PromiseCallback<T, TOut>, ?rejectCallback : EitherType<Dynamic -> Void, PromiseCallback<Dynamic, TOut>> ) : Promise<TOut>;
+
 	@:native("catch")
-	function catch_( ?rejectCallback : haxe.Constraints.Function ) : Promise/*<Any>*/;
-}
+	function catchError<TOut>( rejectCallback : EitherType<Dynamic -> Void, PromiseCallback<Dynamic, TOut>> ) : Promise<TOut>;
+}
+
+typedef PromiseCallback<T, TOut> = EitherType<T -> TOut, T -> Promise<TOut>>;
+
+typedef Thenable<T> = {
+	then : EitherType<(T -> Void) -> (Dynamic -> Void) -> Void, (T -> Void) -> Void>
+}