Skip to content

Commit

Permalink
Add template types to kew.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Santos committed Feb 17, 2014
1 parent e3cad88 commit 6265df3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
28 changes: 14 additions & 14 deletions kew.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/** @typedef {function(?, ?)} */
var OnSuccessCallbackType;
/** @typedef {function(!Error, ?)} */
var OnFailCallbackType;

/**
* An object representing a "promise" for a future value
*
* @param {?OnSuccessCallbackType=} onSuccess a function to handle successful
* @param {?function(T)=} onSuccess a function to handle successful
* resolution of this promise
* @param {OnFailCallbackType=} onFail a function to handle failed
* @param {?function(!Error)=} onFail a function to handle failed
* resolution of this promise
* @constructor
* @template T
*/
function Promise(onSuccess, onFail) {
this.promise = this
Expand Down Expand Up @@ -148,8 +145,8 @@ Promise.prototype.reject = function (e) {
* resolves. Allows for an optional second callback to handle the failure
* case.
*
* @param {?OnSuccessCallbackType} onSuccess
* @param {OnFailCallbackType=} onFail
* @param {?function(this:void, T)} onSuccess
* @param {?function(this:void, !Error)=} onFail
* @return {!Promise} returns a new promise with the output of the onSuccess or
* onFail handler
*/
Expand All @@ -167,10 +164,11 @@ Promise.prototype.then = function (onSuccess, onFail) {
* Provide a callback to be called whenever this promise successfully
* resolves. The callback will be executed in the context of the provided scope.
*
* @param {?OnSuccessCallbackType} onSuccess
* @param {Object} scope Object whose context callback will be executed in.
* @param {function(this:SCOPE, T)} onSuccess
* @param {SCOPE} scope Object whose context callback will be executed in.
* @param {...*} var_args Additional arguments to be passed to the promise callback.
* @return {!Promise} returns a new promise with the output of the onSuccess
* @template SCOPE
*/
Promise.prototype.thenBound = function (onSuccess, scope, var_args) {
var promise = new Promise(onSuccess)
Expand All @@ -191,7 +189,7 @@ Promise.prototype.thenBound = function (onSuccess, scope, var_args) {
/**
* Provide a callback to be called whenever this promise is rejected
*
* @param {OnFailCallbackType} onFail
* @param {function(this:void, !Error)} onFail
* @return {!Promise} returns a new promise with the output of the onFail handler
*/
Promise.prototype.fail = function (onFail) {
Expand All @@ -202,11 +200,13 @@ Promise.prototype.fail = function (onFail) {
* Provide a callback to be called whenever this promise is rejected.
* The callback will be executed in the context of the provided scope.
*
* @param {OnFailCallbackType} onFail
* @param {Object} scope Object whose context callback will be executed in.
* @param {function(this:SCOPE, Error)} onFail
* @param {SCOPE} scope Object whose context callback will be executed in.
* @param {...?} var_args
* @return {!Promise} returns a new promise with the output of the onSuccess
* @template SCOPE
*/
Promise.prototype.failBound = function (onFail, scope) {
Promise.prototype.failBound = function (onFail, scope, var_args) {
var promise = new Promise(null, onFail)
if (this._nextContext) promise._useContext(this._nextContext)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"devDependencies": {
"q": "0.9.7",
"nodeunit": "0.8.1",
"closure-npc": "0.0.9"
"closure-npc": "0.0.10"
},
"scripts": {
"test": "nodeunit test && closure-npc ./test/closure_test.js --jscomp_error=checkTypes"
Expand Down

0 comments on commit 6265df3

Please sign in to comment.