Skip to content

Commit

Permalink
feat: change packages architecture and giving independence to modules…
Browse files Browse the repository at this point in the history
…/methods

This changes was made to make the modules/methods more independent:
* standalone methods return 'Promise' instead of 'Promises', It is more logical for standalone methods to return 'Promise' and not 'Promises', and only in case that the use of Promises this will return a 'Promises'.
* changing the architecture of loading methods to 'Promises', now methods will not automatically load to 'Promises' only when you call to '<package>/add'.
* move methods interfaces from '@promises/interfaces' to packages of methods.
* preventing overriding parent (Promise) methods, for avoid problems with polyfill 'Promise'.

BREAKING CHANGES:
**standalone methods return 'Promise' instead of 'Promises'**

before
```ts
import method from '@promises/method';
let promises: Promises<any> = method<any>();
```

after
```ts
import method from '@promises/method';
let promise: Promise<any> = method<any>();
```

for Promises use Promises
```ts
import Promises from '@promises/-all';

let promises: Promises<any> = Promises.method<any>();
```
**changing the architecture of loading methods to 'Promises'**

before
```ts
import Promises from '@promises/core';
import method from '@promises/method';

method()
Promise.method()
```
```ts
import Promises from '@promises/core';
import '@promises/method';

Promise.method()
```

after
```ts
import
Promises from '@promises/core';
import method from '@promises/method';

method()
Promise.method() // throw Error
```
```ts
import Promises from '@promises/core';
import method from'@promises/method/add';

method()
Promise.method()
```
  • Loading branch information
yisraelx committed Mar 4, 2018
1 parent 5a146dc commit 832216b
Show file tree
Hide file tree
Showing 172 changed files with 1,895 additions and 1,608 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,35 @@ $ npm install --save @promises/for-each-series

## Use
#### static
```typescript
```ts
import mapSeries from '@promises/map-series';
let array: number[] = [1, 2, 3];
let map: Promises<number[]> = mapSeries(array, (value: number, index: number, array: number[]) => {
let map: Promise<number[]> = mapSeries(array, (value: number, index: number, array: number[]) => {
return value * index;
});
map.then((result: number[]) => {
console.log(result) // => [0, 2, 6]
});
```
#### wrapper
```typescript
```ts
import { Promises } from '@promises/-all';
let array: number[] = [1, 2, 3];
let promises: Promises<number[]> = Promises.resolve(array);
let filter: Promises<number[]> = promises.filterParallel((value: number) => value % 2 !== 0);
let map: Promises<number[]> = filter.mapParallel((value: number, index: number) => value + index);
let delay: Promises<number[]> = map.delay(1000);
delay.then((result: number[]) => {
console.log(result) // => [1, 4]
});
```
Or
```ts
import { Promises } from '@promises/core';
import '@promises/filter-parallel/add';
import '@promises/map-parallel/add';
import '@promises/delay/add';

let array: number[] = [1, 2, 3];
let promises: Promises<number[]> = Promises.resolve(array);
let filter: Promises<number[]> = promises.filterParallel((value: number) => value % 2 !== 0);
Expand Down
75 changes: 38 additions & 37 deletions modules/-all/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,42 @@
* @license MIT
*/

export { default as compose } from '@promises/compose';
export { default as compose } from '@promises/compose/add';
export { default as Promises } from '@promises/core';
export { default as create } from '@promises/create';
export { default as delay } from '@promises/delay';
export { default as error } from '@promises/error';
export { default as everyParallel } from '@promises/every-parallel';
export { default as everySeries } from '@promises/every-series';
export { default as exec } from '@promises/exec';
export { default as filterParallel } from '@promises/filter-parallel';
export { default as filterSeries } from '@promises/filter-series';
export { default as finally } from '@promises/finally';
export { default as forEachParallel } from '@promises/for-each-parallel';
export { default as forEachSeries } from '@promises/for-each-series';
export { default as forEachRightSeries } from '@promises/for-each-right-series';
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, IPromisifyOptions } from '@promises/promisify';
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';
export { default as rejectSeries } from '@promises/reject-series';
export { default as reset } from '@promises/reset';
export { default as retry, IRetryOptions, IRetryFilterInfo, IRetryTimeInfo } from '@promises/retry';
export { default as series } from '@promises/series';
export { default as sleep } from '@promises/sleep';
export { default as someParallel } from '@promises/some-parallel';
export { default as someSeries } from '@promises/some-series';
export { default as spread } from '@promises/spread';
export { default as timeout } from '@promises/timeout';
export { default as timer } from '@promises/timer';
export { default as timesParallel } from '@promises/times-parallel';
export { default as timesSeries } from '@promises/times-series';
export { default as toCallback } from '@promises/to-callback';
export { default as wrap } from '@promises/wrap';
export { default as create } from '@promises/create/add';
export { default as delay } from '@promises/delay/add';
export { default as error } from '@promises/error/add';
export { default as everyParallel } from '@promises/every-parallel/add';
export { default as everySeries } from '@promises/every-series/add';
export { default as exec } from '@promises/exec/add';
export { default as filterParallel } from '@promises/filter-parallel/add';
export { default as filterSeries } from '@promises/filter-series/add';
export { default as finally } from '@promises/finally/add';
export { default as forEachParallel } from '@promises/for-each-parallel/add';
export { default as forEachRightSeries } from '@promises/for-each-right-series/add';
export { default as forEachSeries } from '@promises/for-each-series/add';
export * from '@promises/interfaces';
export { default as isPromise } from '@promises/is-promise/add';
export { default as keys } from '@promises/keys/add';
export { default as mapParallel } from '@promises/map-parallel/add';
export { default as mapSeries } from '@promises/map-series/add';
export { default as next } from '@promises/next/add';
export { default as parallel } from '@promises/parallel/add';
export { default as promisify, IPromisifyOptions } from '@promises/promisify/add';
export { default as reduceRightSeries } from '@promises/reduce-right-series/add';
export { default as reduceSeries } from '@promises/reduce-series/add';
export { default as rejectParallel } from '@promises/reject-parallel/add';
export { default as rejectSeries } from '@promises/reject-series/add';
export { default as reset } from '@promises/reset/add';
export { default as retry, IRetryFilterInfo, IRetryOptions, IRetryTimeInfo} from '@promises/retry/add';
export { default as series } from '@promises/series/add';
export { default as sleep } from '@promises/sleep/add';
export { default as someParallel } from '@promises/some-parallel/add';
export { default as someSeries } from '@promises/some-series/add';
export { default as spread } from '@promises/spread/add';
export { default as timeout } from '@promises/timeout/add';
export { default as timer } from '@promises/timer/add';
export { default as timesParallel } from '@promises/times-parallel/add';
export { default as timesSeries } from '@promises/times-series/add';
export { default as toCallback } from '@promises/to-callback/add';
export { default as wrap } from '@promises/wrap/add';
29 changes: 15 additions & 14 deletions modules/-constructor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
* @license MIT
*/

export { default as compose } from '@promises/compose';
export { default as Promises } from '@promises/core';
export { default as create } from '@promises/create';
export { default as delay } from '@promises/delay';
export { default as exec } from '@promises/exec';
export { default as isPromise } from '@promises/is-promise';
export { default as promisify, IPromisifyOptions } from '@promises/promisify';
export { default as parallel } from '@promises/parallel';
export { default as retry, IRetryOptions, IRetryFilterInfo, IRetryTimeInfo } from '@promises/retry';
export { default as series } from '@promises/series';
export { default as timeout } from '@promises/timeout';
export { default as timesParallel } from '@promises/times-parallel';
export { default as timesSeries } from '@promises/times-series';
export { default as wrap } from '@promises/wrap';
export {default as compose} from '@promises/compose/add';
export {default as Promises} from '@promises/core';
export {default as create} from '@promises/create/add';
export {default as delay} from '@promises/delay/add';
export {default as exec} from '@promises/exec/add';
export * from '@promises/interfaces';
export {default as isPromise} from '@promises/is-promise/add';
export {default as promisify, IPromisifyOptions} from '@promises/promisify/add';
export {default as parallel} from '@promises/parallel/add';
export {default as retry, IRetryFilterInfo, IRetryOptions, IRetryTimeInfo} from '@promises/retry/add';
export {default as series} from '@promises/series/add';
export {default as timeout} from '@promises/timeout/add';
export {default as timesParallel} from '@promises/times-parallel/add';
export {default as timesSeries} from '@promises/times-series/add';
export {default as wrap} from '@promises/wrap/add';
17 changes: 9 additions & 8 deletions modules/-parallel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
*/

export { default as Promises } from '@promises/core';
export { default as everyParallel } from '@promises/every-parallel';
export { default as filterParallel } from '@promises/filter-parallel';
export { default as forEachParallelParallel } from '@promises/for-each-parallel';
export { default as mapParallel } from '@promises/map-parallel';
export { default as parallel } from '@promises/parallel';
export { default as rejectParallel } from '@promises/reject-parallel';
export { default as someParallel } from '@promises/some-parallel';
export { default as timesParallel } from '@promises/times-parallel';
export { default as everyParallel } from '@promises/every-parallel/add';
export { default as filterParallel } from '@promises/filter-parallel/add';
export { default as forEachParallel } from '@promises/for-each-parallel/add';
export * from '@promises/interfaces';
export { default as mapParallel } from '@promises/map-parallel/add';
export { default as parallel } from '@promises/parallel/add';
export { default as rejectParallel } from '@promises/reject-parallel/add';
export { default as someParallel } from '@promises/some-parallel/add';
export { default as timesParallel } from '@promises/times-parallel/add';
49 changes: 25 additions & 24 deletions modules/-prototype/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@
*/

export { default as Promises } from '@promises/core';
export { default as error } from '@promises/error';
export { default as everyParallel } from '@promises/every-parallel';
export { default as everySeries } from '@promises/every-series';
export { default as filterParallel } from '@promises/filter-parallel';
export { default as filterSeries } from '@promises/filter-series';
export { default as finally } from '@promises/finally';
export { default as forEachParallel } from '@promises/for-each-parallel';
export { default as forEachSeries } from '@promises/for-each-series';
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';
export { default as rejectSeries } from '@promises/reject-series';
export { default as reset } from '@promises/reset';
export { default as sleep } from '@promises/sleep';
export { default as someParallel } from '@promises/some-parallel';
export { default as someSeries } from '@promises/some-series';
export { default as spread } from '@promises/spread';
export { default as timer } from '@promises/timer';
export { default as toCallback } from '@promises/to-callback';
export { default as error } from '@promises/error/add';
export { default as everyParallel } from '@promises/every-parallel/add';
export { default as everySeries } from '@promises/every-series/add';
export { default as filterParallel } from '@promises/filter-parallel/add';
export { default as filterSeries } from '@promises/filter-series/add';
export { default as finally } from '@promises/finally/add';
export { default as forEachParallel } from '@promises/for-each-parallel/add';
export { default as forEachRightSeries } from '@promises/for-each-right-series/add';
export { default as forEachSeries } from '@promises/for-each-series/add';
export * from '@promises/interfaces';
export { default as keys } from '@promises/keys/add';
export { default as mapParallel } from '@promises/map-parallel/add';
export { default as mapSeries } from '@promises/map-series/add';
export { default as next } from '@promises/next/add';
export { default as reduceRightSeries } from '@promises/reduce-right-series/add';
export { default as reduceSeries } from '@promises/reduce-series/add';
export { default as rejectParallel } from '@promises/reject-parallel/add';
export { default as rejectSeries } from '@promises/reject-series/add';
export { default as reset } from '@promises/reset/add';
export { default as sleep } from '@promises/sleep/add';
export { default as someParallel } from '@promises/some-parallel/add';
export { default as someSeries } from '@promises/some-series/add';
export { default as spread } from '@promises/spread/add';
export { default as timer } from '@promises/timer/add';
export { default as toCallback } from '@promises/to-callback/add';
5 changes: 3 additions & 2 deletions modules/-rxjs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
*/

export { default as Promises } from '@promises/core';
export { default as fromObservable } from '@promises/from-observable';
export { default as toObservable } from '@promises/to-observable';
export { default as fromObservable } from '@promises/from-observable/add';
export * from '@promises/interfaces';
export { default as toObservable } from '@promises/to-observable/add';
23 changes: 12 additions & 11 deletions modules/-series/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
*/

export { default as Promises } from '@promises/core';
export { default as everySeries } from '@promises/every-series';
export { default as filterSeries } from '@promises/filter-series';
export { default as forEachSeries } from '@promises/for-each-series';
export { default as forEachRightSeries } from '@promises/for-each-right-series';
export { default as mapSeries } from '@promises/map-series';
export { default as reduceSeries } from '@promises/reduce-series';
export { default as reduceRightSeries } from '@promises/reduce-right-series';
export { default as rejectSeries } from '@promises/reject-series';
export { default as series } from '@promises/series';
export { default as someSeries } from '@promises/some-series';
export { default as timesSeries } from '@promises/times-series';
export { default as everySeries } from '@promises/every-series/add';
export { default as filterSeries } from '@promises/filter-series/add';
export { default as forEachSeries } from '@promises/for-each-series/add';
export { default as forEachRightSeries } from '@promises/for-each-right-series/add';
export * from '@promises/interfaces';
export { default as mapSeries } from '@promises/map-series/add';
export { default as reduceSeries } from '@promises/reduce-series/add';
export { default as reduceRightSeries } from '@promises/reduce-right-series/add';
export { default as rejectSeries } from '@promises/reject-series/add';
export { default as series } from '@promises/series/add';
export { default as someSeries } from '@promises/some-series/add';
export { default as timesSeries } from '@promises/times-series/add';
6 changes: 2 additions & 4 deletions modules/_create-checks-boolean/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
* @license MIT
*/

import Promises from '@promises/core';

export default function _createChecksBoolean(iterator, check, is) {
return (collection?, iteratee: any = v => v) => {
return iterator(collection, (value, index, collection) => {
let result = iteratee(value, index, collection);
return Promises.resolve(result).then(check);
return Promise.resolve(result).then(check);
}).then(() => {
return !is;
}).catch((result) => {
return (result === is) ? Promises.resolve(result) : Promises.reject(result);
return (result === is) ? Promise.resolve(result) : Promise.reject(result);
});
};
}
4 changes: 0 additions & 4 deletions modules/_create-checks-boolean/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,5 @@
},
"bugs": {
"url": "https://github.com/yisraelx/promises/issues"
},
"dependencies": {
"@promises/core": "^0.2.0",
"@promises/interfaces": "^0.2.0"
}
}
6 changes: 2 additions & 4 deletions modules/_create-filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
* @license MIT
*/

import Promises from '@promises/core';

export default function _createFilter(iterator, is) {
return (collection?, iteratee: any = v => v) => {
return Promises.resolve(collection).then((collection = []) => {
return Promise.resolve(collection).then((collection = []) => {
let isArray = Array.isArray(collection);
let result = isArray ? [] : {};
let count = 0;
return iterator(collection, (value, key, collection) => {
let isPass = iteratee(value, key, collection);
return Promises.resolve(isPass).then((isPass) => {
return Promise.resolve(isPass).then((isPass) => {
if (!!isPass === is) result[isArray ? count++ : key] = value;
});
}).then(() => {
Expand Down
4 changes: 0 additions & 4 deletions modules/_create-filter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,5 @@
},
"bugs": {
"url": "https://github.com/yisraelx/promises/issues"
},
"dependencies": {
"@promises/core": "^0.2.0",
"@promises/interfaces": "^0.2.0"
}
}
7 changes: 3 additions & 4 deletions modules/_create-for-each-series/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@
* @license MIT
*/

import Promises from '@promises/core';
import keys from '@promises/_keys';

export default function _createForEachSeries(rtl?: boolean) {
return (collection?, iteratee: any = v => v) => {
return Promises.resolve(collection).then((collection = []) => {
return Promise.resolve(collection).then((collection = []) => {
let objectKeys = !Array.isArray(collection) && keys(collection);
let {length} = objectKeys ? objectKeys : collection;
let left = 0;
let right = length - 1;
let each = Promises.resolve();
let each = Promise.resolve();
while (left <= right) {
let current = rtl ? right-- : left++;
each = each.then(() => {
let key = objectKeys ? objectKeys[current] : current;
let value = collection[key];
return Promises.resolve(value).then((value) => {
return Promise.resolve(value).then((value) => {
return iteratee(value, key, collection);
});
});
Expand Down
4 changes: 1 addition & 3 deletions modules/_create-for-each-series/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
"url": "https://github.com/yisraelx/promises/issues"
},
"dependencies": {
"@promises/_keys": "^0.2.0",
"@promises/core": "^0.2.0",
"@promises/interfaces": "^0.2.0"
"@promises/_keys": "^0.2.0"
}
}
6 changes: 2 additions & 4 deletions modules/_create-map/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
* @license MIT
*/

import Promises from '@promises/core';

export default function _createMap(iterator) {
return (collection?, iteratee: any = v => v) => {
return Promises.resolve(collection).then((collection = []) => {
return Promise.resolve(collection).then((collection = []) => {
let result = Array.isArray(collection) ? Array(collection.length) : {};
return iterator(collection, (value, key, collection) => {
let getNewValue = iteratee(value, key, collection);
return Promises.resolve(getNewValue).then((newValue) => {
return Promise.resolve(getNewValue).then((newValue) => {
result[key] = newValue;
});
}).then(() => {
Expand Down
4 changes: 0 additions & 4 deletions modules/_create-map/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,5 @@
},
"bugs": {
"url": "https://github.com/yisraelx/promises/issues"
},
"dependencies": {
"@promises/core": "^0.2.0",
"@promises/interfaces": "^0.2.0"
}
}
Loading

0 comments on commit 832216b

Please sign in to comment.