-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This method is same as the previous "reset" method(same api, just the name changed).
- Loading branch information
Showing
7 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* @module @promises/next | ||
* @copyright © 2017 Yisrael Eliav <yisraelx@gmail.com> (https://github.com/yisraelx) | ||
* @license MIT | ||
*/ | ||
|
||
import Promises from '@promises/core'; | ||
import { OptionalPromise } from '@promises/interfaces'; | ||
|
||
/** | ||
* @example | ||
* | ||
* ```typescript | ||
* let promises: Promises<string> = Promises.resolve<string>('foo'); | ||
* next(promises, 'bar').then((result: string) => { | ||
* console.log(result); // => 'bar' | ||
* }); | ||
* ``` | ||
* @example | ||
* | ||
* ```typescript | ||
* let promises: Promises<string> = Promises.reject<string>('foo'); | ||
* next(promises, 'bar').then((result: string) => { | ||
* console.log(result); // => 'bar' | ||
* }); | ||
* ``` | ||
*/ | ||
function next<R>(promise: OptionalPromise<any>, value: OptionalPromise<R>): Promises<R> { | ||
return Promises.resolve(promise).then(() => { | ||
return value; | ||
}) as Promises<R>; | ||
} | ||
|
||
export default next; | ||
|
||
Promises._setOnPrototype('next', next); | ||
|
||
declare module '@promises/core' { | ||
interface Promises<T> { | ||
/** | ||
* @example | ||
* | ||
* ```typescript | ||
* let promises: Promises<string> = Promises.resolve<string>('foo').next('bar'); | ||
* promises.then((result: string) => { | ||
* console.log(result); // => 'bar' | ||
* }); | ||
* ``` | ||
* @example | ||
* | ||
* ```typescript | ||
* let promises: Promises<string> = Promises.reject<string>('foo').next('bar'); | ||
* promises.then((result: string) => { | ||
* console.log(result); // => 'bar' | ||
* }); | ||
* ``` | ||
*/ | ||
next<R>(this: Promises<T>, value: OptionalPromise<R>): Promises<R>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "@promises/next", | ||
"version": "NEXT-PLACEHOLDER", | ||
"description": "Next is package from Promises library", | ||
"main": "umd.js", | ||
"browser": "umd.js", | ||
"module": "es5.js", | ||
"es2015": "index.js", | ||
"typings": "index.d.ts", | ||
"bundle": "bundle.js", | ||
"author": { | ||
"name": "Yisrael Eliev", | ||
"url": "https://github.com/yisraelx", | ||
"email": "yisraelx@gmail.com" | ||
}, | ||
"license": "MIT", | ||
"keywords": [ | ||
"promise", | ||
"promises", | ||
"utility", | ||
"modules", | ||
"async", | ||
"await", | ||
"deferred" | ||
], | ||
"homepage": "https://github.com/yisraelx/promises#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/yisraelx/promises.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/yisraelx/promises/issues" | ||
}, | ||
"dependencies": { | ||
"@promises/core": "^0.1.0", | ||
"@promises/interfaces": "^0.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Promises from '@promises/core'; | ||
import reset from '@promises/next'; | ||
|
||
describe('next', () => { | ||
it('should be return promise resolve with new value', () => { | ||
let promises = Promises.resolve('foo'); | ||
return reset(promises, 'new val').then((result: string) => { | ||
expect(result).toBe('new val'); | ||
}); | ||
}); | ||
}); |