Skip to content

Commit

Permalink
feat: add method next
Browse files Browse the repository at this point in the history
This method is same as the previous "reset" method(same api, just the name changed).
  • Loading branch information
yisraelx committed Sep 13, 2017
1 parent a88fee6 commit 04c6d44
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/-all/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export { default as isPromise } from '@promises/is-promise';
export { default as keys } from '@promises/keys';
export { default as mapParallel } from '@promises/map-parallel';
export { default as mapSeries } from '@promises/map-series';
export { default as next } from '@promises/next';
export { default as parallel } from '@promises/parallel';
export { default as promisify, PromisifyOptions } from '@promises/promisify';
export { default as reduceSeries } from '@promises/reduce-series';
Expand Down
1 change: 1 addition & 0 deletions modules/-all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@promises/keys": "^0.1.0",
"@promises/map-parallel": "^0.1.0",
"@promises/map-series": "^0.1.0",
"@promises/next": "NEXT-PLACEHOLDER",
"@promises/parallel": "^0.1.0",
"@promises/promisify": "^0.1.0",
"@promises/reduce-right-series": "^0.1.0",
Expand Down
1 change: 1 addition & 0 deletions modules/-prototype/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export { default as forEachRightSeries } from '@promises/for-each-right-series';
export { default as keys } from '@promises/keys';
export { default as mapParallel } from '@promises/map-parallel';
export { default as mapSeries } from '@promises/map-series';
export { default as next } from '@promises/next';
export { default as reduceSeries } from '@promises/reduce-series';
export { default as reduceRightSeries } from '@promises/reduce-right-series';
export { default as rejectParallel } from '@promises/reject-parallel';
Expand Down
1 change: 1 addition & 0 deletions modules/-prototype/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@promises/keys": "^0.1.0",
"@promises/map-parallel": "^0.1.0",
"@promises/map-series": "^0.1.0",
"@promises/next": "NEXT-PLACEHOLDER",
"@promises/reduce-right-series": "^0.1.0",
"@promises/reduce-series": "^0.1.0",
"@promises/reject-parallel": "^0.1.0",
Expand Down
60 changes: 60 additions & 0 deletions modules/next/index.ts
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>;
}
}
38 changes: 38 additions & 0 deletions modules/next/package.json
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"
}
}
11 changes: 11 additions & 0 deletions test/next.spec.ts
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');
});
});
});

0 comments on commit 04c6d44

Please sign in to comment.